Memcached vs APC which one should I choose? [closed]
Asked Answered
D

7

165

I read this article: http://www.mysqlperformanceblog.com/2006/09/27/apc-or-memcached/ from way back when.. I want to get the best caching engine available so that my application is really fast. Of course I don't want to over-cache but I want to at least choose the best thing out there. In that article it says Memcached is slow and apc is fast so why is everyone choosing memcached?

http://framework.zend.com/manual/en/zend.cache.backends.html#zend.cache.backends.twolevels here is says "use a fast one (but limited) like Apc, Memcache... and a "slow" one like File, Sqlite..." do you think using Apc as the fast and Memcache as the slow is a good idea?

Doloroso answered 2/5, 2009 at 15:31 Comment(5)
BTW: you should use APC even if you don't use apc_store. Opcode cache alone makes PHP few times faster.Preglacial
@porneL: what do you mean? Does APC increase PHP speed after just the installation, even if I don't add code to cache anything in my scripts?Julietajulietta
@Marco Demaio: Indeed. APC is mainly a PHP optimizer (optimizes by default as long as it's enabled), and apc_store() is just an extra bonus on top of that.Preglacial
in 2014, if you only use it for caching on 1 server, go for APCu.Stellastellar
Also https://mcmap.net/q/151551/-apc-vs-eaccelerator-vs-xcache/632951Triolein
D
275

Memcached is a distributed caching system, whereas APC is non-distributed - and mainly an opcode cache.

If (and only if) you have a web application which has to live on different webservers (loadbalancing), you have to use memcache for distributed caching. If not, just stick to APC and its cache.

You should always use an opcode cache, which APC is (also APC will get integrated into php6 iirc, so why not start using it now).

You can/should use both for different purposes.

Dissatisfied answered 2/5, 2009 at 15:33 Comment(6)
Stunning answer +1. My question now is what's an opcode cache?Julietajulietta
@Dissatisfied If you have different servers (like a cloud loadbalaced environment) as long as you don't need to maintain/share state across them, APC will also work fine as a straight up memory cache--though maybe not as optimal as each cloud instance will have to warm their own cache...Onlybegotten
An opcode cache is one that compiles the plain PHP code into machine code ("opcode") and then stores it in the compiled form for future requests (until it detects the original PHP file has changed). This means that PHP doesn't have to run this compile step on every single request, saving some time. It's just one of the ways to help ensure a speedy site (amongst many others).Pevzner
There's an interesting slideshow that explains some of the differences with diagrams and benchmarks, here: slideshare.net/FordAntiTrust/php-performance-with-apc-memcachedPevzner
Can memechached be used in non-distributed system instead of APC? It will be good to keep only one if in the future you will have more machines. right? Or use them both, one for opcode and the other for extensible caching?Lake
Is this answer still up-to-date? According to this wikipedia article: en.wikipedia.org/wiki/… it seems that APC caches the output in shared memory Or is shared memory and distributed systems not the same?Aniline
A
44

Memcached if you need to preserve state across several web servers (if you're load balanced and it's important that what's in the cache is the same for all servers).

APC if you just need access to quick memory to read (& write) on a (or each) server.

Remember APC can also compile and speed up your script execution time. So you could for example be using APC for increased execution performance, while using memcached for cache storage.

Alonso answered 2/5, 2009 at 15:31 Comment(2)
APC can cache storage too.... Or?Nonfeasance
2014 update: PHP 5.5 will nativly include Zend Optimizer Plus (which is only for opcache, so not for user cache) and it seems APC will not be developed beyond PHP 5.4? However there is now APCu pecl.php.net/package/APCu, which took only the user cache parts of APCStellastellar
S
20

The main advatage of APC is opcode cache. Since PHP 5.5 integrated OpCache to its core and APC for PHP 5.4 is still flagged as beta, it's not official annoucement, but the development of APC would be dropped in near future.

So I would recommend you to choose Memcached.

Sardonyx answered 7/1, 2014 at 4:6 Comment(1)
I have spent hours on the web to think about it, and I have the same conclusion.Kiersten
B
9

I use both one for speed and the other to sync all my servers. If you do use memcache then please do keep in mind of the open ports which you will need to block with iptables.

Baerl answered 22/3, 2012 at 0:32 Comment(0)
A
6

Hey Thomaschaaf, I hope this is not tool late for you but please note that APC has some issues related to "user-cache". To make a long story short, when you set time-outs for cache entries, or if your apache crashes inside internal APC code (timeout, for example), then you may suffer some problems.

I have an entry about the issue here: http://nirlevy.blogspot.com/2009/06/apc-futexwait-lockdown-make-your-apache.html, and you should also read http://t3.dotgnu.info/blog/php/user-cache-timebomb.html (from one of the APC developers i think)

Aristate answered 4/8, 2009 at 7:39 Comment(1)
I stumbled across this and wanted to update that it seems to have been addressed now (as it should, 2 years later!). Here's a closed bug report, for example: bugs.debian.org/cgi-bin/bugreport.cgi?bug=572529Spectroscope
A
1

I use only APC since APC is a code cache and acts like memcache ! Only 1 config file instead of 2.

And only 1 place to monitor both cache.....

Alliance answered 21/4, 2012 at 12:37 Comment(0)
R
1

It depends on what you are doing but for my drupal websites running on a VPS I find APC works great! If you are running CentOS 6 it is available as a yum update so dead simple to install and no config as the defaults are reasonable. A no brainer imho.

Rammish answered 2/3, 2013 at 19:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.