59

I'm trying to improve performance under high load and would like to implement opcode caching. Which of the following should I use?

I'm also open to any other alternatives that have slipped under my radar.

Currently running on a stock Debian Etch with Apache 2 and PHP 5.2

[Update 1]

HowtoForge installation links added

[Update 2]

Based on the answers and feedback given, I have tested all 3 implementations using the following Apache JMeter test plan on my application:

  • Login
  • Access Home Page

With 50 concurrent connections, the results are as follows:

No Opcode Caching
No Opcode Caching

APC
APC

eAccelerator
eAccelerator

XCache
XCache

Performance Graph (smaller is better)
Performance Graph

From the above results, eAccelerator has a slight edge in performance compared to APC and XCache. However, what matters most from the above data is that any sort of opcode caching gives a tremendous boost in performance.

I have decided to use APC due to the following 2 reasons:

  • Package is available in official Debian repository
  • More functional control panel

To summarize my experience:

Ease of Installation: APC > eAccelerator > XCache
Performance: eAccelerator > APC, XCache
Control Panel: APC > XCache > eAccelerator

2
  • APC has some problems like Connection Reset!
    – Abadis
    Jan 27, 2015 at 19:14
  • @Pacerier The definition of what is on-topic has changed over the years, so this "became" off-topic.
    – James
    Jun 20, 2015 at 21:48

7 Answers 7

18

I think the answer might depend on the type of web applications you are running. I had to make this decision myself two years ago and couldn't decide between Zend Optimizer and eAccelerator.

In order to make my decision, I used ab (apache bench) to test the server, and tested the three combinations (zend, eaccelerator, both running) and proved that eAccelerator on its own gave the greatest performance.

If you have the luxury of time, I would recommend doing similar tests yourself, and making the decision based on your results.

2
  • Why is HipHop not mentioned?
    – Pacerier
    Oct 17, 2014 at 16:25
  • 1
    Because HipHop is neither an opcode cache nor did it exist when this question was asked.
    – BlaM
    Jun 22, 2015 at 13:50
6

I have run several benchmarks with eAcclerator, APC, XCache, and Zend Optimizer (even though Zend is an optimizer, not a cache).

Benchmark Results http://blogs.interdose.com/dominik/wp-content/uploads/2008/04/opcode_wordpress.png

Result: eAccelerator is fastest (in all tests), followed by XCache and APC. (The one in the diagram is the number of seconds to call a WordPress home page 10,000 times).

Zend Optimizer made everything slower (!).

5

I use APC because it was easy to install in windows and I'm developing on WAMP.

Integrating APC into PHP6 was discussed here: http://www.php.net/~derick/meeting-notes.html#add-an-opcode-cache-to-the-distribution-apc

And there are directions on installing APC on Debian Etch here: http://www.howtoforge.com/apc-php5-apache2-debian-etch

4

I can't tell you for sure, but the place where I am working now is looking at APC and eAccelerator. However, this might influence you - APC will be integrated into a future release of PHP (thanks to Ed Haber for the link).

3

I've had good success with eAccelerator (speed improvement with no load is noticable) but XCache also seems pretty promising. You may want to run some trials with each though, your application might scale differently on each.

1

I've been using XCache for more than a year now with no problems at all.

I tried to switch to eAccelerator, but ended up with a bunch of segmentation faults (it's less forgiving of errors). The major benefit to eAccelerator is that it's not just an opcode cache, it's also an optimizer.

You should fully test out your application with each one of them to make sure there aren't any problems, and then I'd use apachebench to test it under load.

1

These add-ons have historically introduced lots of weird bugs to track down. These bugs can cause inconsistent behaviour which can't be diagnosed easily because it depends on the state of the cache.

So I'd say:

  1. Don't use any of the above. Buy more tin instead, it's a more reliable (i.e. error-free) way of increasing performance. OR
  2. Go with whichever of the above is the most robust, having tested the pants off your application.

But I'd say:

  1. Make sure it's REALLY PHP code parsing that is causing your performance problems by profiling your application. I think it's extremely likely that it isn't - in which case you'd be wasting your time (actually, using your time negatively productively) by installing any of them.
1
  • We can use some of them to cache data. For example APC is capable of caching both data and opcode. but I really agree with your last sentence:"Make sure it's REALLY PHP code parsing that is causing your performance problems"
    – Abadis
    Jan 27, 2015 at 19:17

Not the answer you're looking for? Browse other questions tagged or ask your own question.