Browse Source

add jmh test

pull/3/MERGE
CalvinKirs 4 years ago
parent
commit
0a92a53f63
  1. 4
      dolphinscheduler-microbench/pom.xml
  2. 31
      dolphinscheduler-microbench/src/main/java/org/apache/dolphinscheduler/microbench/common/IUserService.java
  3. 77
      dolphinscheduler-microbench/src/main/java/org/apache/dolphinscheduler/microbench/common/RpcTest.java
  4. 30
      dolphinscheduler-microbench/src/main/java/org/apache/dolphinscheduler/microbench/common/UserCallback.java
  5. 37
      dolphinscheduler-microbench/src/main/java/org/apache/dolphinscheduler/microbench/common/UserService.java
  6. 28
      dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/remote/codec/NettyDecoder.java
  7. 5
      dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/rpc/config/ServiceBean.java
  8. 3
      dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/rpc/serializer/ProtoStuffSerializer.java
  9. 1
      dolphinscheduler-remote/src/test/java/org/apache/dolphinscheduler/rpc/RpcTest.java

4
dolphinscheduler-microbench/pom.xml

@ -61,6 +61,10 @@
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.dolphinscheduler</groupId>
<artifactId>dolphinscheduler-remote</artifactId>
</dependency>
</dependencies>

31
dolphinscheduler-microbench/src/main/java/org/apache/dolphinscheduler/microbench/common/IUserService.java

@ -0,0 +1,31 @@
/*
* 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.dolphinscheduler.microbench.common;
import org.apache.dolphinscheduler.rpc.base.Rpc;
/**
* IUserService
*/
public interface IUserService {
@Rpc(async = true, serviceCallback = UserCallback.class, retries = 9999)
Boolean say(String s);
Integer hi(int num);
}

77
dolphinscheduler-microbench/src/main/java/org/apache/dolphinscheduler/microbench/common/RpcTest.java

@ -0,0 +1,77 @@
/*
* 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.dolphinscheduler.microbench.common;
import org.apache.dolphinscheduler.microbench.base.AbstractBaseBenchmark;
import org.apache.dolphinscheduler.remote.config.NettyServerConfig;
import org.apache.dolphinscheduler.remote.utils.Host;
import org.apache.dolphinscheduler.rpc.client.IRpcClient;
import org.apache.dolphinscheduler.rpc.client.RpcClient;
import org.apache.dolphinscheduler.rpc.remote.NettyClient;
import org.apache.dolphinscheduler.rpc.remote.NettyServer;
import java.util.concurrent.TimeUnit;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Measurement;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.OutputTimeUnit;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.TearDown;
import org.openjdk.jmh.annotations.Warmup;
@Warmup(iterations = 5, time = 1)
@Measurement(iterations = 10, time = 1)
@State(Scope.Benchmark)
@BenchmarkMode({Mode.Throughput, Mode.AverageTime, Mode.SampleTime})
public class RpcTest extends AbstractBaseBenchmark {
private NettyServer nettyServer;
private IUserService userService;
private Host host;
private IRpcClient rpcClient = new RpcClient();
@Setup
public void before() throws Exception {
nettyServer = new NettyServer(new NettyServerConfig());
IRpcClient rpcClient = new RpcClient();
host = new Host("127.0.0.1", 12346);
userService = rpcClient.create(IUserService.class, host);
}
@Benchmark
@BenchmarkMode({Mode.Throughput, Mode.AverageTime, Mode.SampleTime})
@OutputTimeUnit(TimeUnit.MILLISECONDS)
public void sendTest() throws Exception {
userService = rpcClient.create(IUserService.class, host);
Integer result = userService.hi(1);
}
@TearDown
public void after() {
NettyClient.getInstance().close();
nettyServer.close();
}
}

30
dolphinscheduler-microbench/src/main/java/org/apache/dolphinscheduler/microbench/common/UserCallback.java

@ -0,0 +1,30 @@
/*
* 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.dolphinscheduler.microbench.common;
import org.apache.dolphinscheduler.rpc.common.AbstractRpcCallBack;
/**
* UserCallback
*/
public class UserCallback extends AbstractRpcCallBack {
@Override
public void run(Object object) {
}
}

37
dolphinscheduler-microbench/src/main/java/org/apache/dolphinscheduler/microbench/common/UserService.java

