Ayende @ Rahien

My name is Oren Eini
Founder of Hibernating Rhinos LTD and RavenDB.
You can reach me by phone or email:


+972 52-548-6969

, @ Q c

Posts: 6,123 | Comments: 45,470

filter by tags archive

NMemcached: A WCF experiment

time to read 1 min | 197 words


While doing a code review of NMemcached it started to bother me just how much of the application was infrastructure and argument parsing code. It shouldn't be this way. So I decided to port the whole thing to WCF and see how it works.

Porting it wasn't hard, and significantly reduced the amount of code in the application. After updating all the tests and verifying that I fixed all the things I broke, I built an appropriate memcache client and started perf testing again.

As a reminder, native Memcached server managed to field 10,000 reads and writes in just 1709.6 ms. My own implementation got to the same point in 3144.5 ms.

The WCF implementation (note, the implementation and the benchmark are different, because of the different approaches, but the test is the same)...

Right now it is using net.tcp binding and it is at a lousy 7853.3 ms.

The code is available here, and I would appreciate any comments. I didn't even try to optimize anything with WCF, just set it to net.tcp and let it handle everything else.


Tomas Restrepo

Haven't looked at the code, but out of curiosity: Are you using the binary or the text encoders?.

Troy Gould

You've probably already seen this, but sending it just in case.


I know that in .NET 3.0, calling client.Open() explicitly before making the service call was another way of speeding up performance. I don't know if this makes a difference in .NET 3.5.

Christian Weyer

Just some quick test on my machine - and I did not see your original code and whether you have security in there or not.



created clients, starting to connect

read 10000

wrote 10000

took 4752 total 10005 reads and 10002 writes using 20 connections

netTcpBinding - w/o security


created clients, starting to connect

wrote 10000

read 10000

took 3816 total 10001 reads and 10003 writes using 20 connections

Ayende Rahien

I am using new NetTcpBinding(), whatever that means

Ayende Rahien


Haven't seen that, thanks.

Just tried this, and this and removing security dropped to 6454ms

Tomas Restrepo

In that case you're probably already using the binary encoders. I'm not sure exactly how your nmemcached architecture works, but it;s possible you might get away with some interesting things using the peer channels instead.

Tomas Restrepo

Also, disabling reliable sessions might help a bit as well, unless you explicitly need them...

Ayende Rahien

After disabling reliable sesisons, I am down to ~6100ms

Troy Gould

This is becoming an experiment on tuning WCF services. :)


Try rebooting your machine and running the test, or force paging your memory to disk, bet the first call to the service is "significantly" slower... According to Microsoft this is expected behavior. ;)

Comment preview

Comments have been closed on this topic.


  1. RavenDB 3.5 whirl wind tour: You want all the data, you can’t handle all the data - 3 days from now
  2. The design of RavenDB 4.0: Making Lucene reliable - 4 days from now
  3. RavenDB 3.5 whirl wind tour: I’ll find who is taking my I/O bandwidth and they SHALL pay - 5 days from now
  4. The design of RavenDB 4.0: Physically segregating collections - 6 days from now
  5. RavenDB 3.5 Whirlwind tour: I need to be free to explore my data - 7 days from now

And 13 more posts are pending...

There are posts all the way to May 30, 2016


  1. RavenDB 3.5 whirl wind tour (14):
    29 Apr 2016 - A large cluster goes into a bar and order N^2 drinks
  2. The design of RavenDB 4.0 (12):
    28 Apr 2016 - The implications of the blittable format
  3. Tasks for the new comer (2):
    15 Apr 2016 - Quartz.NET with RavenDB
  4. Code through the looking glass (5):
    18 Mar 2016 - And a linear search to rule them
  5. Find the bug (8):
    29 Feb 2016 - When you can't rely on your own identity
View all series



Main feed Feed Stats
Comments feed   Comments Feed Stats