PHP Classes

Unusual site speedup

Recommend this page to a friend!

      PHP Classes blog  >  Unusual Site Speedup ...  >  All threads  >  Unusual site speedup  >  (Un) Subscribe thread alerts  
Subject:Unusual site speedup
Summary:checking /proc/loadavg
Messages:5
Author:Tom Davidson
Date:2010-11-11 21:59:52
Update:2010-11-13 06:15:59
 

  1. Unusual site speedup   Reply   Report abuse  
Picture of Tom Davidson Tom Davidson - 2010-11-11 23:14:09
What about a long runnig script (maybe run from cron) that has already started when the load starts to ramp up? Or if you want the script to still carry on running but giving up resources to higher priority threads?

This can be done on unix by starting scripts using `nice`. This will allow you to specify the thread priority to be below that of apache or any other services or scripts that are more important to the running of your site.

swoolley.org/man.cgi/nice

  2. Re: Unusual site speedup   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2010-11-11 23:28:35 - In reply to message 1 from Tom Davidson
nice just changes the priority by which the CPU is given to a process.

It does not prevent that a low priority process gets the CPU and still effectively slow down the rest of the processes.

For instance, lets say that you have a typical Web script process that needs to access a database to show some data in HTML.

If you have a low priority process running a CPU intensive task in the background, when the Web process accesses the database, it has to wait for the database server to respond. In that moment, the Web process goes idle and the background task gets the CPU.

When the Web process gets the response of the database, it does not get the CPU immediately. The OS scheduler will only gives the CPU to the Web process when the current multi-tasking time slice ends.

This would be different if you use the technique that I have described in the article. It consists in effectively stopping low priority background processes when the average CPU load is too high. This way, the scheduler will never split the CPU with the low priority process because it was intentionally put to sleep for a good period.

  3. Re: Unusual site speedup   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2010-11-11 23:41:02 - In reply to message 1 from Tom Davidson
That is a different solution, which was also discussed in a previous article:

phpclasses.org/blog/post/131-Accele ...

The point of asynchronous programming is mainly to run in parallel tasks that otherwise would be serialized, I mean if you have multiple long tasks to run in a script, you could save a lot of time by running them in parallel instead of running one task only after the previous has ended.

The gain can be more noticeable in applications that need to access external resources, such as databases or remote servers via network, as those are typically the ones that take more time and most of the time your script stays idle waiting for the database server or the remote host to respond.

  4. Re: Unusual site speedup   Reply   Report abuse  
Picture of Tom Davidson Tom Davidson - 2010-11-12 21:34:33 - In reply to message 2 from Manuel Lemos
Absolutely they solve slightly different problems, they are related so I was advocating the use of this aswell rather than instead.

  5. Re: Unusual site speedup   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2010-11-13 06:15:59 - In reply to message 4 from Tom Davidson
Oh, I misunderstood your point, sorry.