i have a module called online events in my website, this module will run for every 8 sec and fetches a recent activities in my websites. So, if more than 100 users are using my website at a time, it consumes more memory and more cpu usuage. what should i do to reduce cpu usage and memory, provided it should not affect a online events module. will it be would to do something with files here? pls help me.
views:
30answers:
3If I understand it correctly the module needs to run every 8 seconds?
Why not store the time when the module ran last and then with every access from those thousands of users you only check if the time since the module last ran is bigger than 8 seconds? If it is you ran the module and store thwe new time, if it isn't you do nothing and wait for another user to access the site, to generate new online events for him?
http://www.mnot.net/cache_docs/
http://php.net/manual/en/book.apc.php
Database optimization
http://dev.mysql.com/doc/refman/5.0/en/optimization.html
http://20bits.com/articles/10-tips-for-optimizing-mysql-queries-that-dont-suck/
http://forge.mysql.com/wiki/Top10SQLPerformanceTips
Apache optimization
http://www.prelovac.com/vladimir/wordpress-optimization-guide (About Wordpress, but has good tips for all applications)
http://httpd.apache.org/docs/2.1/mod/mod_proxy_balancer.html
http://www.howtoforge.com/high_availability_loadbalanced_apache_cluster
At first, make the interval higher. Then, cache the module somehow on server side. E.g. make a static html file that gets loaded through a php file, and that will only get updated if something has changed in the db, so you only need to query the DB and render the data from it if really something happened. A simple approach to ensure cache update would be to remove the static file everytime something changes in the DB. This only makes sense if there are not too many DB changes.