提交 2145f78f 编写于 作者: X xvrl

add memcached cache benchmarking code

上级 1083ed9c
......@@ -187,6 +187,11 @@
<artifactId>easymock</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.caliper</groupId>
<artifactId>caliper</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
......
package com.metamx.druid.client.cache;
import com.google.caliper.Param;
import com.google.caliper.Runner;
import com.google.caliper.SimpleBenchmark;
import java.util.Random;
import java.util.concurrent.TimeUnit;
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 MemcachedCacheBroker broker;
private Cache cache;
private static byte[] randBytes;
// object size in kB
@Param({"1", "5", "10", "40"}) int objectSize;
@Param({"100", "1000"}) int objectCount;
@Override
protected void setUp() throws Exception
{
broker = MemcachedCacheBroker.create(
new MemcachedCacheBrokerConfig()
{
@Override
public int getExpiration()
{
// 1 year
return 3600 * 24 * 365;
}
@Override
public int getTimeout()
{
// 500 milliseconds
return 500;
}
@Override
public String getHosts()
{
return "localhost:11211";
}
@Override
public int getMaxObjectSize()
{
// 50 MB
return 50 * 1024 * 1024;
}
}
);
cache = broker.provideCache("default");
randBytes = new byte[objectSize * 1024];
new Random(0).nextBytes(randBytes);
}
@Override
protected void tearDown() throws Exception
{
broker.getClient().flush();
broker.getClient().shutdown();
}
public void timePutObjects(int reps) {
for(int i = 0; i < reps; ++i) {
for(int k = 0; k < objectCount; ++k) {
String key = BASE_KEY + i;
cache.put(key.getBytes(), randBytes);
}
broker.getClient().waitForQueues(1, TimeUnit.HOURS);
}
}
public byte[] timeGetObject(int reps) {
byte[] bytes = null;
for (int i = 0; i < reps; i++) {
for(int k = 0; k < objectCount; ++k) {
String key = BASE_KEY + i;
bytes = cache.get(key.getBytes());
}
}
return bytes;
}
public static void main(String[] args) throws Exception {
Runner.main(MemcachedCacheBrokerBenchmark.class, args);
}
}
......@@ -279,6 +279,13 @@
<version>4.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.caliper</groupId>
<artifactId>caliper</artifactId>
<version>0.5-rc1</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册