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,007 | Comments: 44,761

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.


No future posts left, oh my!


  1. Speaking (3):
    23 Sep 2015 - Build Stuff 2015 (Lithuania & Ukraine), Nov 18 - 24
  2. Production postmortem (11):
    22 Sep 2015 - The case of the Unicode Poo
  3. Technical observations from my wife (2):
    15 Sep 2015 - Disk speeds
  4. Find the bug (5):
    11 Sep 2015 - The concurrent memory buster
  5. Buffer allocation strategies (3):
    09 Sep 2015 - Bad usage patterns
View all series



Main feed Feed Stats
Comments feed   Comments Feed Stats