Skip to content

Commit

Permalink
Merge pull request #19 from project-tsurugi/move-debug-and-kvs
Browse files Browse the repository at this point in the history
Move debug and kvs
  • Loading branch information
kookubo authored Nov 8, 2023
2 parents 1b12b1a + 834d91c commit 7f13da8
Show file tree
Hide file tree
Showing 39 changed files with 4,170 additions and 0 deletions.
21 changes: 21 additions & 0 deletions modules/debug/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
plugins {
id 'tsubakuro-examples.app-conventions'
}

dependencies {
implementation "com.tsurugidb.tsubakuro:tsubakuro-debug:${tsubakuroVersion}"
}

tasks.register('runDebugClientExample', JavaExec) {
classpath = sourceSets.main.runtimeClasspath
mainClass = 'com.tsurugidb.tsubakuro.debug.example.DebugClientExample'
args = ['<<<Tsubakuro DebugClient Test Message>>>']

systemProperty 'com.tsurugidb.tsubakuro.jniverify', 'false'
systemProperty 'tsurugi.dbname', findProperty('tsurugi.dbname') ?: 'ipc:tsurugi'

systemProperty 'org.slf4j.simpleLogger.defaultLogLevel', findProperty('loglevel') ?: 'info'
systemProperty 'org.slf4j.simpleLogger.showThreadName', 'false'
systemProperty 'org.slf4j.simpleLogger.showShortLogName', 'true'
systemProperty 'org.slf4j.simpleLogger.levelInBrackets', 'true'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.tsurugidb.tsubakuro.debug.example;

import java.net.URI;

import com.tsurugidb.tsubakuro.channel.common.connection.NullCredential;
import com.tsurugidb.tsubakuro.common.SessionBuilder;
import com.tsurugidb.tsubakuro.debug.DebugClient;
import com.tsurugidb.tsubakuro.debug.LogLevel;

/**
* Example program to test DebugClient
*/
public class DebugClientExample {

private final URI endpoint;
private final String message;

DebugClientExample(String[] args) {
this.endpoint = URI.create(System.getProperty("tsurugi.dbname", "ipc:tsurugi"));
this.message = args[0];
}

private void output() throws Exception {
try (var session = SessionBuilder.connect(endpoint).withCredential(NullCredential.INSTANCE).create();
var debug = DebugClient.attach(session)) {
debug.logging(message);
debug.logging(LogLevel.INFO, message);
debug.logging(LogLevel.WARN, message);
debug.logging(LogLevel.ERROR, message);
}
}

/**
* @param args command arguments
* args[0] message to be shown in server log.
* The message will be shown 4 times at default log level(info), info, warn, and error.
* @throws Exception some exceptional situation occurred
*/
public static void main(String[] args) throws Exception {
if (args.length == 0) {
System.err.println("Usage: java [-Dtsurugi.dbname=name] DebugClientExample [message]");
System.err.println("\tex\tjava DebugClientExample hello");
System.err.println("\tex\tjava -Dtsurugi.dbname=ipc:tsurugi DebugClientExample hello");
return;
}
DebugClientExample app = new DebugClientExample(args);
app.output();
}

}
112 changes: 112 additions & 0 deletions modules/kvs/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
plugins {
id 'tsubakuro-examples.app-conventions'
}

dependencies {
implementation "com.tsurugidb.tsubakuro:tsubakuro-kvs:${tsubakuroVersion}"

// for src/inttest/java
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.2'
}

sourceSets {
main {
java {
srcDir "src/bench/java"
}
}
kvsIntegrationTest {
java {
compileClasspath += main.output + test.output
runtimeClasspath += main.output + test.output
srcDir "src/inttest/java"
}
resources.srcDir file('src/inttest/resources')
}
}

configurations {
kvsIntegrationTestImplementation.extendsFrom testImplementation
kvsIntegrationTestRuntime.extendsFrom testRuntime
}

// "./gradlew kvsIntegrationTest" or "./gradlew kvsIntegrationTest --info"
task kvsIntegrationTest(type: Test) {
systemProperty 'tsurugi.kvstest.endpoint', 'ipc:tsurugi'
useJUnitPlatform()
testClassesDirs = sourceSets.kvsIntegrationTest.output.classesDirs
classpath = sourceSets.kvsIntegrationTest.runtimeClasspath
outputs.upToDateWhen { false }
}

tasks.register('runSingleEmptyMessageBench', JavaExec) {
classpath = sourceSets.main.runtimeClasspath
mainClass = 'com.tsurugidb.tsubakuro.kvs.bench.EmptyMessageBench'
jvmArgs = ['--add-opens=java.base/java.nio=ALL-UNNAMED', '-Xmx1024M']
args = ['ipc:tsurugi', '1', '10', '30']

systemProperty 'com.tsurugidb.tsubakuro.jniverify', 'false'
systemProperty 'tsurugi.dbname', findProperty('tsurugi.dbname') ?: 'ipc:tsurugi'

systemProperty 'org.slf4j.simpleLogger.defaultLogLevel', findProperty('loglevel') ?: 'info'
systemProperty 'org.slf4j.simpleLogger.showThreadName', 'false'
systemProperty 'org.slf4j.simpleLogger.showShortLogName', 'true'
systemProperty 'org.slf4j.simpleLogger.levelInBrackets', 'true'
}

tasks.register('runMultiEmptyMessageBench', JavaExec) {
classpath = sourceSets.main.runtimeClasspath
mainClass = 'com.tsurugidb.tsubakuro.kvs.bench.EmptyMessageBench'
jvmArgs = ['--add-opens=java.base/java.nio=ALL-UNNAMED', '-Xmx1024M']
args = ['ipc:tsurugi', '1,2,4,8', '10', '30']

systemProperty 'com.tsurugidb.tsubakuro.jniverify', 'false'

systemProperty 'org.slf4j.simpleLogger.defaultLogLevel', findProperty('loglevel') ?: 'info'
systemProperty 'org.slf4j.simpleLogger.showThreadName', 'false'
systemProperty 'org.slf4j.simpleLogger.showShortLogName', 'true'
systemProperty 'org.slf4j.simpleLogger.levelInBrackets', 'true'
}

tasks.register('runYCSBlikeBenchCreateDB', JavaExec) {
classpath = sourceSets.main.runtimeClasspath
mainClass = 'com.tsurugidb.tsubakuro.kvs.ycsb.YCSBlikeBenchmark'
jvmArgs = ['--add-opens=java.base/java.nio=ALL-UNNAMED', '-Xmx1024M']
args = ['ipc:tsurugi', '8', 'createDB']

systemProperty 'com.tsurugidb.tsubakuro.jniverify', 'false'

systemProperty 'org.slf4j.simpleLogger.defaultLogLevel', findProperty('loglevel') ?: 'info'
systemProperty 'org.slf4j.simpleLogger.showThreadName', 'false'
systemProperty 'org.slf4j.simpleLogger.showShortLogName', 'true'
systemProperty 'org.slf4j.simpleLogger.levelInBrackets', 'true'
}

tasks.register('runYCSBlikeBench', JavaExec) {
classpath = sourceSets.main.runtimeClasspath
mainClass = 'com.tsurugidb.tsubakuro.kvs.ycsb.YCSBlikeBenchmark'
jvmArgs = ['--add-opens=java.base/java.nio=ALL-UNNAMED', '-Xmx1024M']
args = ['ipc:tsurugi', '1,2,4,8', '50', '10', '30']

systemProperty 'com.tsurugidb.tsubakuro.jniverify', 'false'

systemProperty 'org.slf4j.simpleLogger.defaultLogLevel', findProperty('loglevel') ?: 'info'
systemProperty 'org.slf4j.simpleLogger.showThreadName', 'false'
systemProperty 'org.slf4j.simpleLogger.showShortLogName', 'true'
systemProperty 'org.slf4j.simpleLogger.levelInBrackets', 'true'
}

tasks.register('runYCSBlikeBenchBySql', JavaExec) {
classpath = sourceSets.main.runtimeClasspath
mainClass = 'com.tsurugidb.tsubakuro.kvs.ycsb.YCSBlikeBenchmark'
jvmArgs = ['--add-opens=java.base/java.nio=ALL-UNNAMED', '-Xmx1024M', '-DuseSqlClient=true']
args = ['ipc:tsurugi', '1,2,4,8', '50', '10', '30']

systemProperty 'com.tsurugidb.tsubakuro.jniverify', 'false'

systemProperty 'org.slf4j.simpleLogger.defaultLogLevel', findProperty('loglevel') ?: 'info'
systemProperty 'org.slf4j.simpleLogger.showThreadName', 'false'
systemProperty 'org.slf4j.simpleLogger.showShortLogName', 'true'
systemProperty 'org.slf4j.simpleLogger.levelInBrackets', 'true'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.tsurugidb.tsubakuro.kvs.bench;

/**
* elapsed time counter.
*/
class Elapse {

private final long start = System.currentTimeMillis();

/**
* retrieve elapsed time in milli second.
* @return elapsed time in milli second
*/
public long msec() {
return System.currentTimeMillis() - start;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
package com.tsurugidb.tsubakuro.kvs.bench;

import java.net.URI;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

import com.tsurugidb.tsubakuro.channel.common.connection.Credential;
import com.tsurugidb.tsubakuro.channel.common.connection.NullCredential;
import com.tsurugidb.tsubakuro.common.SessionBuilder;
import com.tsurugidb.tsubakuro.kvs.impl.KvsServiceStub;
import com.tsurugidb.tsubakuro.kvs.util.RunManager;

/**
* Empty message send/receive benchmark
*/
final class EmptyMessageBench {

private final URI endpoint;
private final List<Integer> numClients;
private final long warmupMsec;
private final long runningMsec;
private final Credential credential = NullCredential.INSTANCE;

private EmptyMessageBench(String[] args) {
this.endpoint = URI.create(args[0]);
var nums = args[1].split(",");
this.numClients = new ArrayList<Integer>(nums.length);
for (var s : nums) {
this.numClients.add(Integer.parseInt(s));
}
this.warmupMsec = Long.parseLong(args[2]) * 1000L;
this.runningMsec = Long.parseLong(args[3]) * 1000L;
System.out.println("endpoint=" + endpoint + ", numClients=" + args[1] + ", warmupSec=" + (warmupMsec / 1000)
+ ", runningSec=" + (runningMsec / 1000));
}

private class EmptyMessageLoop implements Callable<Long> {

private final RunManager mgr;

EmptyMessageLoop(RunManager mgr) {
this.mgr = mgr;
}

@Override
public Long call() throws Exception {
long nloop = 0;
try (var session = SessionBuilder.connect(endpoint).withCredential(credential).create();
var service = new KvsServiceStub(session)) {
mgr.addReadyWorker();
mgr.waitUntilWorkerStartTime();
while (!mgr.isQuit()) {
service.request().await();
nloop++;
}
}
return nloop;
}
}

private void bench(int numClient, long loopMsec) throws InterruptedException, ExecutionException {
RunManager mgr = new RunManager(numClient);
ExecutorService executor = Executors.newFixedThreadPool(numClient);
var clients = new ArrayList<Future<Long>>(numClient);
for (int i = 0; i < numClient; i++) {
clients.add(executor.submit(new EmptyMessageLoop(mgr)));
}
mgr.setWorkerStartTime();
Thread.sleep(loopMsec);
mgr.setQuit();
long nloopSum = 0;
for (var future : clients) {
nloopSum += future.get();
}
executor.shutdown();
//
double sec = loopMsec / 1000.0;
long numMsg = 2 * nloopSum; // one loop handles request and response messages
System.out.printf("%d,%d,%.1f,%.1f,%.3f", numClient, numMsg, sec, numMsg / sec, sec / numMsg * 1e+6);
System.out.println();
}

private void bench() throws InterruptedException, ExecutionException {
System.out.println("# nclient, elapsed_sec, num_messages, message/sec, usec/message");
bench(1, warmupMsec);
for (int numClient : numClients) {
bench(numClient, runningMsec);
}
}

/**
* main.
* @param args program arguments.
*/
public static void main(String[] args) {
if (args.length < 4 || args[0].contains("help")) {
System.out.println("Usage: java EmptyMessageBench endpoint num_client(s) warmup_sec running_sec");
System.out.println("\tex: java EmptyMessageBench ipc:tsurugi 1 30 60");
System.out.println("\tex: java EmptyMessageBench ipc:tsurugi 1,2,4,8,16 30 60");
return;
}
EmptyMessageBench app = new EmptyMessageBench(args);
try {
app.bench();
} catch (Exception e) {
e.printStackTrace();
}
}

}
Loading

0 comments on commit 7f13da8

Please sign in to comment.