How to Improve System Performance And CPU Load
|
skuszi
Joined: 2008-06-27
Posts: 1 |
Posted: Sat, 2008-06-28 13:14
|
|
Gallery version = 2.2.5 core 1.2.0.7 Hi , I am very new in webhosting as well as these technical stuffs so please consider this and help me. recently i got mail from hosting providers that my account is using more cpu load and usage and told me to switch to vps or any other plan , now i have only 300 visitors per day . pleas tell me all possible steps or ways through which i can minimize CPU load or database load or server load . i am not able to understand Admin option > performance option > Performance Tuning >> Acceleration i want to minimize server load and dynamic data is not at all important for me... so which settings do i need to keep No acceleration ??? or High acceleration ??? apart from this please let me know what else i should do at Admin option > Maintenance to make less CPU load and usage. Please reply me soon i am waiitng for some help regards |
|
| Login or register to post comments |

Posts: 14523
Set acceleration to 'Hight acceleration'. It will cache the pages.
See: http://codex.gallery2.org/Gallery2:Performance_Tips
Dave
_____________________________________________
Blog & G2 || floridave - Gallery Team
Posts: 15
You want High Acceleration
Then, tell users to avoid downloading static stuff over and over (effect should be tiny, but it's easy). Edit your .htaccess file in gallery2's root adding this:
Now, in each of
create a .htaccess file with:
Now, let's avoid wasting CPU cycles for stuff that you can live without.
Uninstall plugins that you don't use. EXIF can be your main problem.
Avoid imageframes, random picture, newest pictures, RSS, dynamic album select, sitemap, useralbums. If you have a set of known image uploaders and your visitors don't need to login, consider hiding the login/register links, as they can cause a lot of hits from dumb bots. I believe that URL rewriting can be good for you (keep in mind the perf tips), but it's a guess. Try to have all images and albums public (everyone can see)
Remove (or password protect)
/install/and/upgrade/.If you can convince your providers to install a opcode cache (like eaccelerator), you'd be lighter on the CPU.
Last, the deal breaker. If you're lucky enough to convince your hosting to enable mod_cache and mod_mem_cache (mod_disk_cache would work too) in Apache, you'll never hear about CPU issues and your site will be blazing fast. This one should live in http://codex.gallery2.org/Gallery2:Performance_Tips and your dream config would be something like this (in your vhost or apache2.conf, not settable in .htaccess):
<IfModule mod_mem_cache.c> CacheEnable mem / MCacheSize 64000 MCacheMaxObjectCount 1000 MCacheMinObjectSize 1 MCacheMaxObjectSize 6400000 </IfModule>I can benchmark mod_mem_cache versus no cache if you want numbers, the difference is astonishing.
If you want to know whether mod_expires and mod_cache/mem_cache are enabled, create a .php file containing this:
, upload it and visit it.
Then look for Loaded modules. You can paste the modules list here (not all of your php info!) if you're still unsure.
HTH,
Daniel
Posts: 14523
Daniel,
Thanks for the detailed info. It would be great if you could benchmark various settings and then we could create a code page with your findings.
I have not looked but I guess some of your suggestions should go into the existing performance improvements page.
Dave
_____________________________________________
Blog & G2 || floridave - Gallery Team
Posts: 15
Dave,
Great to hear there's interest, I hope I can help more than disturb
I'm trying to get more meaningful benchmarks involving representative load, trying some tools from http://www.opensourcetesting.org/performance.php . In the mean time, here are some results of using mod_disk_cache under ab.
without mod_disk_cache
with mod_disk_cache
See that
1349 (longest request)above? Cache missTotally unreliable as measure of real impact on Gallery2 sites (this test doesn't touch more than a single HTTP request for main.php) ... but aint that still impressive?
The bad news: mod_disk_cache is supported for Apache 2.2 only (2.0 has it as 'experimental'), it needs Server or Virtual Host config (i.e., .htaccess isn't enough) to load mod_cache and mod_disk_cache, the file cache needs to be cleaned in a semi-manual way (cronjob).
Posts: 15
Hmm, http_load also thinks the sky is falling:
without mod_disk_cache
ajaksu@Belkar:~/http_load-12mar2006$ ./http_load -parallel 5 -fetches 1000 ../../urls.txt 1000 fetches, 5 max parallel, 5.40638e+06 bytes, in 53.2069 seconds 5406.39 mean bytes/connection 18.7946 fetches/sec, 101611 bytes/sec msecs/connect: 0.298216 mean, 99.786 max, 0.053 min msecs/first-response: 259.506 mean, 5216.23 max, 0.54 min HTTP response codes: code 200 -- 1000with mod_disk_cache
ajaksu@Belkar:~/http_load-12mar2006$ ./http_load -parallel 5 -fetches 1000 ../../urls.txt 1000 fetches, 5 max parallel, 5.55476e+06 bytes, in 2.22359 seconds 5554.77 mean bytes/connection 449.724 fetches/sec, 2.49811e+06 bytes/sec msecs/connect: 0.094963 mean, 0.365 max, 0.056 min msecs/first-response: 11.0145 mean, 1544.3 max, 0.241 min HTTP response codes: code 200 -- 1000urls.txt content (1000 urls random picked)
Any suggestions on how to create a better benchmark?
Posts: 5649
@ajaksu, this is great info. I typically do benchmarking for new G2 features the same way that you do it. http_load with a distribution of urls is good for overall benchmarking for systemic stuff, and then I typically do a breakdown over several types of pages. These tests were performed with a concurrency of 3 on a fairly fast machine with, eaccelerator, mod_disk_cache and G2 performance turned on to demonstrate high level performance. It will vary considerably on loaded machines when you start hitting memory limits, but under reasonable load if you can keep most of the important parts of your Gallery in memory the caches really perform well.
1. Static assets (css, gif, etc) to get an idea of the "speed of light" on the system under test. I typically use something like http://www.menalto.com/gallery/images/gallery.gif. Expected: median 0ms, 90%ile 2ms.
2. Simple PHP files to get the minimum time to do any PHP work. I typically use something like http://www.menalto.com/gallery/config.php for that. Expected: median 1ms, 90%ile 3ms
3. Individual thumbnail views, eg: http://www.menalto.com/gallery/d/2564-27/family.jpg Expected: median 2ms, 90%ile < 5ms
4. Individual photo view, eg: http://www.menalto.com/gallery/family/NewYork2007/IMG_6564.JPG.html Expected: median <50ms, 90%ile <80ms
5. Album views with a small window (9 images per page, this is a common setting). I typically use something like http://www.menalto.com/gallery/family/ Expected: median <50ms, 90%ile < 80ms
6. Album views with a large window (100 images per page, this is uncommon but useful to find SQL bottlenecks). I don't have a public URL for the what I use for this, but I'm sure you can find one. Expected: median <60ms, 90%ile <100ms
Some important things to note here:
a) #3 should be as close as possible to #2 so that it's the "speed of light" for a PHP response. Since we're employing an image firewall, it can't be any faster than the PHP engine itself.
b) #5 should be very close to #4. If it's not, then our album queries are not as efficient as individual lookups
c) #6 should be very close to #5, else our code for processing album entities is inefficient
For development, I typically benchmark on much slower machines so that inefficiencies are much more visible.
Posts: 15
Bharat,
Great to hear from you and Dave. Thanks a lot for guiding me with benchmarks!
Could you please try putting the following into a .htaccess in gallery's root and running your tests with mod_disk_cache?
Here are my timings, I have a CeleronM 410 @ 1.46GHz with 1GB of DDR2-533MHz RAM and some slow notebook HD, so performance isn't any good compared to your numbers.
Speed of images/gallery.gif
Speed(?) of fat album view
This album has all modules on, 4x4 thumbs on matrix, lots of dummy tags and keywords, rating, custom fields, random picture and the kitchen sink.
Speed(!) of fat album view
Same setup, just added that
ExpiresDefaultsnippet I asked you to test.I'm amazed at what Apache caching can do and you nailed it: your point a) above is what we expect, but Apache is taking PHP and MySQL out of the loop until those 5 minutes end. In my mean timings, #5 is taking 4ms, while #1 is taking 1ms! Obviously obsolescence and cache misses will take a hit, see below.
Here are some cwazy results:
Besides speed cwazyness, it lowers CPU use from a two minute crawl at load 8 to a "what was that?" that lasts two seconds.
I know this is not what you'll see due to cache misses so I'm building a long list of URLs so that I can compare the timings of no-cache to misses only.
I've learned to reload the admin interface to avoid being fooled by stale pages, so I guess highly dynamic sites would have issues too. Perhaps being able to go thru the high load times without hitting the CPU hard is very desirable, I think adding a mod_disk_cache + mod_expires plugin (for Apache >= 2.2) can become a killer feature
Posts: 5649
That is pretty interesting stuff. It's interesting to me that apachebench would be affected by mod_expires, since I would expect it to not be adding If-Modified-Since to its requests (ie: I wouldn't expect it to obey cache headers). However, I think that it makes sense to add a snippet like this to the .htaccess file. You need to guard it, though for installs that don't have mod_expires active, so it'd look like:
Would you like to take a shot at adding this information about mod_disk_cache and mod_expires to the http://codex.gallery2.org/Gallery2:Performance_Tips page? That would be very useful for all! I'll investigate getting this into the default .htaccess file for our distribution, too.
Posts: 15
You're right about guarding and I'll add that users should be warned about what this caching means. ApacheBench isn't obeying cache headers, httpd is: you can delete the .php and Apache will still serve the cached HTML + images. Which means so-stale-I'd-call-'em-frozen pages until they expire... doesn't sound so good, does it? :/
Now, I think we can reap some of the benefits while staying 100% safe from HTML staleness if we limit caching to cached images (the PHP scriptlets wouldn't run before Expire, but we'd have double disk space used for caching), JS and CSS.
Anyway, for many large sites, full caching as described in my previous posts would be the best.
Do you think it'd be possible to trigger a 'no-cache' request to Apache from Gallery2 to regenerate a known stale page (say, after editing an item, in Admin, etc.)? That would make this setup even more awesome. Perhaps simply displaying a "Generated at:" text could solve most issues.
Regarding Gallery2:Performance_Tips, yes, I'll be glad to add mod_X and .htaccess stuff, plus (if you think it's relevant):
I've stopped tinkering with Apache caching for now because cache misses are still costly, so I'm checking memcached and APC's memory cache to avoid issues with MySQL key cache granularity. I plan to check opcode caches after this, then cache warming using sitemaps.
I'll join you on IRC to discuss whether I should neat up and post mod_cache and .htaccess now or keep doing the DB cache thing
Posts: 15
Just a note: I've got Gallery2 working with memcached via adodb's support. You'd have to download adodb to get some support files, add some configuration to adodb.inc.php and change some Execute commands in GalleryStorage.class to ExecuteCached.
Since I'm still figuring how things work, expect better instructions soon
If someone with knowledge on the many G2 caches, maps and storages wants to suggest/ask/explain something, I'll all ears
Regards,
Daniel
Posts: 1
Hi
I read your discussion about mod_cache and mem_cache.
With mod_cache I have about 8 seconds, without about 20, but only when I test on localhost
so looks ok, but when I test it from another host (with the same LAN network) the times are exactly the same as without mod_cache.
ab -n 1000 -c 5 http://10.0.0.9/bench.php
Server Software: Apache/2.2.9
Server Hostname: 10.0.0.9
Server Port: 80
Time taken for tests: 40.532848 seconds
Requests per second: 24.67 [#/sec] (mean)
Time per request: 40.533 [ms] (mean, across all concurrent requests)
Transfer rate: 11464.16 [Kbytes/sec] received
When I test from localhost and different host the cache are write to the /var/www/cache, so it looks ok.
my config in httpd.conf:
I don't known where ther problem is, I hope You help me. Thanks.
Posts: 1
Article about mod_deflate settings like on Amazon EC2 AMI
http://railsgeek.com/2008/12/16/apache2-httpd-improving-performance-mod_deflate-gzip