简体   繁体   中英

nginx php-fpm cache same multiple requests per second

I'm having the following situation:

An auction website where all users connected make a ajax request to the server every 2 seconds.

The data changes every 2 seconds so it cannot be cached for a long duration so I was wondering.

What would be the best way to accomplish this:

If I have 200 request in the same second, serve them the same response instead of running again php and connecting to mysql to get results.

So I don't know if this could be done with such a small duration of cache of 1 second, also I don't know what would be better to use, something on Nginx side, or something on PHP side such as APC.

Any ideas? does it make sense?

My problem is that I've tried to tweak Nginx and php-fpm and right now it can handle 200 requests/s at 2000ms response time, at 500requests/s is about 5000ms so I'm looking for a way to speed things up and handle as much requests per second as possible.

Update:
The website is running on Symfony2 so any suggestions related to it are also welcome.

Update 2!!!
I have moved the part of the application that handled the ajax request into a single php file without using the Symfony2 framework. It does 3 sql queries and returns json response. Now it can handle 1000+ requests at 150ms/second, it's really incredible.. I guess Symfony2 really needs tweaks to be able to do the same and I guess the problem was not php but all the memory used by the framework.

Vanilla PHP is of course faster than any PHP framework but maintaining dozens of such scripts is painful. You can stick with Symfony and use Varnish to handle the heavy load. Cache TTL can be as low as 1 second and with Varnish you can handle thousands of requests.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM