Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

memcached vs. internal caching in PHP?

I'm working on some old(ish) software in PHP that maintains a $cache array to reduce the number of SQL queries. I was thinking of just putting memcached in its place and I'm wondering whether or not to get rid of the internal caching. Would there still be a worthwihle performance increase if I keep the internal caching, or would memcached suffice?

like image 869
bcoughlan Avatar asked Jun 14 '10 14:06

bcoughlan


People also ask

What does memcached do in PHP?

Memcached is an object caching system. It is primarily used to cache the results of database queries, helping dynamic websites like WordPress® and Drupal to serve pages faster. It can also significantly decrease resource use on a busy web server by reducing calls to the database.

Is memcached faster than mysql?

Benchmarks suggest that queries and DML operations (inserts, updates, and deletes) that use the memcached interface are faster than traditional SQL.

Which is faster Redis or memcached?

Redis uses a single core and shows better performance than Memcached in storing small datasets when measured in terms of cores. Memcached implements a multi-threaded architecture by utilizing multiple cores. Therefore, for storing larger datasets, Memcached can perform better than Redis.


2 Answers

According to this blog post, the PHP internal array is way faster than any other method:

Cache Type                Cache Gets/sec

Array Cache                       365000
APC Cache                          98000
File Cache                         27000
Memcached Cache (TCP/IP)           12200
MySQL Query Cache (TCP/IP)          9900
MySQL Query Cache (Unix Socket)    13500
Selecting from table (TCP/IP)       5100
Selecting from table (Unix Socket)  7400
like image 177
István Ujj-Mészáros Avatar answered Oct 07 '22 15:10

István Ujj-Mészáros


It seems likely that memcache (which is implemented on the metal) would be faster than some php interpreted caching scheme.

However: if it's not broken, don't fix it.

If you remove the custom caching code, you might have to deal with other code that depends on the cache. I can't speak for the quality of the code you have to maintain but it seems like one of those "probably not worth it" things.

Let me put it this way: Do you trust the original developer(s) to have written code that will still work if you rip out the caching? (I probably wouldn't)

So unless the existing caching is giving you problems I would recommend against taking it out.

like image 35
Kris Avatar answered Oct 07 '22 13:10

Kris