xmemcached发布1.1.2 (权重、noreply、spring集成)

    xiaoxiao2024-05-30  96

    XMemcached发布1.1.2版本,这一版本仍然是1.1.0版本以来的改进版本,主要的改进如下: 1.支持设置memcached 节点权重,权重高的负载相应比较大。 2.为部分协议添加 noreply选项,memcached 1.2.5引入了noreply支持,部分文本协议(如存储,删除,incr/decr等)允许附加设置一个noreply,表示客户端不要求memcached应答。这一特性利于批量处理。 3.支持与 spring框架的集成。 4.添加 verbosity协议,这个协议用于让客户端设置memcached的日志输出级别。 5.一些细节改进。XMemcached从0.5开始就有重连机制,在连接意外断开的情况下会不断地自动重连,不过间隔是10秒,现在改成将间隔缩小为0秒以便客户端能及时连接。改进了JMX支持,可以通过JMX查看节点权重和动态设置节点权重。 6.BUG修复,包括:Issue 35、Issue 36、Issue 37、Issue 38等,具体请看 这里 7.去除了对spy-2.4.jar依赖,现在序列化部分已经不再需要spymemcached的这个jar包。 项目主页: http://code.google.com/p/xmemcached/ 下载地址: http://code.google.com/p/xmemcached/downloads/list wiki地址: http://code.google.com/p/xmemcached/w/list     下面是关于特性的详细说明,首先是权重的使用,看例子:     MemcachedClientBuilder builder  =   new XMemcachedClientBuilder(AddrUtil.getAddresses( " localhost:12000 localhost:12001 " ), new   int []{ 1 , 3 });     MemcachedClient memcachedClient = builder.build();         现在的 XMemcachedClientBuilder允许传入了两个参数,一个是InetSocketAddress组成的列表,一个是权重的数组,权重数组的元素与列表中的地址一一对应,例如这里就是将"localhost:12000"节点的权重设置为1,而将"localhost:12001"的权重设置为3。同样在XMemcachedClientMBean中添加了两个新的方法:      public   void  addOneServerWithWeight(String server,  int  weight)              throws  IOException;      /**      * Set a memcached server's weight      *       *  @param  server      *  @param  weight       */      public   void  setServerWeight(String server,  int  weight);     用于动态添加和修改节点的权重。     其次,为了支持 noreply选项,MemcachedClient接口引入了系列xxxWithNoReply方法,例如 public   abstract   void  setWithNoReply( final  String key,  final   int  exp,              final  Object value)  throws  InterruptedException, MemcachedException;      public   abstract   < T >   void  setWithNoReply( final  String key,  final   int  exp,              final  T value,  final  Transcoder < T >  transcoder)              throws  InterruptedException, MemcachedException; public   abstract   void  addWithNoReply( final  String key,  final   int  exp,              final  Object value)  throws  InterruptedException, MemcachedException; public   abstract   void  replaceWithNoReply( final  String key,  final   int  exp,              final  Object value)  throws  InterruptedException, MemcachedException; public   void  deleteWithNoReply( final  String key)              throws  InterruptedException, MemcachedException;    完整的列表请看changelog.txt, noreply系列方法非常适合于批量处理,比之需要等待memcached应答的效率上提升很多。    第三,与spring的集成,通过XMemcachedClientFactoryBean可以很方便地与spring框架集成,最简单的配置如下:    < bean  name ="memcachedClient"         class ="net.rubyeye.xmemcached.utils.XMemcachedClientFactoryBean" >          < property  name ="servers" >              < value > localhost:12000 localhost:12001 </ value >          </ property >      </ bean >       只要设置servers属性,那么就可以在任何需要的地方引用memcachedClient这个Bean.更完整的配置参考 wiki    第四,引入了对verbosity协议的支持,通过两个新方法:      public   void  setLoggingLevelVerbosity(InetSocketAddress address,  int  level)              throws  TimeoutException, InterruptedException, MemcachedException;      public   void  setLoggingLevelVerbosityWithNoReply(InetSocketAddress address,              int  level)  throws  InterruptedException, MemcachedException;

           其中的level就是日志级别。请注意你的memcached版本是否支持这一协议。     1.1.2是一个承前启后的版本,按俺的计划应该还有个1.1.3(专注性能改进和优化),之后才是实现了二进制协议的1.2.0。俺非常希望能有任何人给出任何建议和bug反馈。

    文章转自庄周梦蝶  ,原文发布时间2009-06-21

    相关资源:敏捷开发V1.0.pptx
    最新回复(0)