简体   繁体   中英

Using PHP sleep to give priority to some requests - a good or bad idea?

I'm running an ecommerce site where we at times experience high peak loads.

After a certain number of customers is exceeded, some very simple overload control actions will be taken.

One of the planned actions it to give priority to those customers having items in their shopping carts, for very obvious reasons.

This is done by adding a short sleep (or usleep) to all other requests but those from customers with items in cart.

Is this a good idea?

a) Yes, it Will it work like a dream!

b) It will not have a significant impact on anything...

c) No, it will just reserve resources unnecessarily and slow everything down!

d) Well, it depends... (on what?)

c - it will just reserve resources unnecessarily and slow everything down.

Sleep won't free up resources, because the script is still running. Each time a user makes a request to your site, a new PHP thread is spawned and takes up memory. The more running threads, the more memory being used. By sleeping, you are actually taking up MORE memory by delaying each thread and making it run longer.

What you can do is open your developer console in firefox or chrome, go to the network tab, and press refresh. Look at all the network resources that are loading and think about how you can decrease that loadtime and the number of requests to the server. Maybe you have 10 or 50 queries per page, when you really only need 4-5. Optimize your site code and network utilization to speed it up.

If you post the link, we can take a look at it too.

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