Ayende @ Rahien

Refunds available at head office

NMemcached: A WCF experiment

image

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.

Comments

Tomas Restrepo
06/25/2008 06:50 PM by
Tomas Restrepo

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

Troy Gould
06/25/2008 07:19 PM by
Troy Gould

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

http://blogs.msdn.com/wenlong/archive/2007/10/27/performance-improvement-of-wcf-client-proxy-creation-and-best-practices.aspx

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
06/25/2008 08:09 PM by
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.

netTcpBinding

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

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
06/25/2008 08:16 PM by
Ayende Rahien

I am using new NetTcpBinding(), whatever that means

Ayende Rahien
06/25/2008 08:26 PM by
Ayende Rahien

Troy,

Haven't seen that, thanks.

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

Tomas Restrepo
06/25/2008 08:28 PM by
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
06/25/2008 08:31 PM by
Tomas Restrepo

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

Ayende Rahien
06/25/2008 08:46 PM by
Ayende Rahien

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

Troy Gould
06/25/2008 09:02 PM by
Troy Gould

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

magell
06/25/2008 10:32 PM by
magell

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. ;)

Comments have been closed on this topic.