NMemcached: A WCF experiment
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
Haven't looked at the code, but out of curiosity: Are you using the binary or the text encoders?.
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.
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
I am using new NetTcpBinding(), whatever that means
Troy,
Haven't seen that, thanks.
Just tried this, and this and removing security dropped to 6454ms
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.
Also, disabling reliable sessions might help a bit as well, unless you explicitly need them...
After disabling reliable sesisons, I am down to ~6100ms
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