PHP caching and optimization
|This page is outdated, but if it were updated, it may still be useful. Please help by correcting, augmenting and revising the text into an up-to-date form.|
- Which PHP cache is used? APC or Turck MMcache?
Wikimedia currently uses APC.
Caches compiled PHP scripts to avoid the overhead of parsing and compiling the code every time pages are loaded.
Also provides a general purpose PHP shared memory store, you can stuff whatever data you like in it (e.g. sessions, arbitrary objects), and it's much faster than distributed caches like memcache if you don't need the distribution.
It contains a optimizer that's currently marked as 'experimental'.
As the 'official' PHP Accelerator (it's destined for inclusion in PHP6 as a default), it's also very easy to install:
pecl install apc
I installed it in a rush on a very heavily loaded (95% CPU) server that was terribly bogged down with requests. After the apache restart it served a million PHP file hits in 10 mins with about 10% CPU.
YMMV, but since they (notably Rasmus) sorted out the big bugs it used to have it's worked flawlessly for me. MarcusBointon
PHPA or Zend Optimizer
- These two projects are not free software (though they are free of charge), which makes me rather leery. Although since they are theoretically just drop-in accelerators and are not required, we would not be made dependant on closed-source software by using them for a boost. --Brion VIBBER
- While I too wish it was OSS, I don't see what the loss is in at least giving them a shot. If they change their license in the future, then we are (at the very least) no worse off than we are now. Anything to help the performance is horribly needed. Wikipedia is nearly unusable during the daytime hours, and any kind of solution is dearly needed. --Marumari
- I'll give them a shot, see if they're less problematic than APC. --Brion VIBBER
- I've installed PHPA, we'll see how it goes. --Brion VIBBER 21:34 20 Mar 2003 (UTC)
Comparing the 15 minutes before installation with the 15 minutes after, using the English Wikipedia logfile:
20030320211530 |20030320213030| 20030320214530 Before cutoff: 2689 pages served, runtime 14463.218 seconds That's 2.98777777777778pages/sec served At avg time per page of 5.37866046857568 After cutoff: 4169 pages served, runtime 8020.671 seconds That's 4.63222222222222pages/sec served At avg time per page of 1.92388366514752
Load average has also fallen somewhat, from 15-20 to 7-10 range. I'm reasonably happy with it so far, hopefully it won't have any other problems. (Note: I've since corrected the pages per second rates above, they was initially calculated with an incorrect ratio.) --Brion VIBBER 21:51 20 Mar 2003 (UTC)
Well, that works out to a 55% percent increase in throughput and a 64% decrease in load time. If it doesn't break anything, it seems like a big win to me. --Marumari 22:08 20 Mar 2003 (UTC)
- That's only a few minutes -- during which traffic type can change -- so it's not a reliable data set, but it's a good sign. :) --Brion VIBBER 22:11 20 Mar 2003 (UTC)
Okay, 90 minutes on either side:
20030320200030 |20030320213030| 20030320230030 Before cutoff: 19682 pages served, runtime 53717.1640000001 seconds That's 3.64481481481481pages/sec served At avg time per page of 2.72925332791383 After cutoff: 24891 pages served, runtime 59320.2220000005 seconds That's 4.60944444444444pages/sec served At avg time per page of 2.38319963038851
And compare with the same time period yesterday, since there's a dropoff in traffic over this period and we need to correct:
20030319200030 |20030319213030| 20030319230030 Before cutoff: 20774 pages served, runtime 69988.5320000001 seconds That's 3.84703703703704pages/sec served At avg time per page of 3.36904457494946 After cutoff: 21771 pages served, runtime 66441.7349999997 seconds That's 4.03166666666667pages/sec served At avg time per page of 3.05184580405125
Yes, that looks like a bigger relative improvement than just the traffic dropoff, which is definitely nice. (Also note that the runtime figures in the wiki log don't directly show script load time, which is one of the principal things that PHPA helps with.) --Brion VIBBER 23:16 20 Mar 2003 (UTC)+
eAccelerator (formerly Turck MMCache)
Claims to be a bit faster than PHPA, a bit slower than Zend Accelerator, and is GPL. May want to consider trying this.
Now, the Fastest GPL Accelerator in GPL. (see above benchmarks)
- Can't say I've ever heard of it. It certainly might be worth trying. Perhaps we could also contact Zend and see if they would offer us a free license of their optimizing software? --Marumari 19:41 11 Apr 2003 (UTC)
How nice is it! It faster then PHPA now :)
- The 2.4.* release claims to be faster than Zend Performance Suite 3.5.0. See the link above for the benchmark. They benchmarked the start page of phpMyAdmin 2.5.1 with the Apache Benchmark program. I tried it out on wigen.net and it improved the performance a lot! Though I have not done any real benchmarking. -- Alexander Wigen, wigen.net 27 Sep 2004
I've had a shot with it on a site and it seems to work quite well, i.e. better than MMCache (but no, I lost the logs to prove this, and the site is now defunct so I can't show evidence). It wasn't as good as Zend though. --Haggis 10:08, 28 Mar 2005 (UTC)
Some Instructions on installation of eaccelerator may help here....
I have written an article about installing and benchmarking eaccelerator using ab and phpMyAdmin here: . It is geared toward OS X but should hold true for any unix-style system. - William
HOWTO install eAccelerator:
You need to get at least a beta of 0.9.5 for MediaWiki 1.7, as 0.9.4 doesn't support PHP5. I found the SVN-snapshots to work best, you can get them here. Then just follow the instructions for installing from source and set your ini settings accordingly.
- I found that i had to download the SVN snapshot in order it to work. Using the currently official 0.9.5 release would cause MediaWiki to only show a blank page even though the rest of my php site would function properly and EA showed pages being cached (php5.2.0; Apache2.2.3; MediaWiki1.8.2) --126.96.36.199 21:58, 7 January 2007 (UTC)
- Thanks for this note about using the SVN version. I had the same thing with the stable version, and for me as well the SNV fixed the problem.
I don't know whether you need to set some options in the MediaWiki setup - I didn't, but EA seems to works on my wiki site as well, as the control.php shows the wiki scripts to be cached.
eAccelerator Installation Guide Installing eAccelerator in Ubuntu Server
IMHO this is a superior Howto than the one below.