-
Notifications
You must be signed in to change notification settings - Fork 282
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(chore) benchmark project is now maven based with proper logging
- Loading branch information
Michał Siatkowski
committed
Mar 27, 2020
1 parent
6615091
commit e3d71f5
Showing
28 changed files
with
871 additions
and
809 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.idea | ||
target/ | ||
logs/ |
This file was deleted.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file was deleted.
Oops, something went wrong.
149 changes: 76 additions & 73 deletions
149
...ubyeye/memcached/BaseReadWriteThread.java → ...ubyeye/memcached/BaseReadWriteThread.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
||
} | ||
} | ||
|
||
} |
73 changes: 43 additions & 30 deletions
73
...k/src/net/rubyeye/memcached/BaseTest.java → .../java/net/rubyeye/memcached/BaseTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
30 changes: 15 additions & 15 deletions
30
...ubyeye/memcached/benchmark/Constants.java → ...ubyeye/memcached/benchmark/Constants.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
} |
22 changes: 11 additions & 11 deletions
22
.../memcached/benchmark/StringGenerator.java → .../memcached/benchmark/StringGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
Oops, something went wrong.