add memcached cache benchmarking code

This commit is contained in:
xvrl 2012-12-04 16:29:51 -08:00
parent 1083ed9c11
commit 2145f78f78
3 changed files with 107 additions and 0 deletions

View File

@ -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>

View File

@ -0,0 +1,95 @@
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);
}
}

View File

@ -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>