This is an automated email from the ASF dual-hosted git repository. yukon pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/rocketmq-remoting.git
commit 7e5d24e74b8e6a1e6d5889dd8ecf10d788ab9b0d Author: yukon <[email protected]> AuthorDate: Fri May 17 20:27:52 2019 +0800 Add benchmark module --- benchmarks/remoting-benchmark/pom.xml | 25 +++++++ .../benchmarks/remoting/AbstractBenchmark.java | 78 ++++++++++++++++++++++ pom.xml | 6 ++ 3 files changed, 109 insertions(+) diff --git a/benchmarks/remoting-benchmark/pom.xml b/benchmarks/remoting-benchmark/pom.xml new file mode 100644 index 0000000..e103ae8 --- /dev/null +++ b/benchmarks/remoting-benchmark/pom.xml @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="UTF-8"?> +<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"> + <parent> + <artifactId>rocketmq-x</artifactId> + <groupId>org.apache.rocketmq</groupId> + <version>0.1.0-SNAPSHOT</version> + <relativePath>../../pom.xml</relativePath> + </parent> + <modelVersion>4.0.0</modelVersion> + + <artifactId>remoting-benchmark</artifactId> + <dependencies> + <dependency> + <groupId>${project.groupId}</groupId> + <artifactId>remoting-impl</artifactId> + </dependency> + <dependency> + <groupId>ch.qos.logback</groupId> + <artifactId>logback-classic</artifactId> + </dependency> + </dependencies> + +</project> \ No newline at end of file diff --git a/benchmarks/remoting-benchmark/src/main/java/org/apache/rocketmq/benchmarks/remoting/AbstractBenchmark.java b/benchmarks/remoting-benchmark/src/main/java/org/apache/rocketmq/benchmarks/remoting/AbstractBenchmark.java new file mode 100644 index 0000000..b3754e9 --- /dev/null +++ b/benchmarks/remoting-benchmark/src/main/java/org/apache/rocketmq/benchmarks/remoting/AbstractBenchmark.java @@ -0,0 +1,78 @@ +/* + * 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. + */ + +package org.apache.rocketmq.benchmarks.remoting; + +import org.apache.rocketmq.remoting.RemotingBootstrapFactory; +import org.apache.rocketmq.remoting.api.RemotingClient; +import org.apache.rocketmq.remoting.api.RemotingServer; +import org.apache.rocketmq.remoting.api.command.RemotingCommand; +import org.apache.rocketmq.remoting.config.RemotingConfig; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class AbstractBenchmark { + protected static final Logger LOG = LoggerFactory.getLogger(AbstractBenchmark.class); + + /** + * Standard message sizes. + */ + public enum MessageSize { + SMALL(16), MEDIUM(1024), LARGE(65536), JUMBO(1048576); + + private final int bytes; + MessageSize(int bytes) { + this.bytes = bytes; + } + + public int bytes() { + return bytes; + } + } + + /** + * Support channel types. + */ + public enum ChannelType { + NIO, LOCAL; + } + + public static void main(String[] args) throws InterruptedException { + RemotingServer server = RemotingBootstrapFactory.createRemotingServer(new RemotingConfig()); + + server.registerRequestProcessor((short) 1, (channel, request) -> { + RemotingCommand response = server.commandFactory().createResponse(request); + response.payload("zhouxinyu".getBytes()); + System.out.println(new String(request.payload())); + return response; + }); + server.start(); + + RemotingClient client = RemotingBootstrapFactory.createRemotingClient(new RemotingConfig()); + client.start(); + + RemotingCommand request = client.commandFactory().createRequest(); + request.cmdCode((short) 1); + request.cmdVersion((short) 1); + request.payload("hello".getBytes()); + RemotingCommand response = client.invoke("127.0.0.1:8888", request, 3000); + System.out.println(new String(response.payload())); + + client.stop(); + server.stop(); + } +} diff --git a/pom.xml b/pom.xml index 4995eca..2055a40 100644 --- a/pom.xml +++ b/pom.xml @@ -24,6 +24,7 @@ <modules> <module>remoting-core/remoting-api</module> <module>remoting-core/remoting-impl</module> + <module>benchmarks/remoting-benchmark</module> </modules> <dependencies> @@ -55,6 +56,11 @@ <version>${project.version}</version> </dependency> <dependency> + <groupId>${project.groupId}</groupId> + <artifactId>remoting-impl</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> <groupId>io.netty</groupId> <artifactId>netty-all</artifactId> <version>4.1.26.Final</version>
