Skip to content

Commit

Permalink
(chore) benchmark project is now maven based with proper logging
Browse files Browse the repository at this point in the history
  • Loading branch information
Michał Siatkowski committed Mar 27, 2020
1 parent 6615091 commit e3d71f5
Show file tree
Hide file tree
Showing 28 changed files with 871 additions and 809 deletions.
17 changes: 0 additions & 17 deletions benchmark/.classpath

This file was deleted.

3 changes: 3 additions & 0 deletions benchmark/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.idea
target/
logs/
17 changes: 0 additions & 17 deletions benchmark/.project

This file was deleted.

Binary file removed benchmark/lib/commons-logging-1.0.4.jar
Binary file not shown.
Binary file removed benchmark/lib/jcommon-1.0.16.jar
Binary file not shown.
Binary file removed benchmark/lib/jfreechart-1.0.13.jar
Binary file not shown.
Binary file removed benchmark/lib/junit.jar
Binary file not shown.
Binary file removed benchmark/lib/log4j-1.2.15.jar
Binary file not shown.
Binary file removed benchmark/lib/slf4j-api-1.5.6.jar
Binary file not shown.
Binary file removed benchmark/lib/slf4j-log4j12-1.5.6.jar
Binary file not shown.
Binary file removed benchmark/lib/spy-2.4.jar
Binary file not shown.
65 changes: 65 additions & 0 deletions benchmark/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.googlecode.xmemcached</groupId>
<artifactId>xmemcached-benchmarks</artifactId>
<version>2.4.7-SNAPSHOT</version>

<url>https://github.com/killme2008/xmemcached</url>


<dependencies>
<dependency>
<groupId>org.jfree</groupId>
<artifactId>jfreechart</artifactId>
<version>1.0.17</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.7</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.30</version>
</dependency>

<dependency>
<groupId>custom</groupId>
<artifactId>xmemcached</artifactId>
<version>1.2.6.1</version>
<scope>system</scope>
<systemPath>${basedir}/lib/xmemcached-1.2.6.1.jar</systemPath>
</dependency>
<dependency>
<groupId>custom</groupId>
<artifactId>spymemcached</artifactId>
<version>2.5</version>
<scope>system</scope>
<systemPath>${basedir}/lib/memcached-2.5.jar</systemPath>
</dependency>
<dependency>
<groupId>custom</groupId>
<artifactId>java-memcached</artifactId>
<version>2.5.1</version>
<scope>system</scope>
<systemPath>${basedir}/lib/java_memcached-release_2.5.1.jar</systemPath>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
6 changes: 0 additions & 6 deletions benchmark/src/log4j.properties

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,73 +1,76 @@
package net.rubyeye.memcached;

import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.atomic.AtomicLong;

import net.rubyeye.memcached.benchmark.Constants;
import net.rubyeye.memcached.benchmark.StringGenerator;

public abstract class BaseReadWriteThread extends Thread {

private static final Logger log = LoggerFactory.getLogger(BaseReadWriteThread.class);
protected int repeats;
protected CyclicBarrier barrier;
protected int offset;
protected int length;
protected AtomicLong miss;
protected AtomicLong fail;
protected AtomicLong hit;

public BaseReadWriteThread(int repeats, CyclicBarrier barrier, int offset,
int length, AtomicLong miss, AtomicLong fail, AtomicLong hit) {
super();
this.repeats = repeats;
this.barrier = barrier;
this.offset = offset;
this.length = length;
this.miss = miss;
this.fail = fail;
this.hit = hit;
}

public abstract boolean set(int i, String s) throws Exception;

public abstract String get(int n) throws Exception;

public void run() {

int writeTimes = (int) (this.repeats * Constants.WRITE_RATE);
try {
barrier.await();
int writeMax = offset + writeTimes;
for (int i = offset; i <= writeMax; i++) {
String s = StringGenerator.generate(i, length);
if (!set(i, s)) {
System.err.println("set error");
System.exit(1);
}
}
int countMax = (int) ((1 - Constants.WRITE_RATE) / Constants.WRITE_RATE);
for (int count = 0; count < countMax; count++) {
for (int i = offset; i <= writeMax; i++) {
String s = StringGenerator.generate(i, length);
String result = get(i);
if (result != null && !s.equals(result)) {
System.err.println("get error,expected " + s
+ ",actual " + result);
fail.incrementAndGet();
} else if (result == null) {
miss.incrementAndGet();
} else if (result != null && result.equals(s)) {
hit.incrementAndGet();
}
}
}

barrier.await();
} catch (Exception e) {
log.error(e.getMessage(), e);

}
}

}
package net.rubyeye.memcached;

import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.atomic.AtomicLong;

