Memcache performance on Google App Engine/PHP

Miss Adesso
Miss Adesso
Published in
2 min readJan 7, 2018

When you start developing on Google App Engine (in my case: Standard PHP Environment), there are a couple of options for caching application data:

  • for very-short-duration caching (within one request), there is temporary in-memory file storage, but that is really only good to prepare a file to be saved somewhere else (for example: take an existing image, do some ImageMagick operations on it, and then save/post it). This is included in your standard service, but since it’s kept in memory, I wouldn’t use it for 500MB video files.
  • If you need guaranteed retrieval even for these short durations, you could go with a SQL database, or a dedicated Memcache (in the logic that, since you can scale the Memcache yourself, you can make sure that it’s big enough to guarantee retrieval X seconds later)
  • for medium duration (hours/days) best-effort data retrieval there is the choice between shared or dedicated Memcache.
  • another option for medium-term caching could be saving in a database: Google Cloud SQL or saving as a file: Google Cloud Storage. Both of these services are paid extras.

I decided to stay with the standard shared Memcache for the moment, but wanted to know just how fast the performance was. Does it take 10 msec to retrieve something? Does the size of the data matter? So I built a quick benchmark app. These are some typical results:

### MEMCACHE BENCHMARK
# Running on <omitted>.missadesso.com (Google App Engine/1.9.54)
# Using values size 1 KB
# Using 500 repetitions
Memcache WRITE speed: 648 ops/sec (1.54 ms/op)
Memcache READ hits: 681 ops/sec (1.47 ms/op)
Memcache READ misses: 762 ops/sec (1.31 ms/op)

For bigger data chunks (100KB):

### MEMCACHE BENCHMARK
# Running on <omitted>.missadesso.com (Google App Engine/1.9.54)
# Using values size 100 KB
# Using 500 repetitions
Memcache WRITE speed: 449 ops/sec (2.2 ms/op)
Memcache READ hits: 461 ops/sec (2.2 ms/op)
Memcache READ misses: 808 ops/sec (1.24 ms/op)

So in short:

  • Memcache writing peaks at 700 tps (transactions per second),
  • Memcache reading starts at 800 tps for small data (or for cache misses), and goes down with the size of the data.
  • For chunks of 500KB, you get about 200 tps.

For comparison: the local Memcache speed (using Google’s development server dev_appserver.py app.yaml on my Macbook Pro Retina 2015) is about 4 times slower:

### MEMCACHE BENCHMARK
# Running on localhost (Development/2.0)
# Using values size 1 KB
# Using 500 repetitions
Memcache WRITE speed: 164 ops/sec (6.1 ms/op)
Memcache READ hits: 165 ops/sec (6.1 ms/op)
Memcache READ misses: 169 ops/sec (5.9 ms/op)

Both write and read speeds stay around 160 tps, even when blob size goes to 100KB. The development Memcache gives up at +- 60MB of total storage. Just keep that in mind.

--

--