Search in sources :

Example 1 with ProtoService

use of com.alipay.sofa.rpc.protobuf.ProtoService in project sofa-rpc by sofastack.

the class Http2ClientMultipleMain method main.

public static void main(String[] args) {
    ApplicationConfig application = new ApplicationConfig().setAppName("test-client");
    ConsumerConfig<ProtoService> consumerConfig = new ConsumerConfig<ProtoService>().setApplication(application).setInterfaceId(ProtoService.class.getName()).setProtocol("h2c").setDirectUrl("h2c://127.0.0.1:12300").setSerialization("protobuf").setTimeout(3000);
    final ProtoService protoService = consumerConfig.refer();
    LOGGER.warn("started at pid {}", RpcRuntimeContext.PID);
    final int threads = 50;
    final AtomicLong cnt = new AtomicLong(0);
    final ThreadPoolExecutor service1 = new ThreadPoolExecutor(threads, threads, 0L, TimeUnit.MILLISECONDS, new SynchronousQueue<Runnable>(), // 无队列
    new NamedThreadFactory("client-"));
    for (int i = 0; i < threads; i++) {
        service1.execute(new Runnable() {

            @Override
            public void run() {
                while (true) {
                    try {
                        EchoRequest request = EchoRequest.newBuilder().setGroup(Group.A).setName("12345678").build();
                        EchoResponse s = protoService.echoObj(request);
                        cnt.incrementAndGet();
                    } catch (Throwable e) {
                        LOGGER.error("", e);
                    }
                }
            }
        });
    }
    Thread thread = new Thread(new Runnable() {

        private long last = 0;

        @Override
        public void run() {
            while (true) {
                long count = cnt.get();
                long tps = count - last;
                LOGGER.error("last 1s invoke: {}, queue: {}", tps, service1.getQueue().size());
                last = count;
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                }
            }
        }
    }, "Print-tps-THREAD");
    thread.start();
}
Also used : EchoResponse(com.alipay.sofa.rpc.protobuf.EchoResponse) NamedThreadFactory(com.alipay.sofa.rpc.common.struct.NamedThreadFactory) EchoRequest(com.alipay.sofa.rpc.protobuf.EchoRequest) AtomicLong(java.util.concurrent.atomic.AtomicLong) ApplicationConfig(com.alipay.sofa.rpc.config.ApplicationConfig) ProtoService(com.alipay.sofa.rpc.protobuf.ProtoService) ConsumerConfig(com.alipay.sofa.rpc.config.ConsumerConfig) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor)

Example 2 with ProtoService

use of com.alipay.sofa.rpc.protobuf.ProtoService in project sofa-rpc by sofastack.

the class Http2WithSSLClientMain method main.

public static void main(String[] args) {
    System.setProperty("ssl", "true");
    System.setProperty("io.netty.handler.ssl.noOpenSsl", "false");
    String codebase = ReflectUtils.getCodeBase(Http2WithSSLClientMain.class);
    System.setProperty(RpcConfigKeys.CERTIFICATE_PATH.getAlias()[0], codebase + "selfSigned.crt");
    ApplicationConfig application = new ApplicationConfig().setAppName("test-client");
    ConsumerConfig<ProtoService> consumerConfig = new ConsumerConfig<ProtoService>().setApplication(application).setInterfaceId(ProtoService.class.getName()).setProtocol("h2").setDirectUrl("h2://127.0.0.1:12300").setSerialization("protobuf").setRegister(false).setTimeout(1000);
    ProtoService helloService = consumerConfig.refer();
    LOGGER.warn("started at pid {}", RpcRuntimeContext.PID);
    while (true) {
        try {
            EchoRequest request = EchoRequest.newBuilder().setGroup(Group.A).setName("lee").build();
            EchoResponse s = helloService.echoObj(request);
            LOGGER.warn("{}", s);
        } catch (Exception e) {
            LOGGER.error(e.getMessage(), e);
        }
        try {
            Thread.sleep(2000);
        } catch (Exception e) {
        }
    }
}
Also used : EchoResponse(com.alipay.sofa.rpc.protobuf.EchoResponse) ApplicationConfig(com.alipay.sofa.rpc.config.ApplicationConfig) EchoRequest(com.alipay.sofa.rpc.protobuf.EchoRequest) ProtoService(com.alipay.sofa.rpc.protobuf.ProtoService)

