Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update benchmark project #112

Merged
merged 6 commits into from
Mar 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ services:
- memcached
script:
- mvn test integration-test
- cd ./benchmark && mvn compile
after_script:
- '[ "${TRAVIS_PULL_REQUEST}" = "false" ] && travis_wait 300 mvn site -Ppublish-site-github || false'
env:
Expand Down
17 changes: 0 additions & 17 deletions benchmark/.classpath

This file was deleted.

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

This file was deleted.

17 changes: 17 additions & 0 deletions benchmark/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Benchmarks

## How to run

Just run `./run.sh` in this folder.
It will take care of everything.

## Add new test

1. Create a separate Maven module with your library.
1. I guess it is best to copy-paste an existing case.
2. Modify `logging.properties` to log to new file!

2. Add your execution to `./run.sh` for future comparisons.

3. Add your result file in `charts.js` so the HTML report
could pick up and render your results properly.
21 changes: 21 additions & 0 deletions benchmark/benchmark-base/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<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>

<parent>
<artifactId>benchmarks</artifactId>
<groupId>com.googlecode.xmemcached</groupId>
<version>${project-version}</version>
</parent>
<artifactId>benchmark-base</artifactId>

<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.30</version>
</dependency>
</dependencies>


</project>
Original file line number Diff line number Diff line change
@@ -1,73 +1,74 @@
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 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,37 @@
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 org.slf4j.Logger;
import org.slf4j.LoggerFactory;

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

public class BaseTest implements Constants {

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

public static void printHeader() {
logger.info("threads,repeats,valueLength,tps,miss,fail,hit,all,hitRate");
}

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 + "," + repeats
+ "," + length + "," + total * 1000000000
/ duration + "," + miss.get() + "," + fail.get()
+ "," + hit.get() + "," + total + ","
+ 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;

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;

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