@ -0,0 +1,37 @@
/*
* 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.dolphinscheduler.microbench.common;
import org.apache.dolphinscheduler.rpc.base.RpcService;
/**
* UserService
*/
@RpcService("IUserService")
public class UserService implements IUserService {
@Override
public Boolean say(String s) {
return true;
}
@Override
public Integer hi(int num) {
return ++num;
}
}

28
dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/remote/codec/NettyDecoder.java

@ -17,18 +17,19 @@
package org.apache.dolphinscheduler.remote.codec;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ReplayingDecoder;
import org.apache.dolphinscheduler.remote.command.Command;
import org.apache.dolphinscheduler.remote.command.CommandContext;
import org.apache.dolphinscheduler.remote.command.CommandHeader;
import org.apache.dolphinscheduler.remote.command.CommandType;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ReplayingDecoder;
/**
* netty decoder
@ -36,7 +37,7 @@ import java.util.List;
public class NettyDecoder extends ReplayingDecoder<NettyDecoder.State> {
private static final Logger logger = LoggerFactory.getLogger(NettyDecoder.class);
public NettyDecoder(){
public NettyDecoder() {
super(State.MAGIC);
}
@ -48,11 +49,10 @@ public class NettyDecoder extends ReplayingDecoder<NettyDecoder.State> {
* @param ctx channel handler context
* @param in byte buffer
* @param out out content
* @throws Exception
*/
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
switch (state()){
switch (state()) {
case MAGIC:
checkMagic(in.readByte());
checkpoint(State.VERSION);
@ -103,12 +103,12 @@ public class NettyDecoder extends ReplayingDecoder<NettyDecoder.State> {
/**
* get command type
*
* @param type type
* @return
*/
private CommandType commandType(byte type){
for(CommandType ct : CommandType.values()){
if(ct.ordinal() == type){
private CommandType commandType(byte type) {
for (CommandType ct : CommandType.values()) {
if (ct.ordinal() == type) {
return ct;
}
}
@ -117,6 +117,7 @@ public class NettyDecoder extends ReplayingDecoder<NettyDecoder.State> {
/**
* check magic
*
* @param magic magic
*/
private void checkMagic(byte magic) {
@ -127,7 +128,6 @@ public class NettyDecoder extends ReplayingDecoder<NettyDecoder.State> {
/**
* check version
* @param version
*/
private void checkVersion(byte version) {
if (version != Command.VERSION) {
@ -135,7 +135,7 @@ public class NettyDecoder extends ReplayingDecoder<NettyDecoder.State> {
}
}
enum State{
enum State {
MAGIC,
VERSION,
COMMAND,

5
dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/rpc/config/ServiceBean.java

@ -46,7 +46,10 @@ public class ServiceBean {
private static synchronized void init() {
// todo config
Reflections f = new Reflections("org/apache/dolphinscheduler/rpc");
if(initialized.get()){
return;
}
Reflections f = new Reflections("org/apache/dolphinscheduler/");
List<Class<?>> list = new ArrayList<>(f.getTypesAnnotatedWith(RpcService.class));
list.forEach(rpcClass -> {
RpcService rpcService = rpcClass.getAnnotation(RpcService.class);

3
dolphinscheduler-remote/src/main/java/org/apache/dolphinscheduler/rpc/serializer/ProtoStuffSerializer.java

@ -24,13 +24,12 @@ import io.protostuff.ProtostuffIOUtil;
import io.protostuff.Schema;
import io.protostuff.runtime.RuntimeSchema;
public class ProtoStuffSerializer implements Serializer{
public class ProtoStuffSerializer implements Serializer {
private static LinkedBuffer buffer = LinkedBuffer.allocate(LinkedBuffer.DEFAULT_BUFFER_SIZE);
private static Map<Class<?>, Schema<?>> schemaCache = new ConcurrentHashMap<>();
@SuppressWarnings("unchecked")
private static <T> Schema<T> getSchema(Class<T> clazz) {
return (Schema<T>) schemaCache.computeIfAbsent(clazz, RuntimeSchema::createFrom);

1
dolphinscheduler-remote/src/test/java/org/apache/dolphinscheduler/rpc/RpcTest.java

@ -42,7 +42,6 @@ public class RpcTest {
IRpcClient rpcClient = new RpcClient();
host = new Host("127.0.0.1", 12346);
userService = rpcClient.create(IUserService.class, host);
}
@Test

Loading…
Cancel
Save