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
PHP version = 4.4.8 cgi
Webserver = Apache/2.2.8 (Unix) mod_ssl/2.2.8 OpenSSL/0.9.8b DAV/2 mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635
Database = mysqlt 4.1.22-standard, lock.system=flock
Toolkits = ArchiveUpload, Exif, Gd, Thumbnail, Getid3, LinkItemToolkit, SquareThumb
Acceleration = none, none
Operating system = Linux
Default theme = matrix
gettext = enabled
Locale = en_US
Browser = Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9) Gecko/2008052906 Firefox/3.0
Rows in GalleryAccessMap table = 51
Rows in GalleryAccessSubscriberMap table = 8300
Rows in GalleryUser table = 2
Rows in GalleryItem table = 8284
Rows in GalleryAlbumItem table = 257
Rows in GalleryCacheMap table = 0

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
floridave
floridave's picture

Joined: 2003-12-22
Posts: 14523
Posted: Sat, 2008-06-28 16:21

Set acceleration to 'Hight acceleration'. It will cache the pages.
See: http://codex.gallery2.org/Gallery2:Performance_Tips

Dave
_____________________________________________
Blog & G2 || floridave - Gallery Team

Login or register to post comments
ajaksu

Joined: 2008-07-04
Posts: 15
Posted: Fri, 2008-07-04 20:01

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:

ExpiresActive On
ExpiresDefault "access plus 1 week"

Now, in each of

/modules/core/data/ ; /modules/icons/iconpacks/KSIcons/ (and other packs) ; 
/modules/search/ ; /modules/rating/images/ ; /themes/matrix/images/ ; /themes/matrix/ ; 
/images/ ; /modules/comment/ 

create a .htaccess file with:

ExpiresActive On
ExpiresDefault "access plus 1 year"

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:

<?php
phpinfo();
?>

, 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

Login or register to post comments
floridave
floridave's picture

Joined: 2003-12-22
Posts: 14523
Posted: Fri, 2008-07-04 21:38

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

Login or register to post comments
ajaksu

Joined: 2008-07-04
Posts: 15
Posted: Sat, 2008-07-05 06:56

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

ajaksu@Belkar:~/$ ab -c 5 -n 1000 http://127.0.0.1/gallery2/main.php
This is ApacheBench, Version 2.0.40-dev <$Revision: 1.146 $> apache-2.0
[...]
Server Software:        Apache/2.2.4
Server Hostname:        127.0.0.1
Server Port:            80

Document Path:          /gallery2/main.php
Document Length:        11509 bytes

Concurrency Level:      5
Time taken for tests:   122.574364 seconds
Complete requests:      1000
Failed requests:        0
Write errors:           0
Total transferred:      11877000 bytes
HTML transferred:       11509000 bytes
Requests per second:    8.16 [#/sec] (mean)
Time per request:       612.872 [ms] (mean)
Time per request:       122.574 [ms] (mean, across all concurrent requests)
Transfer rate:          94.62 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.0      0       0
Processing:   115  611 416.4    582    5989
Waiting:      108  535 313.7    516    4774
Total:        115  611 416.4    582    5989

Percentage of the requests served within a certain time (ms)
  50%    582
  66%    685
  75%    754
  80%    814
  90%    965
  95%   1139
  98%   1393
  99%   1710
 100%   5989 (longest request)

with mod_disk_cache

ajaksu@Belkar:~/$ ab -c 5 -n 1000 http://127.0.0.1/gallery2/main.php
This is ApacheBench, Version 2.0.40-dev <$Revision: 1.146 $> apache-2.0
Server Software:        Apache/2.2.4
Server Hostname:        127.0.0.1
Server Port:            80

Document Path:          /gallery2/main.php
Document Length:        11509 bytes

Concurrency Level:      5
Time taken for tests:   1.868203 seconds
Complete requests:      1000
Failed requests:        0
Write errors:           0
Total transferred:      11910000 bytes
HTML transferred:       11509000 bytes
Requests per second:    535.27 [#/sec] (mean)
Time per request:       9.341 [ms] (mean)
Time per request:       1.868 [ms] (mean, across all concurrent requests)
Transfer rate:          6225.23 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.0      0       0
Processing:     1    8  95.9      1    1349
Waiting:        0    8  95.8      1    1349
Total:          1    8  95.9      1    1349

Percentage of the requests served within a certain time (ms)
  50%      1
  66%      1
  75%      1
  80%      1
  90%      1
  95%      8
  98%     15
  99%     34
 100%   1349 (longest request)

See that 1349 (longest request) above? Cache miss :)

Totally 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).