import net.rubyeye.memcached.benchmark.Constants;
import net.rubyeye.memcached.benchmark.StringGenerator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public abstract class BaseReadWriteThread extends Thread {

private final Logger log;
protected final int repeats;
protected final CyclicBarrier barrier;
protected final int offset;
protected final int length;
protected final AtomicLong miss;
protected final AtomicLong fail;
protected final AtomicLong hit;

public BaseReadWriteThread(int repeats, CyclicBarrier barrier, int offset,
int length, AtomicLong miss, AtomicLong fail, AtomicLong hit) {
super();
this.repeats = repeats;
this.barrier = barrier;
this.offset = offset;
this.length = length;
this.miss = miss;
this.fail = fail;
this.hit = hit;
this.log = LoggerFactory.getLogger(BaseReadWriteThread.class);
}

public abstract boolean set(int i, String s) throws Exception;

public abstract String get(int n) throws Exception;

public void run() {

int writeTimes = (int) (this.repeats * Constants.WRITE_RATE);
try {
barrier.await();
int writeMax = offset + writeTimes;
for (int i = offset; i <= writeMax; i++) {
String s = StringGenerator.generate(i, length);
if (!set(i, s)) {
log.error("set error");
System.exit(1);
}
}
int countMax = (int) ((1 - Constants.WRITE_RATE) / Constants.WRITE_RATE);
for (int count = 0; count < countMax; count++) {
for (int i = offset; i <= writeMax; i++) {
String s = StringGenerator.generate(i, length);
String result = get(i);
if (result != null && !s.equals(result)) {
log.error("get error,expected " + s
+ ",actual " + result);
fail.incrementAndGet();
} else if (result == null) {
miss.incrementAndGet();
} else if (result != null && result.equals(s)) {
hit.incrementAndGet();
}
}
}

barrier.await();
} catch (Exception e) {
log.error(e.getMessage(), e);

}
}

}
Original file line number Diff line number Diff line change
@@ -1,30 +1,43 @@
package net.rubyeye.memcached;

import java.text.DecimalFormat;
import java.util.concurrent.atomic.AtomicLong;

import net.rubyeye.memcached.benchmark.Constants;

public class BaseTest implements Constants {

public static void printResult(int length, int threads, int repeats,
AtomicLong miss, AtomicLong fail, AtomicLong hit, long duration,
long total) {
DecimalFormat df = new DecimalFormat("######0.00");
double hitRate = ((double) hit.get())
/ (hit.get() + miss.get() + fail.get());
System.out.println("threads=" + threads + ",repeats=" + repeats
+ ",valueLength=" + length + ",tps=" + total * 1000000000
/ duration + ",miss=" + miss.get() + ",fail=" + fail.get()
+ ",hit=" + hit.get() + ",all=" + total + ",hitRate="
+ df.format(hitRate));
}

protected static int getReapts(int i) {
// int t = (int) Math.log(THREADS[i]);
// int repeats = BASE_REPEATS * (t <= 0 ? 1 : t);
// return repeats;
return BASE_REPEATS;
}

}
package net.rubyeye.memcached;

import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.atomic.AtomicLong;

import net.rubyeye.memcached.benchmark.Constants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class BaseTest implements Constants {

// for logging purpose
static {
System.setProperty("log4j.configuration", "log4j-bench.properties");
SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy-hh-mm-ss");
System.setProperty("current.date.time", dateFormat.format(new Date()));
}

protected static Logger logger = LoggerFactory.getLogger("benchmark");

public static void printResult(int length, int threads, int repeats,
AtomicLong miss, AtomicLong fail, AtomicLong hit, long duration,
long total) {
DecimalFormat df = new DecimalFormat("######0.00");
double hitRate = ((double) hit.get())
/ (hit.get() + miss.get() + fail.get());
logger.info("threads=" + threads + ",repeats=" + repeats
+ ",valueLength=" + length + ",tps=" + total * 1000000000
/ duration + ",miss=" + miss.get() + ",fail=" + fail.get()
+ ",hit=" + hit.get() + ",all=" + total + ",hitRate="
+ df.format(hitRate));
}

protected static int getReapts(int i) {
// int t = (int) Math.log(THREADS[i]);
// int repeats = BASE_REPEATS * (t <= 0 ? 1 : t);
// return repeats;
return BASE_REPEATS;
}

}
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package net.rubyeye.memcached.benchmark;

public interface Constants {

final int[] THREADS = {
// 200,
1, 10, 50, 100, 300 };
final int[] BYTES = {
// 128,
64, 512, 1024, 4096, 16 * 1024, };
public static final double WRITE_RATE = 0.20;
final int BASE_REPEATS = 40000;
final long OP_TIMEOUT = 5000;

}
package net.rubyeye.memcached.benchmark;

public interface Constants {

final int[] THREADS = {
// 200,
1, 10, 50, 100, 300 };
final int[] BYTES = {
// 128,
64, 512, 1024, 4096, 16 * 1024, };
public static final double WRITE_RATE = 0.20;
final int BASE_REPEATS = 40000;
final long OP_TIMEOUT = 5000;

}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package net.rubyeye.memcached.benchmark;

public class StringGenerator {
public static final String generate(int n, int length) {
StringBuilder result = new StringBuilder(String.valueOf(n));
while (result.length() < length) {
result.append("0");
}
return result.toString();
}
}
package net.rubyeye.memcached.benchmark;

public class StringGenerator {
public static final String generate(int n, int length) {
StringBuilder result = new StringBuilder(String.valueOf(n));
while (result.length() < length) {
result.append("0");
}
return result.toString();
}
}
Loading

0 comments on commit e3d71f5

Please sign in to comment.