Example 3 with ProtoService

use of com.alipay.sofa.rpc.protobuf.ProtoService in project sofa-rpc by sofastack.

the class Http2ClientMain method main.

public static void main(String[] args) {
    ApplicationConfig application = new ApplicationConfig().setAppName("test-client");
    ConsumerConfig<ProtoService> consumerConfig = new ConsumerConfig<ProtoService>().setApplication(application).setInterfaceId(ProtoService.class.getName()).setProtocol("h2c").setDirectUrl("h2c://127.0.0.1:12300").setSerialization("protobuf").setRegister(false).setTimeout(1000);
    ProtoService helloService = consumerConfig.refer();
    LOGGER.warn("started at pid {}", RpcRuntimeContext.PID);
    while (true) {
        try {
            EchoRequest request = EchoRequest.newBuilder().setGroup(Group.A).setName("xxx").build();
            EchoResponse s = helloService.echoObj(request);
            LOGGER.warn("{}", s);
        } catch (Exception e) {
            LOGGER.error(e.getMessage(), e);
        }
        try {
            Thread.sleep(2000);
        } catch (Exception e) {
        }
    }
}
Also used : EchoResponse(com.alipay.sofa.rpc.protobuf.EchoResponse) ApplicationConfig(com.alipay.sofa.rpc.config.ApplicationConfig) EchoRequest(com.alipay.sofa.rpc.protobuf.EchoRequest) ProtoService(com.alipay.sofa.rpc.protobuf.ProtoService)

Example 4 with ProtoService

use of com.alipay.sofa.rpc.protobuf.ProtoService in project sofa-rpc by sofastack.

the class Http2ServerMain method main.

public static void main(String[] args) {
    ApplicationConfig application = new ApplicationConfig().setAppName("test-server");
    ServerConfig serverConfig = new ServerConfig().setProtocol("h2c").setPort(12300).setDaemon(false);
    ProviderConfig<ProtoService> providerConfig = new ProviderConfig<ProtoService>().setInterfaceId(ProtoService.class.getName()).setApplication(application).setRef(new ProtoServiceImpl()).setServer(serverConfig);
    providerConfig.export();
    ProviderConfig<HelloService> providerConfig2 = new ProviderConfig<HelloService>().setInterfaceId(HelloService.class.getName()).setApplication(application).setRef(new HelloServiceImpl()).setServer(serverConfig).setRegister(false);
    providerConfig2.export();
    // http://127.0.0.1:12300/com.alipay.sofa.rpc.test.HelloService/sayHello
    LOGGER.error("started at pid {}", RpcRuntimeContext.PID);
    final AtomicInteger cnt = ((ProtoServiceImpl) providerConfig.getRef()).getCounter();
    final ThreadPoolExecutor executor = ((Http2ClearTextServer) serverConfig.getServer()).getBizThreadPool();
    Thread thread = new Thread(new Runnable() {

        private long last = 0;

        @Override
        public void run() {
            while (true) {
                long count = cnt.get();
                long tps = count - last;
                LOGGER.error("last 1s invoke: {}, queue: {}", tps, executor.getQueue().size());
                last = count;
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                }
            }
        }
    }, "Print-tps-THREAD");
    thread.start();
}
Also used : ProtoServiceImpl(com.alipay.sofa.rpc.protobuf.ProtoServiceImpl) ProviderConfig(com.alipay.sofa.rpc.config.ProviderConfig) HelloService(com.alipay.sofa.rpc.test.HelloService) HelloServiceImpl(com.alipay.sofa.rpc.test.HelloServiceImpl) Http2ClearTextServer(com.alipay.sofa.rpc.server.http.Http2ClearTextServer) ServerConfig(com.alipay.sofa.rpc.config.ServerConfig) ApplicationConfig(com.alipay.sofa.rpc.config.ApplicationConfig) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ProtoService(com.alipay.sofa.rpc.protobuf.ProtoService) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor)

Example 5 with ProtoService

