好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

Memcached客户端评测报告20100125

Memcached客户端评测报告20100125

缘起:

原先用的 https://sourceforge.net/projects/memcacheddotnet/ 一个客户端,在使用Increment这个方法时出现一些莫名的问题,于是请命对这个块做一个评测。

定位:

首先用熟悉的python来定位排除一下,是不是别的问题引起的,我找了良久 http://www.tummy.com/Community/software/python-memcached/ ,用的是这个主流的库

主要的当心是在windows下能不能好使,事实上我的担心是多余的,

#! /usr/bin/env python

#coding=utf-8

#brief memcached increment test

import memcache

mc = memcache . Client ([ '192.168.0.74:11211' ], debug = 0 )

#mc.set("key","2")

#mc.incr("key")

#print mc.get("key")

##print mc.get("key")

#import sys

#sys.exit()

 

 

mc . set ( "key" , "0" )

#mc.incr("key")

#print type(mc.get("key"))

 

for i in xrange ( 1 , 10000 ):

mc . incr ( "key" )

if mc . get ( "key" )<> str ( i ):

print u"错误出现在%d" . encode ( "gbk" , 'ignore' )% i

break

print "done!"

 

之后

我给 https://sourceforge.net/projects/memcacheddotnet/ 的类库做了一个简单的测试,来定位它的increment是否真有问题,结果表明真的是有的

   using    System  ;  
				  

   using    System  .  Collections  .  Generic  ;  
				  

   using    System  .  Text  ;  
				  

   using    Memcached  .  ClientLibrary  ;  
				  

 

   namespace    IsolateMemcachedTest
  

  {  
				  

  
				   class    Program
  

  
				  {  
				  

  
				   private   
				   static    MemcachedClient mc   =  
				   new    MemcachedClient  ()  ;  
				  

  
				   static   
				   void    Main  (   string   []   args  )  
				  

  
				  {  
				  

              mc  .  EnableCompression   =  
				   false   ;  
				  

              SockIOPool pool   =   SockIOPool  .  GetInstance  ()  ;  
				  

              pool  .  SetServers  (   new   
				   string   []  {  "  192.168.0.74:11211  "  }  )  ;  
				  

              pool  .  InitConnections   =  
				  3  ;  //初始化链接数  
				  

              pool  .  MinConnections   =  
				  3  ;  //最少链接数  
				  

              pool  .  MaxConnections   =  
				  3  ;  //最大连接数  
				  

              pool  .  SocketConnectTimeout   =  
				  5000  ;  //Socket链接超时时间  
				  

              pool  .  SocketTimeout   =  
				  5000  ;  // Socket超时时间  
				  

              pool  .  MaintenanceSleep   =  
				  5  ;  //维护线程休息时间  
				  

              pool  .  Failover   =  
				   false   ;  
				  //失效转移(一种备份操作模式)  
				  

  
				  //pool.Nagle = Nagle;// ��� 否用nagle算法启动socket  
				  

              pool  .  HashingAlgorithm   =   HashingAlgorithm  .  NewCompatibleHash  ;  
				  

              pool  .  Initialize  ()  ;  
				  

 

              mc  .  Set  (  "  haha  "  ,  
				  "  1  "  )  ;  
				  

              Console  .  WriteLine  (  mc  .  Get  (  "  haha  "  ).  ToString  ()  
				  ==  
				  "  1  "  )  ;  
				  

              Console  .  WriteLine  (  mc  .  Increment  (  "  haha  "  ))  ;  
				  

              Console  .  WriteLine  (  mc  .  Get  (  "  haha  "  ))  ;  
				  

 

最后,我们要找一个替补的方案,它最后更新在2009-2

http://code.google.com/p/beitmemcached/

也写了一段测试代码

   using    System  ;  
				  

   using    System  .  Collections  .  Generic  ;  
				  

   using    System  .  Text  ;  
				  

   using    BeIT  .  MemCached  ;  
				  

 

   namespace    IsolateMemcachedTest
  

  {  
				  

  
				   class    Program2
  

  
				  {  
				  

  
				   static   
				   void    Main  (   string   []   args  )  
				  

  
				  {  
				  

              MemcachedClient  .  Setup  (  "  MyCache  "  ,  
				   new   
				   string   []  
				  {  
				  "  192.168.0.74:11211  "  
				  }  )  ;  
				  

              MemcachedClient cache   =   MemcachedClient  .  GetInstance  (  "  MyCache  "  )  ;  
				  

              cache  .  SendReceiveTimeout   =  
				  5000  ;  
				  

              cache  .  MinPoolSize   =  
				  1  ;  
				  

              cache  .  MaxPoolSize   =  
				  5  ;  
				  

 

              cache  .  Set  (  "  hh  "  ,  
				  "  0  "  )  ;  
				  

  
				  //Console.WriteLine(cache.Increment("hh", 1));  
				  

  
				  //Console.WriteLine(cache.Get("hh"));  
				  

 

  
				   for   
				  (   int    i   =  
				  1  ;   i   <=  
				  10000  ;   i  ++)  
				  

  
				  {  
				  

                  cache  .  Increment  (  "  hh  "  ,  
				  1  )  ;  
				  

  
				   if   
				  (  Convert  .  ToString  (  cache  .  Get  (  "  hh  "  ))  
				  !=   i  .  ToString  ())  
				  

  
				  {  
				  

                      Console  .  WriteLine  (  "  在{0}处出现错误  "  ,   i  )  ;  
				  

  
				   break   ;  
				  

  
				  }  
				  

 

  
				  }  
				  

              Console  .  WriteLine  (  "  done!  "  )  ;  
				  

              Console  .  WriteLine  (  cache  .  Get  (  "  hh  "  ))  ;  
				  

  
				  }  
				  

  
				  }  
				  

  }
  

  另外还有一个:  
				  

http://www.codeplex.com/EnyimMemcached/ ,它最后更新在2008-11

虽然它更新的速度不行,但是它的文字是这么写的,所以还是有些吸引力

Main features

written for .NET, not ported from a different architecture ( so uses the framework's features better ) configuration is stored in app/web.config ( sample configuration file is included ) or can be done from code uses minimal locking to increase the throughput supports consistent hashing for keys: a specific item goes to a specific server every time. ( based on libketama, http://lists.danga.com/pipermail/memcached/2007-April/003834.html ) operations are factored into separate classes, so they are more separated from the main client class, easier manageability and thread safety primitive types ( currently some numeric types, bool, DateTime, byte[] and strings, but can be extended ) are stored in an optimized form; only Objects are serialized excessive extensibility: define your own configuration, serialization format or "consistent hashing" algorithm (see Cannot resolve release macro, invalid id.) based on our non-disclosed specially handcrafted in-house performance test we're the fastest C# client ever, using negative amount of system resources, be it memory or CPU time we follow memcached's protocol specification as strictly as no one else: even the memcached guys ask us if they don't understand something

不过看了它的工程代码还是比较全面的,但是太复杂,不符合我的开发哲学

所以它就被我排除了,所以我们还是聚焦到上面googlecode上的那个BiTMemcached的项目上了。

BeITMemcached项目评测

它的代码很是简洁,不过相比而言就没有什么单元测试什么的了,不过也不错

 

Reference:

http://www.cnblogs.com/sig556/archive/2009/12/30/1635722.html

今天就到这里

2010-02-04
另诉一下心中的苦闷,在测memcached的过期功能,结果linux server的日期时间不对,郁闷了我半天,小记于此以慰后来人

另外,找了一个同步windows server 2003下时间的工具

automachron

时间同步服务配置

查看更多关于Memcached客户端评测报告20100125的详细内容...

  阅读:37次