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反饋。