From 4b0608980d6aebdcf5603553a4b24123592152ff Mon Sep 17 00:00:00 2001 From: Min Zhou Date: Wed, 15 Jul 2015 11:20:07 -0700 Subject: [PATCH] Refactor code * Move all benchmark relative code into a new benchmark module * Add hadoop style shell scripts for benchmark --- bin/client/clientcommon.sh | 6 - bin/client/nettyrpc.sh | 2 - bin/client/nettysimple.sh | 2 - bin/server/nettyserver.sh | 2 - bin/server/servercommon.sh | 2 - build.gradle | 7 +- gradle/convention.gradle | 8 +- gradle/maven.gradle | 18 +- gradle/minzhou-oss.gradle | 1 + gradle/release.gradle | 2 +- gradle/tango-oss.gradle | 1 - lightningrpc-benchmark/bin/benchmark | 261 ++++++++++++++++++ .../bin/benchmark-config.sh | 70 +++++ .../bin/benchmark-daemon.sh | 144 ++++++++++ lightningrpc-benchmark/conf/application.conf | 6 + lightningrpc-benchmark/conf/discovery-env.sh | 71 +++++ lightningrpc-benchmark/conf/log4j.properties | 76 +++++ .../benchmark/AbstractBenchmarkClient.java | 1 + .../benchmark/AbstractBenchmarkServer.java | 1 + .../benchmark/AbstractRPCBenchmarkClient.java | 0 ...bstractSimpleProcessorBenchmarkClient.java | 0 .../rpc/benchmark/BenchmarkTestService.java | 0 .../benchmark/BenchmarkTestServiceImpl.java | 0 .../rpc/benchmark/ClientRunnable.java | 0 .../minzhou/lightning/rpc/benchmark/PB.java | 0 .../benchmark/PBBenchmarkTestServiceImpl.java | 0 .../benchmark/RPCBenchmarkClientRunnable.java | 0 .../rpc/benchmark/RequestObject.java | 0 .../benchmark/RequestObjectSerializer.java | 0 .../rpc/benchmark/ResponseObject.java | 0 .../benchmark/ResponseObjectSerializer.java | 0 ...impleProcessorBenchmarkClientRunnable.java | 0 .../netty}/NettyBenchmarkServer.java | 2 +- .../netty}/NettyRPCBenchmarkClient.java | 2 +- .../netty}/NettySimpleBenchmarkClient.java | 2 +- .../lightning/rpc/protocol/KryoDecoder.java | 2 - .../lightning/rpc/protocol/KryoEncoder.java | 2 - .../{benchmark => protocol}/KryoUtils.java | 8 +- .../rpc/server/RPCJava7ServerHandler.java.txt | 108 -------- .../src/main/resources/log4j.properties | 15 - settings.gradle | 2 +- 41 files changed, 659 insertions(+), 165 deletions(-) delete mode 100644 bin/client/clientcommon.sh delete mode 100644 bin/client/nettyrpc.sh delete mode 100644 bin/client/nettysimple.sh delete mode 100644 bin/server/nettyserver.sh delete mode 100644 bin/server/servercommon.sh create mode 100644 gradle/minzhou-oss.gradle delete mode 100644 gradle/tango-oss.gradle create mode 100755 lightningrpc-benchmark/bin/benchmark create mode 100644 lightningrpc-benchmark/bin/benchmark-config.sh create mode 100755 lightningrpc-benchmark/bin/benchmark-daemon.sh create mode 100644 lightningrpc-benchmark/conf/application.conf create mode 100644 lightningrpc-benchmark/conf/discovery-env.sh create mode 100644 lightningrpc-benchmark/conf/log4j.properties rename {lightningrpc-common => lightningrpc-benchmark}/src/main/java/info/minzhou/lightning/rpc/benchmark/AbstractBenchmarkClient.java (99%) rename {lightningrpc-common => lightningrpc-benchmark}/src/main/java/info/minzhou/lightning/rpc/benchmark/AbstractBenchmarkServer.java (96%) rename {lightningrpc-common => lightningrpc-benchmark}/src/main/java/info/minzhou/lightning/rpc/benchmark/AbstractRPCBenchmarkClient.java (100%) rename {lightningrpc-common => lightningrpc-benchmark}/src/main/java/info/minzhou/lightning/rpc/benchmark/AbstractSimpleProcessorBenchmarkClient.java (100%) rename {lightningrpc-common => lightningrpc-benchmark}/src/main/java/info/minzhou/lightning/rpc/benchmark/BenchmarkTestService.java (100%) rename {lightningrpc-common => lightningrpc-benchmark}/src/main/java/info/minzhou/lightning/rpc/benchmark/BenchmarkTestServiceImpl.java (100%) rename {lightningrpc-common => lightningrpc-benchmark}/src/main/java/info/minzhou/lightning/rpc/benchmark/ClientRunnable.java (100%) rename {lightningrpc-common => lightningrpc-benchmark}/src/main/java/info/minzhou/lightning/rpc/benchmark/PB.java (100%) rename {lightningrpc-common => lightningrpc-benchmark}/src/main/java/info/minzhou/lightning/rpc/benchmark/PBBenchmarkTestServiceImpl.java (100%) rename {lightningrpc-common => lightningrpc-benchmark}/src/main/java/info/minzhou/lightning/rpc/benchmark/RPCBenchmarkClientRunnable.java (100%) rename {lightningrpc-common => lightningrpc-benchmark}/src/main/java/info/minzhou/lightning/rpc/benchmark/RequestObject.java (100%) rename {lightningrpc-common => lightningrpc-benchmark}/src/main/java/info/minzhou/lightning/rpc/benchmark/RequestObjectSerializer.java (100%) rename {lightningrpc-common => lightningrpc-benchmark}/src/main/java/info/minzhou/lightning/rpc/benchmark/ResponseObject.java (100%) rename {lightningrpc-common => lightningrpc-benchmark}/src/main/java/info/minzhou/lightning/rpc/benchmark/ResponseObjectSerializer.java (100%) rename {lightningrpc-common => lightningrpc-benchmark}/src/main/java/info/minzhou/lightning/rpc/benchmark/SimpleProcessorBenchmarkClientRunnable.java (100%) rename {lightningrpc-netty/src/main/java/info/minzhou/lightning/rpc/netty/benchmark => lightningrpc-benchmark/src/main/java/info/minzhou/lightning/rpc/benchmark/netty}/NettyBenchmarkServer.java (86%) rename {lightningrpc-netty/src/main/java/info/minzhou/lightning/rpc/netty/benchmark => lightningrpc-benchmark/src/main/java/info/minzhou/lightning/rpc/benchmark/netty}/NettyRPCBenchmarkClient.java (92%) rename {lightningrpc-netty/src/main/java/info/minzhou/lightning/rpc/netty/benchmark => lightningrpc-benchmark/src/main/java/info/minzhou/lightning/rpc/benchmark/netty}/NettySimpleBenchmarkClient.java (88%) rename lightningrpc-common/src/main/java/info/minzhou/lightning/rpc/{benchmark => protocol}/KryoUtils.java (92%) delete mode 100644 lightningrpc-common/src/main/java/info/minzhou/lightning/rpc/server/RPCJava7ServerHandler.java.txt delete mode 100644 lightningrpc-netty/src/main/resources/log4j.properties diff --git a/bin/client/clientcommon.sh b/bin/client/clientcommon.sh deleted file mode 100644 index 46b32b4..0000000 --- a/bin/client/clientcommon.sh +++ /dev/null @@ -1,6 +0,0 @@ -# datatype -# java 1 -# hessian 2 -# protobuf 3 -# kryo 4 -java -Xms4g -Xmx4g -Xmn1g -XX:+PrintGCDetails -XX:+PrintGCDateStamps -Xloggc:gc.log -Dwrite.statistics=true -Djava.ext.dirs="../../lib" $1 [serverip] [serverport] [concurrents] [timeout] [datatype] [requestsize] [runtime] [clientnums] > $2 2>&1 & \ No newline at end of file diff --git a/bin/client/nettyrpc.sh b/bin/client/nettyrpc.sh deleted file mode 100644 index 4f124c1..0000000 --- a/bin/client/nettyrpc.sh +++ /dev/null @@ -1,2 +0,0 @@ -cd `dirname $0` -sh clientcommon.sh "info.minzhou.lightning.rpc.netty.benchmark.NettyRPCBenchmarkClient" "benchmark.log.netty.rpc" diff --git a/bin/client/nettysimple.sh b/bin/client/nettysimple.sh deleted file mode 100644 index 18dea06..0000000 --- a/bin/client/nettysimple.sh +++ /dev/null @@ -1,2 +0,0 @@ -cd `dirname $0` -sh clientcommon.sh "info.minzhou.lightning.rpc.netty.benchmark.NettySimpleBenchmarkClient" "benchmark.log.netty.simple" diff --git a/bin/server/nettyserver.sh b/bin/server/nettyserver.sh deleted file mode 100644 index 1f2b68e..0000000 --- a/bin/server/nettyserver.sh +++ /dev/null @@ -1,2 +0,0 @@ -cd `dirname $0` -sh servercommon.sh "info.minzhou.lightning.rpc.netty.benchmark.NettyBenchmarkServer" "server.log.netty" diff --git a/bin/server/servercommon.sh b/bin/server/servercommon.sh deleted file mode 100644 index 3e7d740..0000000 --- a/bin/server/servercommon.sh +++ /dev/null @@ -1,2 +0,0 @@ -# java -Djava.ext.dirs=... mainClassName listenPort maxThreads responseSize -java -Xms2g -Xmx2g -Xmn500m -XX:+PrintGCDetails -XX:+PrintGCDateStamps -Xloggc:gc.log -Djava.ext.dirs="../../lib" $1 12200 100 100 > $2 2>&1 & \ No newline at end of file diff --git a/build.gradle b/build.gradle index dbedd80..f794240 100644 --- a/build.gradle +++ b/build.gradle @@ -48,7 +48,6 @@ project(':lightningrpc-common') { } - project(':lightningrpc-netty') { dependencies { compile project(':lightningrpc-common') @@ -56,3 +55,9 @@ project(':lightningrpc-netty') { } } +project(':lightningrpc-benchmark') { + dependencies { + compile project(':lightningrpc-netty') + } +} + diff --git a/gradle/convention.gradle b/gradle/convention.gradle index 341db06..3d7d6be 100644 --- a/gradle/convention.gradle +++ b/gradle/convention.gradle @@ -89,7 +89,7 @@ def docTasks = [:] } githubPages { - repoUri = "git@github.com:TangoMe/${rootProject.githubProjectName}.git" + repoUri = "git@github.com:coderplay/${rootProject.githubProjectName}.git" pages { docTasks.each { shortName, docTask -> from(docTask.outputs.files) { @@ -110,12 +110,12 @@ task releaseTarGz(type: Tar, dependsOn: subprojects.assemble) { into "${baseName}" compression = Compression.GZIP duplicatesStrategy = DuplicatesStrategy.EXCLUDE - from(project.file("bin")) { into "bin/" } - from(project.file("conf")) { into "conf/" } - from(project.file("logs")) { into "logs/" } from 'LICENSE' from 'README.md' subprojects.each { child -> + from(child.file("bin")) { into "bin/" } + from(child.file("conf")) { into "conf/" } + from(child.file("logs")) { into "logs/" } from(child.jar.archivePath) from(child.configurations.runtime) { into("lib/") } } diff --git a/gradle/maven.gradle b/gradle/maven.gradle index cf1effe..85d1d70 100644 --- a/gradle/maven.gradle +++ b/gradle/maven.gradle @@ -39,12 +39,12 @@ task uploadMavenCentral(type:Upload, dependsOn: signArchives) { // Closure to configure all the POM with extra info, common to all projects pom.project { name "${project.name}" - description "${project.name} developed by TangoMe" + description "${project.name} developed by Min Zhou" developers { developer { - id 'tangogithub' - name 'TangoMe Open Source Development' - email 'talent@tango.me' + id 'mzhou' + name 'Min Zhou Open Source Development' + email 'mzhou@apache.org' } } licenses { @@ -54,15 +54,15 @@ task uploadMavenCentral(type:Upload, dependsOn: signArchives) { distribution 'repo' } } - url "https://github.com/TangoMe/${rootProject.githubProjectName}" + url "https://github.com/coderplay/${rootProject.githubProjectName}" scm { - connection "scm:git:git@github.com:TangoMe/${rootProject.githubProjectName}.git" - url "scm:git:git@github.com:TangoMe/${rootProject.githubProjectName}.git" - developerConnection "scm:git:git@github.com:TangoMe/${rootProject.githubProjectName}.git" + connection "scm:git:git@github.com:coderplay/${rootProject.githubProjectName}.git" + url "scm:git:git@github.com:coderplay/${rootProject.githubProjectName}.git" + developerConnection "scm:git:git@github.com:coderplay/${rootProject.githubProjectName}.git" } issueManagement { system 'github' - url "https://github.com/TangoMe/${rootProject.githubProjectName}/issues" + url "https://github.com/coderplay/${rootProject.githubProjectName}/issues" } } } diff --git a/gradle/minzhou-oss.gradle b/gradle/minzhou-oss.gradle new file mode 100644 index 0000000..45e006d --- /dev/null +++ b/gradle/minzhou-oss.gradle @@ -0,0 +1 @@ +apply from: 'http://artifacts.minzhou.info/gradle-minzhou-local/artifactory.gradle' diff --git a/gradle/release.gradle b/gradle/release.gradle index 3107fa2..4f73091 100644 --- a/gradle/release.gradle +++ b/gradle/release.gradle @@ -7,7 +7,7 @@ apply plugin: 'release' doFirst { startParameter.projectProperties = [status: project.status, preferredStatus: project.status] } - startParameter.addInitScript( file('gradle/tango-oss.gradle') ) + startParameter.addInitScript( file('gradle/mzhou-oss.gradle') ) startParameter.getExcludedTaskNames().add('check') tasks = [ 'build', value ] } diff --git a/gradle/tango-oss.gradle b/gradle/tango-oss.gradle deleted file mode 100644 index 29e83cd..0000000 --- a/gradle/tango-oss.gradle +++ /dev/null @@ -1 +0,0 @@ -apply from: 'http://artifacts.tango.me/gradle-tango-local/artifactory.gradle' diff --git a/lightningrpc-benchmark/bin/benchmark b/lightningrpc-benchmark/bin/benchmark new file mode 100755 index 0000000..78192ee --- /dev/null +++ b/lightningrpc-benchmark/bin/benchmark @@ -0,0 +1,261 @@ +#!/usr/bin/env bash + +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +# The Benchmark command script +# +# Environment Variables +# +# JAVA_HOME The java implementation to use. Overrides JAVA_HOME. +# +# BENCHMARK_CLASSPATH Extra Java CLASSPATH entries. +# +# BENCHMARK_USER_CLASSPATH_FIRST When defined, the BENCHMARK_CLASSPATH is +# added in the beginning of the global +# classpath. Can be defined, for example, +# by doing +# export BENCHMARK_USER_CLASSPATH_FIRST=true +# +# BENCHMARK_SERVER_HEAPSIZE The maximum amount of heap to use, in MB. +# Default is 1000. +# +# BENCHMARK_CLIENT_HEAPSIZE The maximum amount of heap to use, in MB. +# Default is 1000. +# +# BENCHMARK_OPTS Extra Java runtime options. +# +# BENCHMARK_CONF_DIR Alternate conf dir. Default is ${BENCHMARK_HOME}/conf. +# +# + +bin=`dirname "$0"` +bin=`cd "$bin"; pwd` + +. "$bin"/benchmark-config.sh + +cygwin=false +case "`uname`" in +CYGWIN*) cygwin=true;; +esac + +function print_usage() { + echo "Usage: benchmark [--config confdir] COMMAND" + echo "where COMMAND is one of:" + echo " server run the benchmark server" + echo " client run the benchmark rpc client" + echo " simple-client run the benchmark simple client" + echo " classpath prints the class path needed to get the" + echo " Benchmark jar and the required libraries" + echo " or" + echo " CLASSNAME run the class named CLASSNAME" + echo "Most commands print help when invoked w/o parameters." +} + +# if no args specified, show usage +if [ $# = 0 ]; then + print_usage + exit 1 +fi + +# get arguments +COMMAND=$1 +shift + +if [ "$COMMAND" == "--help" ] || [ "$COMMAND" == "-help" ] || [ "$COMMAND" == "-h" ] ; then + print_usage + exit +fi + +if [ -f "${BENCHMARK_CONF_DIR}/benchmark-env.sh" ]; then + . "${BENCHMARK_CONF_DIR}/benchmark-env.sh" +fi + +# some Java parameters +if [ "$JAVA_HOME" != "" ]; then + #echo "run java in $JAVA_HOME" + JAVA_HOME=$JAVA_HOME +fi + +if [ "$JAVA_HOME" = "" ]; then + echo "Error: JAVA_HOME is not set." + exit 1 +fi + +JAVA=$JAVA_HOME/bin/java +JAVA_BENCHMARK_SERVER_HEAP_MAX=-Xmx1024m +JAVA_ICF_SERVER_HEAP_MAX=-Xmx1024m +JAVA_CONN_SERVER_HEAP_MAX=-Xmx1024m + +# check envvars which might override default args +if [ "$BENCHMARK_SERVER_HEAPSIZE" != "" ]; then + #echo "run with heapsize $BENCHMARK_SERVER_HEAPSIZE" + JAVA_BENCHMARK_SERVER_HEAP_MAX="-Xmx""$BENCHMARK_SERVER_HEAPSIZE""m" + #echo $JAVA_SERVER_HEAP_MAX +fi +if [ "$BENCHMARK_ICF_SERVER_HEAPSIZE" != "" ]; then + #echo "run with heapsize $BENCHMARK_ICF_SERVER_HEAPSIZE" + JAVA_ICF_SERVER_HEAP_MAX="-Xmx""$BENCHMARK_ICF_SERVER_HEAPSIZE""m" + #echo JAVA_ICF_SERVER_HEAP_MAX +fi +if [ "$BENCHMARK_CONN_SERVER_HEAPSIZE" != "" ]; then + #echo "run with heapsize $BENCHMARK_CONN_SERVER_HEAPSIZE" + JAVA_CONN_SERVER_HEAP_MAX="-Xmx""$BENCHMARK_CONN_SERVER_HEAPSIZE""m" + #echo JAVA_CONN_SERVER_HEAP_MAX +fi + +############################################################################## +# Find and Set Benchmark CLASSPATH +############################################################################## + +# BENCHMARK_BASE_CLASSPATH initially contains $BENCHMARK_CONF_DIR +BENCHMARK_BASE_CLASSPATH="${BENCHMARK_CONF_DIR}" + +# for developers, add Benchmark classes to BENCHMARK_BASE_CLASSPATH +if [ -d "$BENCHMARK_HOME/target/classes" ]; then + BENCHMARK_BASE_CLASSPATH=${BENCHMARK_BASE_CLASSPATH}:$BENCHMARK_HOME/target/classes +fi +if [ -d "$BENCHMARK_HOME/target/test/classes" ]; then + BENCHMARK_BASE_CLASSPATH=${BENCHMARK_BASE_CLASSPATH}:$BENCHMARK_HOME/target/test/classes +fi + +# so that filenames w/ spaces are handled correctly in loops below +IFS=$'\n' + +# Benchmark Jar Directory +BENCHMARK_JAR_DIRS="$BENCHMARK_HOME +${BENCHMARK_HOME}/lib" + +for d in $BENCHMARK_JAR_DIRS; do + for j in `find $d/*.jar ! -name "*test*"`; do + BENCHMARK_BASE_CLASSPATH=$BENCHMARK_BASE_CLASSPATH:$j + done +done + +# add user-specified CLASSPATH last +if [ "$BENCHMARK_CLASSPATH" != "" ]; then + if [ "$BENCHMARK_USER_CLASSPATH_FIRST" != "" ]; then + BENCHMARK_BASE_CLASSPATH=${BENCHMARK_CLASSPATH}:${BENCHMARK_BASE_CLASSPATH} + else + BENCHMARK_BASE_CLASSPATH=${BENCHMARK_BASE_CLASSPATH}:${BENCHMARK_CLASSPATH} + fi +fi + +export BENCHMARK_BASE_CLASSPATH + +CLASSPATH="${BENCHMARK_BASE_CLASSPATH}:${CLASSPATH}" + +############################################################################## +# Benchmark Home Configuration End +############################################################################## + +# restore ordinary behaviour +unset IFS + +# default log directory & file +if [ "$BENCHMARK_LOG_DIR" = "" ]; then + BENCHMARK_LOG_DIR="$BENCHMARK_HOME/logs" +fi +if [ "$BENCHMARK_LOGFILE" = "" ]; then + BENCHMARK_LOGFILE='benchmark.log' +fi + +# default policy file for service-level authorization +if [ "$BENCHMARK_POLICYFILE" = "" ]; then + BENCHMARK_POLICYFILE="benchmark-policy.xml" +fi + +# Disable IPv6 Support for network performance +BENCHMARK_OPTS="$BENCHMARK_OPTS -Djava.net.preferIPv4Stack=true" + +# figure out which class to run +if [ "$COMMAND" = "classpath" ] ; then + if $cygwin; then + CLASSPATH=`cygpath -p -w "$CLASSPATH"` + fi + echo $CLASSPATH + exit +elif [ "$COMMAND" = "server" ] ; then + CLASS='info.minzhou.lightning.rpc.netty.benchmark.NettyBenchmarkServer" + BENCHMARK_OPTS="$BENCHMARK_OPTS $JAVA_BENCHMARK_SERVER_HEAP_MAX $BENCHMARK_SERVER_OPTS" +elif [ "$COMMAND" = "client" ] ; then + CLASS="info.minzhou.lightning.rpc.netty.benchmark.NettyRPCBenchmarkClient" + BENCHMARK_OPTS="$BENCHMARK_OPTS $JAVA_CLIENT_HEAP_MAX $BENCHMARK_CLIENT_OPTS" +elif [ "$COMMAND" = "simple-client" ] ; then + CLASS="info.minzhou.lightning.rpc.netty.benchmark.NettySimpleBenchmarkClient" + BENCHMARK_OPTS="$BENCHMARK_OPTS $JAVA_CLIENT_HEAP_MAX $BENCHMARK_CLIENT_OPTS" +elif [ "$COMMAND" = "version" ] ; then + CLASS='info.minzhou.lightning.rpc.VersionInfo' + BENCHMARK_ROOT_LOGGER_APPENDER="${BENCHMARK_ROOT_LOGGER_APPENDER:-NullAppender}" + BENCHMARK_OPTS="$BENCHMARK_OPTS $BENCHMARK_CLI_OPTS" +else + CLASS=$COMMAND +fi + +# cygwin path translation +if $cygwin; then + CLASSPATH=`cygpath -p -w "$CLASSPATH"` + BENCHMARK_HOME=`cygpath -w "$BENCHMARK_HOME"` + BENCHMARK_LOG_DIR=`cygpath -w "$BENCHMARK_LOG_DIR"` + TOOL_PATH=`cygpath -p -w "$TOOL_PATH"` +fi +# setup 'java.library.path' for native-benchmark code if necessary +JAVA_LIBRARY_PATH='' +if [ -d "${BENCHMARK_HOME}/build/native" -o -d "${BENCHMARK_HOME}/lib/native" ]; then + JAVA_PLATFORM=`CLASSPATH=${CLASSPATH} ${JAVA} -Xmx32m ${BENCHMARK_JAVA_PLATFORM_OPTS} org.apache.benchmark.util.PlatformName | sed -e "s/ /_/g"` + + if [ -d "$BENCHMARK_HOME/build/native" ]; then + JAVA_LIBRARY_PATH=${BENCHMARK_HOME}/build/native/${JAVA_PLATFORM}/lib + fi + + if [ -d "${BENCHMARK_HOME}/lib/native" ]; then + if [ "x$JAVA_LIBRARY_PATH" != "x" ]; then + JAVA_LIBRARY_PATH=${JAVA_LIBRARY_PATH}:${BENCHMARK_HOME}/lib/native/${JAVA_PLATFORM} + else + JAVA_LIBRARY_PATH=${BENCHMARK_HOME}/lib/native/${JAVA_PLATFORM} + fi + fi +fi + +if [ "x$JAVA_LIBRARY_PATH" != "x" ]; then + JAVA_LIBRARY_PATH=${JAVA_LIBRARY_PATH}:${HDFS_LIBRARY_PATH} + else + JAVA_LIBRARY_PATH=${HDFS_LIBRARY_PATH} +fi + +# cygwin path translation +if $cygwin; then + JAVA_LIBRARY_PATH=`cygpath -p "$JAVA_LIBRARY_PATH"` +fi + +BENCHMARK_OPTS="$BENCHMARK_OPTS -Dbenchmark.log.dir=$BENCHMARK_LOG_DIR" +BENCHMARK_OPTS="$BENCHMARK_OPTS -Dbenchmark.log.file=$BENCHMARK_LOGFILE" +BENCHMARK_OPTS="$BENCHMARK_OPTS -Dbenchmark.home.dir=$BENCHMARK_HOME" +BENCHMARK_OPTS="$BENCHMARK_OPTS -Dbenchmark.id.str=$BENCHMARK_IDENT_STRING" +BENCHMARK_OPTS="$BENCHMARK_OPTS -Dbenchmark.root.logger.appender=${BENCHMARK_ROOT_LOGGER_APPENDER:-console}" +if [ "x$BENCHMARK_ROOT_LOGGER_LEVEL" != "x" ]; then + BENCHMARK_OPTS="$BENCHMARK_OPTS -Dbenchmark.root.logger.level=${BENCHMARK_ROOT_LOGGER_LEVEL}" +fi + +if [ "x$JAVA_LIBRARY_PATH" != "x" ]; then + BENCHMARK_OPTS="$BENCHMARK_OPTS -Djava.library.path=$JAVA_LIBRARY_PATH" +fi +BENCHMARK_OPTS="$BENCHMARK_OPTS -Dbenchmark.policy.file=$BENCHMARK_POLICYFILE" + +# run it +export CLASSPATH=$CLASSPATH +exec "$JAVA" -Dproc_$COMMAND $BENCHMARK_OPTS $CLASS $BENCHMARK_DAEMON_MODE "$@" diff --git a/lightningrpc-benchmark/bin/benchmark-config.sh b/lightningrpc-benchmark/bin/benchmark-config.sh new file mode 100644 index 0000000..4bda5ee --- /dev/null +++ b/lightningrpc-benchmark/bin/benchmark-config.sh @@ -0,0 +1,70 @@ +#!/usr/bin/env bash +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# included in all the benchmark scripts with source command +# should not be executable directly +# also should not be passed any arguments, since we need original $* + +# resolve links - $0 may be a softlink + +this="$0" +while [ -h "$this" ]; do + ls=`ls -ld "$this"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '.*/.*' > /dev/null; then + this="$link" + else + this=`dirname "$this"`/"$link" + fi +done + +# convert relative path to absolute path +bin=`dirname "$this"` +script=`basename "$this"` +bin=`cd "$bin"; pwd` +this="$bin/$script" + +# the root of the benchmark installation +export BENCHMARK_HOME=`dirname "$this"`/.. + +#check to see if the conf dir is given as an optional argument +if [ $# -gt 1 ] +then + if [ "--config" = "$1" ] + then + shift + confdir=$1 + shift + BENCHMARK_CONF_DIR=$confdir + fi +fi + +# Allow alternate conf dir location. +BENCHMARK_CONF_DIR="${BENCHMARK_CONF_DIR:-$BENCHMARK_HOME/conf}" + +#check to see it is specified whether to use the workers or the +# workers file +if [ $# -gt 1 ] +then + if [ "--hosts" = "$1" ] + then + shift + workerfile=$1 + shift + export BENCHMARK_WORKERS="${BENCHMARK_CONF_DIR}/$workerfile" + fi +fi diff --git a/lightningrpc-benchmark/bin/benchmark-daemon.sh b/lightningrpc-benchmark/bin/benchmark-daemon.sh new file mode 100755 index 0000000..f376fb4 --- /dev/null +++ b/lightningrpc-benchmark/bin/benchmark-daemon.sh @@ -0,0 +1,144 @@ +#!/usr/bin/env bash + +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +# Runs a Benchmark command as a daemon. +# +# Environment Variables +# +# BENCHMARK_CONF_DIR Alternate conf dir. Default is ${BENCHMARK_HOME}/conf. +# BENCHMARK_LOG_DIR Where log files are stored. PWD by default. +# BENCHMARK_MASTER host:path where benchmark code should be rsync'd from +# BENCHMARK_PID_DIR The pid files are stored. /tmp by default. +# BENCHMARK_IDENT_STRING A string representing this instance of benchmark. $USER by default +# BENCHMARK_NICENESS The scheduling priority for daemons. Defaults to 0. +## + +usage="Usage: benchmark-daemon.sh [--config ] [--hosts hostlistfile] (start|stop) " + +# if no args specified, show usage +if [ $# -le 1 ]; then + echo $usage + exit 1 +fi + +bin=`dirname "$0"` +bin=`cd "$bin"; pwd` + +. "$bin"/benchmark-config.sh + +# get arguments +startStop=$1 +shift +command=$1 +shift + +benchmark_rotate_log () +{ + log=$1; + num=5; + if [ -n "$2" ]; then + num=$2 + fi + if [ -f "$log" ]; then # rotate logs + while [ $num -gt 1 ]; do + prev=`expr $num - 1` + [ -f "$log.$prev" ] && mv "$log.$prev" "$log.$num" + num=$prev + done + mv "$log" "$log.$num"; + fi +} + +if [ -f "${BENCHMARK_CONF_DIR}/benchmark-env.sh" ]; then + . "${BENCHMARK_CONF_DIR}/benchmark-env.sh" +fi + +if [ "$BENCHMARK_IDENT_STRING" = "" ]; then + export BENCHMARK_IDENT_STRING="$USER" +fi + +# get log directory +if [ "$BENCHMARK_LOG_DIR" = "" ]; then + export BENCHMARK_LOG_DIR="$BENCHMARK_HOME/logs" +fi +mkdir -p "$BENCHMARK_LOG_DIR" +chown $BENCHMARK_IDENT_STRING $BENCHMARK_LOG_DIR + +if [ "$BENCHMARK_PID_DIR" = "" ]; then + BENCHMARK_PID_DIR=/tmp +fi + +# some variables +export BENCHMARK_LOGFILE=benchmark-$BENCHMARK_IDENT_STRING-$command-$HOSTNAME.log +export BENCHMARK_ROOT_LOGGER_APPENDER="${BENCHMARK_ROOT_LOGGER_APPENDER:-DRFA}" +export BENCHMARK_PULLSERVER_STANDALONE="${BENCHMARK_PULLSERVER_STANDALONE:-false}" +log=$BENCHMARK_LOG_DIR/benchmark-$BENCHMARK_IDENT_STRING-$command-$HOSTNAME.out +pid=$BENCHMARK_PID_DIR/benchmark-$BENCHMARK_IDENT_STRING-$command.pid + +# Set default scheduling priority +if [ "$BENCHMARK_NICENESS" = "" ]; then + export BENCHMARK_NICENESS=0 +fi + +case $startStop in + + (start) + + mkdir -p "$BENCHMARK_PID_DIR" + + if [ -f $pid ]; then + if kill -0 `cat $pid` > /dev/null 2>&1; then + echo $command running as process `cat $pid`. Stop it first. + exit 1 + fi + fi + + if [ "$BENCHMARK_MASTER" != "" ]; then + echo rsync from $BENCHMARK_MASTER + rsync -a -e ssh --delete --exclude=.svn --exclude='logs/*' --exclude='contrib/hod/logs/*' $BENCHMARK_MASTER/ "$BENCHMARK_HOME" + fi + + benchmark_rotate_log $log + echo starting $command, logging to $log + cd "$BENCHMARK_HOME" + nohup nice -n $BENCHMARK_NICENESS "$BENCHMARK_HOME"/bin/benchmark --config $BENCHMARK_CONF_DIR $command "$@" > "$log" 2>&1 < /dev/null & + echo $! > $pid + sleep 1; head "$log" + ;; + + (stop) + + if [ -f $pid ]; then + if kill -0 `cat $pid` > /dev/null 2>&1; then + echo stopping $command + kill `cat $pid` + else + echo no $command to stop + fi + else + echo no $command to stop + fi + ;; + + (*) + echo $usage + exit 1 + ;; + +esac \ No newline at end of file diff --git a/lightningrpc-benchmark/conf/application.conf b/lightningrpc-benchmark/conf/application.conf new file mode 100644 index 0000000..5283949 --- /dev/null +++ b/lightningrpc-benchmark/conf/application.conf @@ -0,0 +1,6 @@ +akka { + loggers = ["akka.event.slf4j.Slf4jLogger"] + loglevel = "INFO" +} + + diff --git a/lightningrpc-benchmark/conf/discovery-env.sh b/lightningrpc-benchmark/conf/discovery-env.sh new file mode 100644 index 0000000..4d437b6 --- /dev/null +++ b/lightningrpc-benchmark/conf/discovery-env.sh @@ -0,0 +1,71 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Set Benchmark-specific environment variables here. + +# The only required environment variable is JAVA_HOME. All others are +# optional. When running a distributed configuration it is best to +# set JAVA_HOME in this file, so that it is correctly defined on +# remote nodes. + +# The java implementation to use. Required. +# export JAVA_HOME=/usr/java/default + +# Extra Java CLASSPATH elements. Optional. +# export BENCHMARK_CLASSPATH=/xxx/extlib/*:/xxx/xxx.jar + +# The maximum amount of heap to use, in MB. Default is 1000. +# export BENCHMARK_SERVER_HEAPSIZE=1000 + +# The maximum amount of heap to use, in MB. Default is 1000. +# export BENCHMARK_CLIENT_HEAPSIZE=1000 + +# Extra Java runtime options. Empty by default. +# export BENCHMARK_OPTS=-server + +# Extra BenchmarkMaster's java runtime options for BenchmarkMaster. Empty by default +# export BENCHMARK_SERVER_OPTS= + +# Extra BenchmarkWorker's java runtime options. Empty by default +# export BENCHMARK_CLIENT_OPTS= + +# Extra BenchmarkPullServer's java runtime options. Empty by default +# export BENCHMARK_PULLSERVER_OPTS= + +# Extra QueryMaster mode BenchmarkWorker's java runtime options for BenchmarkMaster. Empty by default +# export BENCHMARK_QUERYSERVER_OPTS= + +# Where log files are stored. $BENCHMARK_HOME/logs by default. +# export BENCHMARK_LOG_DIR=${BENCHMARK_HOME}/logs + +# The directory where pid files are stored. /tmp by default. +# export BENCHMARK_PID_DIR=/var/benchmark/pids + +# A string representing this instance of benchmark. $USER by default. +# export BENCHMARK_IDENT_STRING=$USER + +# The scheduling priority for daemon processes. See 'man nice'. +# export BENCHMARK_NICENESS=10 + +# It must be required to use HiveCatalogStore +# export HIVE_HOME= +# export HIVE_JDBC_DRIVER_DIR= + +# Benchmark PullServer mode. the default is embedded mode (in worker) +# export BENCHMARK_PULLSERVER_STANDALONE=false + +# HBase home directory. It is opitional, but is required mandatorily to use HBase. +# export HBASE_HOME= \ No newline at end of file diff --git a/lightningrpc-benchmark/conf/log4j.properties b/lightningrpc-benchmark/conf/log4j.properties new file mode 100644 index 0000000..56e35f1 --- /dev/null +++ b/lightningrpc-benchmark/conf/log4j.properties @@ -0,0 +1,76 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# log4j configuration used during build and unit tests + +lightningrpc.root.logger.appender=console +lightningrpc.root.logger.level=INFO +lightningrpc.log.dir=. +lightningrpc.log.file=lightningrpc.log + +# Define the root logger to the system property "lightningrpc.root.logger.appender". +log4j.rootLogger=${lightningrpc.root.logger.level},${lightningrpc.root.logger.appender} + +# Logging Threshold +log4j.threshold=ALL + +# Null Appender +log4j.appender.NullAppender=org.apache.log4j.varia.NullAppender + +# +# Rolling File Appender - cap space usage at 5gb. +# +lightningrpc.log.maxfilesize=256MB +lightningrpc.log.maxbackupindex=20 +log4j.appender.RFA=org.apache.log4j.RollingFileAppender +log4j.appender.RFA.File=${lightningrpc.log.dir}/${lightningrpc.log.file} + +log4j.appender.RFA.MaxFileSize=${lightningrpc.log.maxfilesize} +log4j.appender.RFA.MaxBackupIndex=${lightningrpc.log.maxbackupindex} + +log4j.appender.RFA.layout=org.apache.log4j.PatternLayout + +# Pattern format: Date LogLevel LoggerName LogMessage +log4j.appender.RFA.layout.ConversionPattern=%d{ISO8601} %p %c: %m%n +# Debugging Pattern format +#log4j.appender.RFA.layout.ConversionPattern=%d{ISO8601} %-5p %c{2} (%F:%M(%L)) - %m%n + + +# +# Daily Rolling File Appender +# + +log4j.appender.DRFA=org.apache.log4j.DailyRollingFileAppender +log4j.appender.DRFA.File=${lightningrpc.log.dir}/${lightningrpc.log.file} + +# Rollver at midnight +log4j.appender.DRFA.DatePattern=.yyyy-MM-dd + +# 30-day backup +#log4j.appender.DRFA.MaxBackupIndex=30 +log4j.appender.DRFA.layout=org.apache.log4j.PatternLayout + +# Pattern format: Date LogLevel LoggerName LogMessage +log4j.appender.DRFA.layout.ConversionPattern=%d{ISO8601} %p %c: %m%n +# Debugging Pattern format +#log4j.appender.DRFA.layout.ConversionPattern=%d{ISO8601} %-5p %c{2} (%F:%M(%L)) - %m%n + + +# +# console +# Add "console" to rootlogger above if you want to use this +# + +log4j.appender.console=org.apache.log4j.ConsoleAppender +log4j.appender.console.target=System.err +log4j.appender.console.layout=org.apache.log4j.PatternLayout +log4j.appender.console.layout.ConversionPattern=%d{yy/MM/dd HH:mm:ss} %p %c{2}: %m%n \ No newline at end of file diff --git a/lightningrpc-common/src/main/java/info/minzhou/lightning/rpc/benchmark/AbstractBenchmarkClient.java b/lightningrpc-benchmark/src/main/java/info/minzhou/lightning/rpc/benchmark/AbstractBenchmarkClient.java similarity index 99% rename from lightningrpc-common/src/main/java/info/minzhou/lightning/rpc/benchmark/AbstractBenchmarkClient.java rename to lightningrpc-benchmark/src/main/java/info/minzhou/lightning/rpc/benchmark/AbstractBenchmarkClient.java index 31a27bc..20f5d3c 100644 --- a/lightningrpc-common/src/main/java/info/minzhou/lightning/rpc/benchmark/AbstractBenchmarkClient.java +++ b/lightningrpc-benchmark/src/main/java/info/minzhou/lightning/rpc/benchmark/AbstractBenchmarkClient.java @@ -15,6 +15,7 @@ import com.esotericsoftware.kryo.serializers.DefaultArraySerializers; import info.minzhou.lightning.rpc.Codecs; +import info.minzhou.lightning.rpc.protocol.KryoUtils; import info.minzhou.lightning.rpc.protocol.PBDecoder; /** diff --git a/lightningrpc-common/src/main/java/info/minzhou/lightning/rpc/benchmark/AbstractBenchmarkServer.java b/lightningrpc-benchmark/src/main/java/info/minzhou/lightning/rpc/benchmark/AbstractBenchmarkServer.java similarity index 96% rename from lightningrpc-common/src/main/java/info/minzhou/lightning/rpc/benchmark/AbstractBenchmarkServer.java rename to lightningrpc-benchmark/src/main/java/info/minzhou/lightning/rpc/benchmark/AbstractBenchmarkServer.java index de1afab..5c336a9 100644 --- a/lightningrpc-common/src/main/java/info/minzhou/lightning/rpc/benchmark/AbstractBenchmarkServer.java +++ b/lightningrpc-benchmark/src/main/java/info/minzhou/lightning/rpc/benchmark/AbstractBenchmarkServer.java @@ -9,6 +9,7 @@ import java.util.concurrent.TimeUnit; import info.minzhou.lightning.rpc.NamedThreadFactory; +import info.minzhou.lightning.rpc.protocol.KryoUtils; import info.minzhou.lightning.rpc.protocol.PBDecoder; import info.minzhou.lightning.rpc.protocol.RPCProtocol; import info.minzhou.lightning.rpc.protocol.SimpleProcessorProtocol; diff --git a/lightningrpc-common/src/main/java/info/minzhou/lightning/rpc/benchmark/AbstractRPCBenchmarkClient.java b/lightningrpc-benchmark/src/main/java/info/minzhou/lightning/rpc/benchmark/AbstractRPCBenchmarkClient.java similarity index 100% rename from lightningrpc-common/src/main/java/info/minzhou/lightning/rpc/benchmark/AbstractRPCBenchmarkClient.java rename to lightningrpc-benchmark/src/main/java/info/minzhou/lightning/rpc/benchmark/AbstractRPCBenchmarkClient.java diff --git a/lightningrpc-common/src/main/java/info/minzhou/lightning/rpc/benchmark/AbstractSimpleProcessorBenchmarkClient.java b/lightningrpc-benchmark/src/main/java/info/minzhou/lightning/rpc/benchmark/AbstractSimpleProcessorBenchmarkClient.java similarity index 100% rename from lightningrpc-common/src/main/java/info/minzhou/lightning/rpc/benchmark/AbstractSimpleProcessorBenchmarkClient.java rename to lightningrpc-benchmark/src/main/java/info/minzhou/lightning/rpc/benchmark/AbstractSimpleProcessorBenchmarkClient.java diff --git a/lightningrpc-common/src/main/java/info/minzhou/lightning/rpc/benchmark/BenchmarkTestService.java b/lightningrpc-benchmark/src/main/java/info/minzhou/lightning/rpc/benchmark/BenchmarkTestService.java similarity index 100% rename from lightningrpc-common/src/main/java/info/minzhou/lightning/rpc/benchmark/BenchmarkTestService.java rename to lightningrpc-benchmark/src/main/java/info/minzhou/lightning/rpc/benchmark/BenchmarkTestService.java diff --git a/lightningrpc-common/src/main/java/info/minzhou/lightning/rpc/benchmark/BenchmarkTestServiceImpl.java b/lightningrpc-benchmark/src/main/java/info/minzhou/lightning/rpc/benchmark/BenchmarkTestServiceImpl.java similarity index 100% rename from lightningrpc-common/src/main/java/info/minzhou/lightning/rpc/benchmark/BenchmarkTestServiceImpl.java rename to lightningrpc-benchmark/src/main/java/info/minzhou/lightning/rpc/benchmark/BenchmarkTestServiceImpl.java diff --git a/lightningrpc-common/src/main/java/info/minzhou/lightning/rpc/benchmark/ClientRunnable.java b/lightningrpc-benchmark/src/main/java/info/minzhou/lightning/rpc/benchmark/ClientRunnable.java similarity index 100% rename from lightningrpc-common/src/main/java/info/minzhou/lightning/rpc/benchmark/ClientRunnable.java rename to lightningrpc-benchmark/src/main/java/info/minzhou/lightning/rpc/benchmark/ClientRunnable.java diff --git a/lightningrpc-common/src/main/java/info/minzhou/lightning/rpc/benchmark/PB.java b/lightningrpc-benchmark/src/main/java/info/minzhou/lightning/rpc/benchmark/PB.java similarity index 100% rename from lightningrpc-common/src/main/java/info/minzhou/lightning/rpc/benchmark/PB.java rename to lightningrpc-benchmark/src/main/java/info/minzhou/lightning/rpc/benchmark/PB.java diff --git a/lightningrpc-common/src/main/java/info/minzhou/lightning/rpc/benchmark/PBBenchmarkTestServiceImpl.java b/lightningrpc-benchmark/src/main/java/info/minzhou/lightning/rpc/benchmark/PBBenchmarkTestServiceImpl.java similarity index 100% rename from lightningrpc-common/src/main/java/info/minzhou/lightning/rpc/benchmark/PBBenchmarkTestServiceImpl.java rename to lightningrpc-benchmark/src/main/java/info/minzhou/lightning/rpc/benchmark/PBBenchmarkTestServiceImpl.java diff --git a/lightningrpc-common/src/main/java/info/minzhou/lightning/rpc/benchmark/RPCBenchmarkClientRunnable.java b/lightningrpc-benchmark/src/main/java/info/minzhou/lightning/rpc/benchmark/RPCBenchmarkClientRunnable.java similarity index 100% rename from lightningrpc-common/src/main/java/info/minzhou/lightning/rpc/benchmark/RPCBenchmarkClientRunnable.java rename to lightningrpc-benchmark/src/main/java/info/minzhou/lightning/rpc/benchmark/RPCBenchmarkClientRunnable.java diff --git a/lightningrpc-common/src/main/java/info/minzhou/lightning/rpc/benchmark/RequestObject.java b/lightningrpc-benchmark/src/main/java/info/minzhou/lightning/rpc/benchmark/RequestObject.java similarity index 100% rename from lightningrpc-common/src/main/java/info/minzhou/lightning/rpc/benchmark/RequestObject.java rename to lightningrpc-benchmark/src/main/java/info/minzhou/lightning/rpc/benchmark/RequestObject.java diff --git a/lightningrpc-common/src/main/java/info/minzhou/lightning/rpc/benchmark/RequestObjectSerializer.java b/lightningrpc-benchmark/src/main/java/info/minzhou/lightning/rpc/benchmark/RequestObjectSerializer.java similarity index 100% rename from lightningrpc-common/src/main/java/info/minzhou/lightning/rpc/benchmark/RequestObjectSerializer.java rename to lightningrpc-benchmark/src/main/java/info/minzhou/lightning/rpc/benchmark/RequestObjectSerializer.java diff --git a/lightningrpc-common/src/main/java/info/minzhou/lightning/rpc/benchmark/ResponseObject.java b/lightningrpc-benchmark/src/main/java/info/minzhou/lightning/rpc/benchmark/ResponseObject.java similarity index 100% rename from lightningrpc-common/src/main/java/info/minzhou/lightning/rpc/benchmark/ResponseObject.java rename to lightningrpc-benchmark/src/main/java/info/minzhou/lightning/rpc/benchmark/ResponseObject.java diff --git a/lightningrpc-common/src/main/java/info/minzhou/lightning/rpc/benchmark/ResponseObjectSerializer.java b/lightningrpc-benchmark/src/main/java/info/minzhou/lightning/rpc/benchmark/ResponseObjectSerializer.java similarity index 100% rename from lightningrpc-common/src/main/java/info/minzhou/lightning/rpc/benchmark/ResponseObjectSerializer.java rename to lightningrpc-benchmark/src/main/java/info/minzhou/lightning/rpc/benchmark/ResponseObjectSerializer.java diff --git a/lightningrpc-common/src/main/java/info/minzhou/lightning/rpc/benchmark/SimpleProcessorBenchmarkClientRunnable.java b/lightningrpc-benchmark/src/main/java/info/minzhou/lightning/rpc/benchmark/SimpleProcessorBenchmarkClientRunnable.java similarity index 100% rename from lightningrpc-common/src/main/java/info/minzhou/lightning/rpc/benchmark/SimpleProcessorBenchmarkClientRunnable.java rename to lightningrpc-benchmark/src/main/java/info/minzhou/lightning/rpc/benchmark/SimpleProcessorBenchmarkClientRunnable.java diff --git a/lightningrpc-netty/src/main/java/info/minzhou/lightning/rpc/netty/benchmark/NettyBenchmarkServer.java b/lightningrpc-benchmark/src/main/java/info/minzhou/lightning/rpc/benchmark/netty/NettyBenchmarkServer.java similarity index 86% rename from lightningrpc-netty/src/main/java/info/minzhou/lightning/rpc/netty/benchmark/NettyBenchmarkServer.java rename to lightningrpc-benchmark/src/main/java/info/minzhou/lightning/rpc/benchmark/netty/NettyBenchmarkServer.java index 82b43d7..9c45b58 100644 --- a/lightningrpc-netty/src/main/java/info/minzhou/lightning/rpc/netty/benchmark/NettyBenchmarkServer.java +++ b/lightningrpc-benchmark/src/main/java/info/minzhou/lightning/rpc/benchmark/netty/NettyBenchmarkServer.java @@ -1,4 +1,4 @@ -package info.minzhou.lightning.rpc.netty.benchmark; +package info.minzhou.lightning.rpc.benchmark.netty; import info.minzhou.lightning.rpc.benchmark.AbstractBenchmarkServer; diff --git a/lightningrpc-netty/src/main/java/info/minzhou/lightning/rpc/netty/benchmark/NettyRPCBenchmarkClient.java b/lightningrpc-benchmark/src/main/java/info/minzhou/lightning/rpc/benchmark/netty/NettyRPCBenchmarkClient.java similarity index 92% rename from lightningrpc-netty/src/main/java/info/minzhou/lightning/rpc/netty/benchmark/NettyRPCBenchmarkClient.java rename to lightningrpc-benchmark/src/main/java/info/minzhou/lightning/rpc/benchmark/netty/NettyRPCBenchmarkClient.java index 54781ae..383e5de 100644 --- a/lightningrpc-netty/src/main/java/info/minzhou/lightning/rpc/netty/benchmark/NettyRPCBenchmarkClient.java +++ b/lightningrpc-benchmark/src/main/java/info/minzhou/lightning/rpc/benchmark/netty/NettyRPCBenchmarkClient.java @@ -1,4 +1,4 @@ -package info.minzhou.lightning.rpc.netty.benchmark; +package info.minzhou.lightning.rpc.benchmark.netty; import info.minzhou.lightning.rpc.benchmark.AbstractRPCBenchmarkClient; diff --git a/lightningrpc-netty/src/main/java/info/minzhou/lightning/rpc/netty/benchmark/NettySimpleBenchmarkClient.java b/lightningrpc-benchmark/src/main/java/info/minzhou/lightning/rpc/benchmark/netty/NettySimpleBenchmarkClient.java similarity index 88% rename from lightningrpc-netty/src/main/java/info/minzhou/lightning/rpc/netty/benchmark/NettySimpleBenchmarkClient.java rename to lightningrpc-benchmark/src/main/java/info/minzhou/lightning/rpc/benchmark/netty/NettySimpleBenchmarkClient.java index 80d1d54..7697be3 100644 --- a/lightningrpc-netty/src/main/java/info/minzhou/lightning/rpc/netty/benchmark/NettySimpleBenchmarkClient.java +++ b/lightningrpc-benchmark/src/main/java/info/minzhou/lightning/rpc/benchmark/netty/NettySimpleBenchmarkClient.java @@ -1,4 +1,4 @@ -package info.minzhou.lightning.rpc.netty.benchmark; +package info.minzhou.lightning.rpc.benchmark.netty; import info.minzhou.lightning.rpc.benchmark.AbstractSimpleProcessorBenchmarkClient; diff --git a/lightningrpc-common/src/main/java/info/minzhou/lightning/rpc/protocol/KryoDecoder.java b/lightningrpc-common/src/main/java/info/minzhou/lightning/rpc/protocol/KryoDecoder.java index fc2abd7..db7d865 100644 --- a/lightningrpc-common/src/main/java/info/minzhou/lightning/rpc/protocol/KryoDecoder.java +++ b/lightningrpc-common/src/main/java/info/minzhou/lightning/rpc/protocol/KryoDecoder.java @@ -1,7 +1,5 @@ package info.minzhou.lightning.rpc.protocol; -import info.minzhou.lightning.rpc.benchmark.KryoUtils; - import com.esotericsoftware.kryo.io.Input; /** diff --git a/lightningrpc-common/src/main/java/info/minzhou/lightning/rpc/protocol/KryoEncoder.java b/lightningrpc-common/src/main/java/info/minzhou/lightning/rpc/protocol/KryoEncoder.java index 220676c..f8d8ead 100644 --- a/lightningrpc-common/src/main/java/info/minzhou/lightning/rpc/protocol/KryoEncoder.java +++ b/lightningrpc-common/src/main/java/info/minzhou/lightning/rpc/protocol/KryoEncoder.java @@ -1,7 +1,5 @@ package info.minzhou.lightning.rpc.protocol; -import info.minzhou.lightning.rpc.benchmark.KryoUtils; - import com.esotericsoftware.kryo.io.Output; /** diff --git a/lightningrpc-common/src/main/java/info/minzhou/lightning/rpc/benchmark/KryoUtils.java b/lightningrpc-common/src/main/java/info/minzhou/lightning/rpc/protocol/KryoUtils.java similarity index 92% rename from lightningrpc-common/src/main/java/info/minzhou/lightning/rpc/benchmark/KryoUtils.java rename to lightningrpc-common/src/main/java/info/minzhou/lightning/rpc/protocol/KryoUtils.java index ea01220..cfd5995 100644 --- a/lightningrpc-common/src/main/java/info/minzhou/lightning/rpc/benchmark/KryoUtils.java +++ b/lightningrpc-common/src/main/java/info/minzhou/lightning/rpc/protocol/KryoUtils.java @@ -1,11 +1,11 @@ -package info.minzhou.lightning.rpc.benchmark; - -import java.util.ArrayList; -import java.util.List; +package info.minzhou.lightning.rpc.protocol; import com.esotericsoftware.kryo.Kryo; import com.esotericsoftware.kryo.Serializer; +import java.util.ArrayList; +import java.util.List; + /** * Kryo Utils * diff --git a/lightningrpc-common/src/main/java/info/minzhou/lightning/rpc/server/RPCJava7ServerHandler.java.txt b/lightningrpc-common/src/main/java/info/minzhou/lightning/rpc/server/RPCJava7ServerHandler.java.txt deleted file mode 100644 index 74591d2..0000000 --- a/lightningrpc-common/src/main/java/info/minzhou/lightning/rpc/server/RPCJava7ServerHandler.java.txt +++ /dev/null @@ -1,108 +0,0 @@ -package com.bluedavy.rpc.server; -/** - * nfs-rpc - * Apache License - * - - */ -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.invoke.MethodType; -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import com.bluedavy.rpc.Coders; -import com.bluedavy.rpc.RequestWrapper; -import com.bluedavy.rpc.ResponseWrapper; -/** - * MethodHandle RPC Server Handler - * - * @author bluedavy - */ -public class RPCJava7ServerHandler implements ServerHandler { - - // Server Processors key: servicename value: service instance - private static Map processors = new HashMap(); - - // Cached Server Methods key: instanceName#methodname$argtype_argtype - private static Map cachedMethodHandles = new HashMap(); - - /* (non-Javadoc) - * @see com.bluedavy.rpc.ServerHandler#registerProcessor(java.lang.String, java.lang.Object) - */ - @Override - public void registerProcessor(String instanceName,Object instance){ - processors.put(instanceName, instance); - Class instanceClass = instance.getClass(); - Method[] methods = instanceClass.getMethods(); - for (Method method : methods) { - Class[] argTypes = method.getParameterTypes(); - StringBuilder methodKeyBuilder = new StringBuilder(); - methodKeyBuilder.append(instanceName).append("#"); - methodKeyBuilder.append(method.getName()).append("$"); - for (Class argClass : argTypes) { - methodKeyBuilder.append(argClass.getName()).append("_"); - } - MethodType methodType = MethodType.methodType(method.getReturnType(), argTypes); - try{ - MethodHandle methodHandle = MethodHandles.lookup().findVirtual(instance.getClass(), method.getName(), methodType); - cachedMethodHandles.put(methodKeyBuilder.toString(), methodHandle); - } - catch(Exception e){ - e.printStackTrace(); - } - } - } - - /* (non-Javadoc) - * @see com.bluedavy.rpc.ServerHandler#handleRequest(com.bluedavy.rpc.RequestWrapper) - */ - @Override - public ResponseWrapper handleRequest(final RequestWrapper request){ - ResponseWrapper responseWrapper = new ResponseWrapper(); - responseWrapper.setRequestId(request.getId()); - responseWrapper.setDataType(request.getDataType()); - String targetInstanceName = request.getTargetInstanceName(); - String methodName = request.getMethodName(); - String[] argTypes = request.getArgTypes(); - List requestObjects = null; - MethodHandle method = null; - try{ - Object processor = processors.get(targetInstanceName); - requestObjects = new ArrayList(argTypes.length+1); - requestObjects.add(processor); - if(processor == null){ - throw new Exception("no "+targetInstanceName+" instance exists on the server"); - } - if (argTypes != null && argTypes.length > 0) { - StringBuilder methodKeyBuilder = new StringBuilder(); - methodKeyBuilder.append(targetInstanceName).append("#"); - methodKeyBuilder.append(methodName).append("$"); - Class[] argTypeClasses = new Class[argTypes.length]; - for (int i = 0; i < argTypes.length; i++) { - methodKeyBuilder.append(argTypes[i]).append("_"); - argTypeClasses[i] = Class.forName(argTypes[i]); - } - String key = methodKeyBuilder.toString(); - method = cachedMethodHandles.get(key); - - Object[] tmprequestObjects = request.getRequestObjects(); - for (int i = 0; i < tmprequestObjects.length; i++) { - requestObjects.add(Coders.getDecoder(String.valueOf(request.getDataType())).decode((byte[])tmprequestObjects[i])); - } - } - else { - MethodType methodType = MethodType.methodType(Object.class, new Class[]{}); - method = MethodHandles.lookup().findVirtual(processor.getClass(), methodName, methodType); - } - responseWrapper.setResponse(method.invokeWithArguments(requestObjects)); - } - catch(Throwable e){ - responseWrapper.setException(e); - } - return responseWrapper; - } -} diff --git a/lightningrpc-netty/src/main/resources/log4j.properties b/lightningrpc-netty/src/main/resources/log4j.properties deleted file mode 100644 index f6968a9..0000000 --- a/lightningrpc-netty/src/main/resources/log4j.properties +++ /dev/null @@ -1,15 +0,0 @@ -log4j.rootLogger=DEBUG,NFSNETTY -log4j.threshhold=ALL - -log4j.appender.NFSNETTY=org.apache.log4j.DailyRollingFileAppender -log4j.appender.NFSNETTY.File=nfs.netty.log -log4j.appender.NFSNETTY.DatePattern=.yyyy-MM-dd -log4j.appender.NFSNETTY.layout=org.apache.log4j.PatternLayout -log4j.appender.NFSNETTY.layout.ConversionPattern=%d{ISO8601} %p %c: %m%n - -log4j.appender.console=org.apache.log4j.ConsoleAppender -log4j.appender.console.target=System.err -log4j.appender.console.layout=org.apache.log4j.PatternLayout -log4j.appender.console.layout.ConversionPattern=%d{yy/MM/dd HH:mm:ss} %p %c{2}: %m%n - -log4j.logger.code.google.nfs.rpc=INFO diff --git a/settings.gradle b/settings.gradle index 2c8d0df..105dbc6 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,2 +1,2 @@ rootProject.name='lightningrpc' -include 'lightningrpc-common', 'lightningrpc-netty' +include 'lightningrpc-common', 'lightningrpc-netty', 'lightningrpc-benchmark'