fix benchmarking code following removal of unnecessary method on MemcachedCacheBroker

This commit is contained in:
xvrl 2012-12-06 16:07:29 -08:00
parent 9ef46f5e65
commit a0dbd233fb
1 changed files with 33 additions and 31 deletions

View File

@ -3,6 +3,13 @@ package com.metamx.druid.client.cache;
import com.google.caliper.Param; import com.google.caliper.Param;
import com.google.caliper.Runner; import com.google.caliper.Runner;
import com.google.caliper.SimpleBenchmark; import com.google.caliper.SimpleBenchmark;
import net.spy.memcached.AddrUtil;
import net.spy.memcached.ConnectionFactoryBuilder;
import net.spy.memcached.DefaultHashAlgorithm;
import net.spy.memcached.FailureMode;
import net.spy.memcached.MemcachedClient;
import net.spy.memcached.MemcachedClientIF;
import net.spy.memcached.transcoders.SerializingTranscoder;
import java.util.Random; import java.util.Random;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -12,6 +19,8 @@ public class MemcachedCacheBrokerBenchmark extends SimpleBenchmark
private static final String BASE_KEY = "test_2012-11-26T00:00:00.000Z_2012-11-27T00:00:00.000Z_2012-11-27T04:11:25.979Z_"; private static final String BASE_KEY = "test_2012-11-26T00:00:00.000Z_2012-11-27T00:00:00.000Z_2012-11-27T04:11:25.979Z_";
private MemcachedCacheBroker broker; private MemcachedCacheBroker broker;
private MemcachedClientIF client;
private Cache cache; private Cache cache;
private static byte[] randBytes; private static byte[] randBytes;
@ -22,36 +31,28 @@ public class MemcachedCacheBrokerBenchmark extends SimpleBenchmark
@Override @Override
protected void setUp() throws Exception protected void setUp() throws Exception
{ {
broker = MemcachedCacheBroker.create( SerializingTranscoder transcoder = new SerializingTranscoder(
new MemcachedCacheBrokerConfig() 50 * 1024 * 1024 // 50 MB
{ );
@Override // disable compression
public int getExpiration() transcoder.setCompressionThreshold(Integer.MAX_VALUE);
{
// 1 year
return 3600 * 24 * 365;
}
@Override client = new MemcachedClient(
public int getTimeout() new ConnectionFactoryBuilder().setProtocol(ConnectionFactoryBuilder.Protocol.BINARY)
{ .setHashAlg(DefaultHashAlgorithm.FNV1A_64_HASH)
// 500 milliseconds .setLocatorType(ConnectionFactoryBuilder.Locator.CONSISTENT)
return 500; .setDaemon(true)
} .setFailureMode(FailureMode.Retry)
.setTranscoder(transcoder)
.setShouldOptimize(true)
.build(),
AddrUtil.getAddresses("localhost:11211")
);
@Override broker = new MemcachedCacheBroker(
public String getHosts() client,
{ 500, // 500 milliseconds
return "localhost:11211"; 3600 * 24 * 365 // 1 year
}
@Override
public int getMaxObjectSize()
{
// 50 MB
return 50 * 1024 * 1024;
}
}
); );
cache = broker.provideCache("default"); cache = broker.provideCache("default");
@ -64,8 +65,8 @@ public class MemcachedCacheBrokerBenchmark extends SimpleBenchmark
@Override @Override
protected void tearDown() throws Exception protected void tearDown() throws Exception
{ {
broker.getClient().flush(); client.flush();
broker.getClient().shutdown(); client.shutdown();
} }
public void timePutObjects(int reps) { public void timePutObjects(int reps) {
@ -74,7 +75,8 @@ public class MemcachedCacheBrokerBenchmark extends SimpleBenchmark
String key = BASE_KEY + i; String key = BASE_KEY + i;
cache.put(key.getBytes(), randBytes); cache.put(key.getBytes(), randBytes);
} }
broker.getClient().waitForQueues(1, TimeUnit.HOURS); // make sure the write queue is empty
client.waitForQueues(1, TimeUnit.HOURS);
} }
} }