Friday, October 22, 2010

Memcached in Java

Over the last few weeks I was just playing around with some non blocking java code. I had read that jmemcache which works using Netty runs at about 50% the speed of memcached. So I wrote a simple cache implementation and picked up some code from the jmemcache project and I had my own memcached in java. Works at about 80%-90% of the speed of memcached, which I believe is very good given the quadruple data copy involved ... java bytes arrays to java byte buffer to native byte buffer to the kernel.

Benefits:

  • Works on all platforms (32 bit, 64 bit)
  • Works on all OSes which have java.. windows, linux, solaris, hp-unix, mac, etc
  • No slab reallocation issues as we don't have any slabs
  • Multi threaded
  • Pure java. No third party dependency.
Bads:
  • 10%-20% performance drop
  • Cpu utilization is higher than memcached
  • Objects are not tightly packed, so uses a bit more memory

Testing was done using the xmemcached client and their benchmark code.

PS: Java gathering write still has memory leak on 64 bit linux.

No comments:

Post a Comment