Login or register to post comments
ajaksu

Joined: 2008-07-04
Posts: 15
Posted: Sat, 2008-07-05 07:42

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 -- 1000

with 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 -- 1000

urls.txt content (1000 urls random picked)

http://127.0.0.1/gallery2/main.php
http://127.0.0.1/gallery2/v/1361885-lg.jpg.html
http://127.0.0.1/gallery2/v/DSCN2259.JPG.html
http://127.0.0.1/gallery2/v/DSCN2318.JPG.html
http://127.0.0.1/gallery2/v/DSCN2318_001.JPG.html
http://127.0.0.1/gallery2/v/IMG_1277.JPG.html
http://127.0.0.1/gallery2/v/IMG_1282.JPG.html
http://127.0.0.1/gallery2/v/IMG_1340.JPG.html
http://127.0.0.1/gallery2/v/IMG_1496.JPG.html
http://127.0.0.1/gallery2/v/img_1603.jpg.html
http://127.0.0.1/gallery2/main.php
http://127.0.0.1/gallery2/modules/core/data/gallery.css
http://127.0.0.1/gallery2/modules/icons/iconpacks/silk/icons.css
http://127.0.0.1/gallery2/themes/matrix/theme.css
http://127.0.0.1/gallery2/modules/search/SearchBlock.js
http://127.0.0.1/gallery2/images/galleryLogo_sm.gif
http://127.0.0.1/gallery2/d/12-2/1361885-lg.jpg
http://127.0.0.1/gallery2/d/16-2/IMG_1340.JPG
http://127.0.0.1/gallery2/d/21-2/DSCN2318.JPG
http://127.0.0.1/gallery2/d/26-2/img_1603.jpg
http://127.0.0.1/gallery2/d/31-2/IMG_1496.JPG
http://127.0.0.1/gallery2/d/36-2/DSCN2259.JPG
http://127.0.0.1/gallery2/d/41-2/DSCN2318_001.JPG
http://127.0.0.1/gallery2/d/46-2/IMG_1277.JPG
http://127.0.0.1/gallery2/d/51-2/IMG_1282.JPG
http://127.0.0.1/gallery2/images/gallery.gif
http://127.0.0.1/gallery2/modules/icons/iconpacks/silk/advanced_search.png
http://127.0.0.1/gallery2/modules/icons/iconpacks/silk/rss_feed.png
http://127.0.0.1/gallery2/modules/icons/iconpacks/silk/view_slideshow.png
http://127.0.0.1/gallery2/themes/matrix/images/nav_next.gif
http://127.0.0.1/gallery2/themes/matrix/images/nav_last.gif

Any suggestions on how to create a better benchmark?

Login or register to post comments
bharat
bharat's picture

Joined: 2002-05-21
Posts: 5649
Posted: Sat, 2008-07-05 21:27

@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.

Login or register to post comments
ajaksu

Joined: 2008-07-04
Posts: 15
Posted: Sun, 2008-07-06 01:13

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?

ExpiresActive On
ExpiresDefault "access plus 5 minutes"

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

