resources
daniele_dll's picture
Tagged:  •    •  

Have you ever checked resources consumption of your software? I do it regularly !

A lot of web softwares never check memory and cpu consumption: the result is that a lot of these cannot be used on big web sites and if them are used is necessary a lot of powerful hardware!

As you know i started to work on CMSoft2 and the first step of this work is to make a features's list: a list that contains what is really useful, what is necessary and what can be useful later. To do this is necessary to try out famouses CMSes: wordpress have a wonderful dashboard and drupal has a centralized content managent!

Do you ever think how these features are implemented? How them work and how much resources requests? No? I've done this for you!

If you look at the end of the page you will see two strange lines: them are peak memory consumption and execution time.

Now you try to think at your website: if it has 10 users that connect in the same moment THEY WILL USE ~75 MEGABYTE OF MEMORY! With drupal to mantain online 100 users you will need ~750MB of memory: this is an killer application!

If your server has 1GB of memory, it'll use swap fastly and this is bad: when your server start to use swap, memory is copied from harddisk to memory and from memory to harddisk, without a pause: this kill your harddisks and your applications are slowed down!

As drupal a lot of well known famous software are killer application:
- wordpress
- phpnuke
- xaraya
- xoops
- exoops
- postnuke
- evolution
- drupal
and so on

Wordpress, for example, when a post or a page is loaded extract from a serialized array a tons of perl compatible regular expressions and execute them stopping only when one of these match the url! If you blogged for one year and someone access to your "Who I Am" page, added at begginning, wordpress will execute server preg for every post/page before the correct one and this means a lot of CPU used!

No one optimize the logic behind the code and the code itself! It is like: "If you use my software don't ask me to do better, do it yourself!"

Check memory consumption and time execution is really simply and isin't necessary to modify your source code!

Create a file called resource_check.php
--- CODE ---

function __securename__output_handler($output)
{
$output .= '

Memory Peak: ' . sprintf('%0.6f', memory_get_peak_usage() / 1024) . 'kb';
return $output;
}

ob_start(__securename__output_handler);

?>
--- CODE ---

and modify, or create, your htaccess adding this
--- CODE ---
php_value auto_prepend_file "/PATH/TO/resource_check.php"
--- CODE ---