我在多线程java SE应用程序中使用couchbase和xmemcached客户端。我一直在观察沙发基地无法保存最后几个键,而传统的memcached正在极好地设置所有键。我在两种情况下都使用exaclty相同的xmemcachedclient配置。
弹簧配置
<bean name="memcachedClient" class="net.rubyeye.xmemcached.utils.XMemcachedClientFactoryBean" destroy-method="shutdown">
<property name="configuration">
<bean class="com.google.code.yanf4j.config.Configuration">
<property name="handleReadWriteConcurrently" value="true" />
</bean>
</property>
<property name="servers">
<value>127.0.0.1:11211</value>
</property>
<!-- server's weights -->
<property name="weights">
<list>
<value>2</value>
</list>
</property>
<!-- nio connection pool size -->
<!-- <property name="connectionPoolSize" value="4"></property> -->
<!-- Use binary protocol,default is TextCommandFactory -->
<property name="commandFactory">
<bean class="net.rubyeye.xmemcached.command.BinaryCommandFactory" />
</property>
<!-- Distributed strategy -->
<property name="sessionLocator">
<bean class="net.rubyeye.xmemcached.impl.KetamaMemcachedSessionLocator" />
</property>
<!-- Serializing transcoder -->
<property name="transcoder">
<bean class="net.rubyeye.xmemcached.transcoders.SerializingTranscoder" />
</property>
<!-- ByteBuffer allocator -->
<property name="bufferAllocator">
<bean class="net.rubyeye.xmemcached.buffer.SimpleBufferAllocator" />
</property>
</bean>
下面是我检查缺失密钥的测试代码
@Test
public void test100000HitMiss()
{
ArrayList<Integer> hits = new ArrayList<Integer>();
ArrayList<Integer> misses = new ArrayList<Integer>();
for(Integer i=0; i < 100000; i++)
{
try
{
Object val = memcachedClient.get("2/C/TALAL" + i.toString());
if(null == val)
misses.add(i);
else
hits.add(i);
}
catch (Exception ex)
{
logger.error(ex);
}
}
logger.info("Hits: " + hits.size() + " - Misses: " + misses.size());
}
每次运行此测试时,我都会在未命中数组中获得3或4个键