use of com.alipay.sofa.rpc.protobuf.ProtoService in project sofa-rpc by sofastack.

the class Http2WithSSLServerMain method main.

public static void main(String[] args) {
    System.setProperty("ssl", "true");
    System.setProperty("io.netty.handler.ssl.noOpenSsl", "false");
    String codebase = ReflectUtils.getCodeBase(Http2WithSSLServerMain.class);
    System.setProperty(RpcConfigKeys.CERTIFICATE_PATH.getAlias()[0], codebase + "selfSigned.crt");
    System.setProperty(RpcConfigKeys.PRIVATE_KEY_PATH.getAlias()[0], codebase + "privatekey.key");
    ApplicationConfig application = new ApplicationConfig().setAppName("test-server");
    ServerConfig serverConfig = new ServerConfig().setProtocol("h2").setPort(12300).setDaemon(false);
    ProviderConfig<ProtoService> providerConfig = new ProviderConfig<ProtoService>().setInterfaceId(ProtoService.class.getName()).setApplication(application).setRef(new ProtoServiceImpl()).setServer(serverConfig);
    providerConfig.export();
    ProviderConfig<HelloService> providerConfig2 = new ProviderConfig<HelloService>().setInterfaceId(HelloService.class.getName()).setApplication(application).setRef(new HelloServiceImpl()).setServer(serverConfig).setRegister(false);
    providerConfig2.export();
    // http://127.0.0.1:12300/com.alipay.sofa.rpc.test.HelloService/sayHello
    LOGGER.error("started at pid {}", RpcRuntimeContext.PID);
    final AtomicInteger cnt = ((ProtoServiceImpl) providerConfig.getRef()).getCounter();
    final ThreadPoolExecutor executor = ((Http2WithSSLServer) serverConfig.getServer()).getBizThreadPool();
    Thread thread = new Thread(new Runnable() {

        private long last = 0;

        @Override
        public void run() {
            while (true) {
                long count = cnt.get();
                long tps = count - last;
                LOGGER.error("last 10s invoke: {}, queue: {}", tps, executor.getQueue().size());
                last = count;
                try {
                    Thread.sleep(10000);
                } catch (InterruptedException e) {
                }
            }
        }
    }, "Print-tps-THREAD");
    thread.start();
}
Also used : ProtoServiceImpl(com.alipay.sofa.rpc.protobuf.ProtoServiceImpl) ProviderConfig(com.alipay.sofa.rpc.config.ProviderConfig) HelloService(com.alipay.sofa.rpc.test.HelloService) HelloServiceImpl(com.alipay.sofa.rpc.test.HelloServiceImpl) Http2WithSSLServer(com.alipay.sofa.rpc.server.http.Http2WithSSLServer) ServerConfig(com.alipay.sofa.rpc.config.ServerConfig) ApplicationConfig(com.alipay.sofa.rpc.config.ApplicationConfig) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ProtoService(com.alipay.sofa.rpc.protobuf.ProtoService) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor)

Aggregations

ApplicationConfig (com.alipay.sofa.rpc.config.ApplicationConfig)5 ProtoService (com.alipay.sofa.rpc.protobuf.ProtoService)5 EchoRequest (com.alipay.sofa.rpc.protobuf.EchoRequest)3 EchoResponse (com.alipay.sofa.rpc.protobuf.EchoResponse)3 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)3 ProviderConfig (com.alipay.sofa.rpc.config.ProviderConfig)2 ServerConfig (com.alipay.sofa.rpc.config.ServerConfig)2 ProtoServiceImpl (com.alipay.sofa.rpc.protobuf.ProtoServiceImpl)2 HelloService (com.alipay.sofa.rpc.test.HelloService)2 HelloServiceImpl (com.alipay.sofa.rpc.test.HelloServiceImpl)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 NamedThreadFactory (com.alipay.sofa.rpc.common.struct.NamedThreadFactory)1 ConsumerConfig (com.alipay.sofa.rpc.config.ConsumerConfig)1 Http2ClearTextServer (com.alipay.sofa.rpc.server.http.Http2ClearTextServer)1 Http2WithSSLServer (com.alipay.sofa.rpc.server.http.Http2WithSSLServer)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1