Skip to content

Creating scalable memcache client in Go

Aliaksandr Valialkin edited this page Dec 17, 2012 · 4 revisions

=============

Intro

Do you think memcache server can process up to 50Kqps on an average laptop? This is plain wrong! It can serve up to 700Kqps on the same laptop from more than 2K workers. Read below for the proof.

=============

How-to

  • Keep low the number of TCP connections to memcache server.
  • Pipeline requests over already established TCP connections.
  • Buffer requests and responses.
  • Flush outgoing buffers only if absolutely required.
  • Avoid expensive operations in hot paths.
  • Investigate go-memcache client source code.

====================

Benchmark results

Legend

  • original_client - gomemcache client
  • new_client - go-memcache client
  • original_server - memcached v1.4.13
  • new_server - go-memcached server
  • Kqps - thousands queries per second
  • workersCount - the number of workers concurrently performing workerMode operation via client API
  • workerMode values:
    • GetMiss - get() request for missing key
    • GetHit - get() request for existing key
    • Set - set() requests for distinct keys
    • GetSetRand - concurrent get() and set() requests for distinct keys. The number of get() requests is proportional to setRatio parameter

Benchmark results have been generated with go-memcached-bench tool on a laptop with the following configuration:

CPU: Intel(R) Core(TM) i5-2450M CPU @ 2.50GHz
RAM: 4Gb
Both original_server and new_server use default configs.

With workerMode=GetMiss, new_client is faster than the original_client by more than 13x with 512 workers. The original_client stops scaling at 8 workers with 50Kqps, while new_client scales up to 2048 workers with 700Kqps.

With workerMode=GetHit, new_client is faster than the original_client by more than 5x with 512 workers. The original_client stops scaling at 8 workers with 40Kqps, while new_client scales up to 2048 workers with 220Kqps.

With workerMode=Set, new_client is faster than the original_client by more than 6x with 512 workers. The original_client stops scaling at 8 workers with 40Kqps, while new_client scales up to 2048 workers with 230Kqps.

With workerMode=GetSetRand, new_client is faster than the original_client by more than 5x with 512 workers. The original_client stops scaling at 8 workers with 40Kqps, while new_client scales up to 4096 workers with 170Kqps.

New_server scales better than the original_server starting from 64 workers on all charts.

go-memcached-bench and go-memcached binaries are available at downloads page.

Clone this wiki locally