ajaksu@Belkar:~/$ ab -c 3 -n 1000 http://127.0.0.1/gallery2/images/gallery.gif
[...]
Concurrency Level:      3
Time taken for tests:   0.441083 seconds
Complete requests:      1000
Failed requests:        0
Write errors:           0
Total transferred:      1627626 bytes
HTML transferred:       1181180 bytes
Requests per second:    2267.15 [#/sec] (mean)
Time per request:       1.323 [ms] (mean)
Time per request:       0.441 [ms] (mean, across all concurrent requests)
Transfer rate:          3602.50 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.7      0       9
Processing:     0    1   0.9      1      10
Waiting:        0    0   0.7      0       9
Total:          0    1   1.2      1      10

Percentage of the requests served within a certain time (ms)
  50%      1
  66%      1
  75%      1
  80%      1
  90%      1
  95%      1
  98%      7
  99%      8
 100%     10 (longest request)

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.

ajaksu@Belkar:~/$ ab -c 3 -n 1000 http://127.0.0.1/gallery2/v/sfgs/
[...]
Document Path:          /gallery2/v/sfgs/
Document Length:        146538 bytes

Concurrency Level:      3
Time taken for tests:   134.481482 seconds
Complete requests:      1000
Failed requests:        0
Write errors:           0
Total transferred:      146836000 bytes
HTML transferred:       146538000 bytes
Requests per second:    7.44 [#/sec] (mean)
Time per request:       403.444 [ms] (mean)
Time per request:       134.481 [ms] (mean, across all concurrent requests)
Transfer rate:          1066.27 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0   12  45.8      0     283
Processing:   130  390 280.2    368    5224
Waiting:        0  318 225.5    311    3763
Total:        130  402 280.8    391    5492

Percentage of the requests served within a certain time (ms)
  50%    391
  66%    417
  75%    454
  80%    476
  90%    553
  95%    632
  98%    764
  99%   1223
 100%   5492 (longest request)

Speed(!) of fat album view
Same setup, just added that ExpiresDefault snippet I asked you to test.

ajaksu@Belkar:~/$ ab -c 3 -n 1000 http://127.0.0.1/gallery2/v/sfgs/
[...]
Document Path:          /gallery2/v/sfgs/
Document Length:        146538 bytes

Concurrency Level:      3
Time taken for tests:   1.597890 seconds
Complete requests:      1000
Failed requests:        0
Write errors:           0
Total transferred:      147229872 bytes
HTML transferred:       146831076 bytes
Requests per second:    625.83 [#/sec] (mean)
Time per request:       4.794 [ms] (mean)
Time per request:       1.598 [ms] (mean, across all concurrent requests)
Transfer rate:          89980.54 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1   1.2      1      10
Processing:     2    3   1.6      3      21
Waiting:        0    1   1.0      1       9
Total:          4    4   1.6      4      21

Percentage of the requests served within a certain time (ms)
  50%      4
  66%      4
  75%      4
  80%      4
  90%      4
  95%      5
  98%     11
  99%     12
 100%     21 (longest request)

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

Login or register to post comments
bharat
bharat's picture

Joined: 2002-05-21
Posts: 5649
Posted: Sun, 2008-07-06 18:53

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:

<IfModule mod_expires.c>
  ExpiresActive On
  ExpiresDefault "access plus 5 minutes"
</IfModule>

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.

Login or register to post comments
ajaksu

Joined: 2008-07-04
Posts: 15
Posted: Sun, 2008-07-06 22:25

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):

  • links to the extensions I'm using (Firebug, LiveHTTPHeades, YSlow, etc.)
  • links to cacheability and optimization analysis sites
  • a few things I'm still trying :)

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 :)

Login or register to post comments
ajaksu

Joined: 2008-07-04
Posts: 15
Posted: Tue, 2008-07-08 17:41

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

Login or register to post comments
KarolGT

Joined: 2008-09-08
Posts: 1
Posted: Mon, 2008-09-08 18:25

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

Quote:
ab -n 1000 -c 5 http://localhost/bench.php
Server Software: Apache/2.2.9
Server Hostname: localhost
Server Port: 80

Time taken for tests: 8.284 seconds
Requests per second: 120.72 [#/sec] (mean)
Time per request: 8.284 [ms] (mean, across all concurrent requests)
Transfer rate: 53223.76 [Kbytes/sec] received

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:

Quote:
#Cache

CacheDefaultExpire 600
CacheMaxExpire 3600
CacheIgnoreCacheControl On
CacheIgnoreNoLastMod On
CacheEnable disk /
CacheRoot /var/www/cache

CacheEnable mem /
MCacheSize 64000
#MCacheMaxObjectCount 1000
#MCacheMinObjectSize 1
#MCacheMaxObjectSize 6400000

I don't known where ther problem is, I hope You help me. Thanks.

Login or register to post comments
Mikhailov Anatoly

Joined: 2008-12-18
Posts: 1
Posted: Thu, 2008-12-18 04:52

Article about mod_deflate settings like on Amazon EC2 AMI
http://railsgeek.com/2008/12/16/apache2-httpd-improving-performance-mod_deflate-gzip

Login or register to post comments