Test Tengine Open Source Dubbo Function

Python WeChat Subscription Applet Course Video

https://edu.csdn.net/course/detail/36074

Python Actual Quantitative Transaction Finance System

https://edu.csdn.net/course/detail/35475

This article has been included https://github.com/lkxiaolou/lkxiaolou Welcome to star.
Search focuses on WeChat's public number "Insect Catcher Master", back-end technology sharing, architecture design, performance optimization, source code reading, problem investigation, and pit-stepping practice.

background

  • Tengine is an open source Web server developed by Alibaba based on Nginx. It inherits all the functions and features of Nginx and makes a lot of extensions and enhancements on it. The abilities such as dynamic module loading, four-layer load balancing, reuseport support and so on, are gradually absorbed and referenced by Nginx. Tengine has become a popular alternative to Nginx since it was opened, the official website. http://tengine.taobao.org/).
  • Dubbo is a high performance, lightweight, open source Java RPC framework from Alibaba Open Source that provides three core capabilities: Interface-oriented remote method calls, smart fault tolerance and load balancing, and automatic service registration and discovery.

In September 2019, Tengine 2.3.2 released dubbo_pass module, which supports the conversion of HTTP protocol to Dubbo protocol. The Release page is as follows:

https://github.com/alibaba/tengine/releases/tag/2.3.2

Significance

Gateway Technology Revolution - Tengine Open Source Dubbo Function The significance of Tengine's support for the Dubbo protocol is clear and summarized as follows:

  • Architecture optimization: Reduce one level of forwarding, reduce system complexity;
  • Performance Advantage: Given the data in this paper, "Tengine directly supports Dubbo's architecture in terms of CPU consumption and RT performance in different scenarios, with 28%-73% performance advantage"

actual measurement

Tengine Environment Setup

Here, I've built a Tengine environment with centos's basic mirror to illustrate the steps:

  • Enter the container and create a working directory
mkdir -p /home/roshi && cd /home/roshi/

  • Download the source code and unzip it
wget https://github.com/alibaba/tengine/archive/2.3.2.zip
unzip 2.3.2.zip && cd tengine-2.3.2/

wget https://ftp.pcre.org/pub/pcre/pcre-8.43.tar.gz
tar xvf pcre-8.43.tar.gz

wget https://www.openssl.org/source/openssl-1.0.2s.tar.gz
tar xvf openssl-1.0.2s.tar.gz

wget http://www.zlib.net/zlib-1.2.11.tar.gz
tar xvf zlib-1.2.11.tar.gz

  • Installation-related dependencies
yum install gcc
yum install gcc-c++
yum -y install gcc automake autoconf libtool make

  • Compile
./configure --add-module=./modules/mod_dubbo --add-module=./modules/ngx_multi_upstream_module --add-module=./modules/mod_config --with-pcre=./pcre-8.43/ --with-openssl=./openssl-1.0.2s/ --with-zlib=./zlib-1.2.11
make && make install

  • start-up
/usr/local/nginx/sbin/nginx

Dubbo example

Here's to mention that before dubbo Application Level Service Discovery First Experience The quick way to set up a Dubbo debugging environment mentioned in:

Due to Tengine limitations, the interface's out and in parameters must be Map, so the example needs to be modified:

  • DemoService
public interface DemoService {

    String sayHello(String name);

    default Map<String, Object> testTengine(Map<String, Object> args) {
        return null;
    }

    default CompletableFuture<String> sayHelloAsync(String name) {
        return CompletableFuture.completedFuture(sayHello(name));
    }
}

  • DemoServiceImpl.java
public class DemoServiceImpl implements DemoService {
    private static final Logger logger = LoggerFactory.getLogger(DemoServiceImpl.class);

    @Override
    public String sayHello(String name) {
        logger.info("Hello " + name + ", request from consumer: " + RpcContext.getContext().getRemoteAddress());
        return "Hello " + name + ", response from provider: " + RpcContext.getContext().getLocalAddress();
    }

    @Override
    public Map<String, Object> testTengine(Map<String, Object> args) {
        Map<String, Object> res = new HashMap<>();
        res.put("body", "hello tengine dubbo\n");
        res.put("status", "200");
        System.out.println("testTengine");
        return res;
    }

    @Override
    public CompletableFuture<String> sayHelloAsync(String name) {
        return null;
    }

}

To better test the case of multiple provider s, you can start multiple services on different ports with the same code.

Modify Tengine configuration

  • vi /usr/local/nginx/conf/nginx.conf
worker_processes  1;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;

    server {
        listen       8080;
        server_name  localhost;

        #pass the Dubbo to Dubbo Provider server listening on 127.0.0.1:20880
        location / {
            dubbo_pass_all_headers on;
            # dubbo\_pass\_set args $args;
            dubbo_pass_set args hello;
            dubbo_pass_set uri $uri;
            dubbo_pass_set method $request\_method;

            dubbo_pass org.apache.dubbo.demo.DemoService 0.0.0 testTengine dubbo_backend;
        }
    }


    #pass the Dubbo to Dubbo Provider server listening on 127.0.0.1:20880
    upstream dubbo_backend {
        multi 1;
        server host.docker.internal:20880;
        server host.docker.internal:20881;
    }
}

  • Modify reload configuration to take effect
/usr/local/nginx/sbin/nginx -s reload

test

Test with the following commands

curl -X POST http://127.0.0.1:8080/dubbo -i -d "hello=roshi"

Take a look at the data transfer

summary

After testing, the following points are summarized:

  • The input and output parameters of the interface are fixed to Map, otherwise an error will be reported
  • Using the body argument, the byte [] to the side of the Dubbo needs to be parsed
  • You can control the returned body and http status codes, where the returned body can be either String or byte[] type, and the status code is String type
  • Load Balancing Algorithm with Tengine Native
  • With troubleshooting, Tegine establishes a long connection with Dubbo Provider and removes when disconnected
  • Version, group grouping are not implemented, and version measurements in the document have no effect

Last

Just as Gateway Technology Revolution - Tengine Open Source Dubbo Function As mentioned in the article, Tengine has only completed the protocol support as Dubbo Consumer. Other functions such as service discovery, custom interface, service grouping, fault tolerance downgrade are not yet implemented, and are still a little away from production.

Last slot in the Tengine website documentation

Reference resources

Search focuses on WeChat's public number "Insect Catcher Master", back-end technology sharing, architecture design, performance optimization, source code reading, problem investigation, and pit-stepping practice.

Keywords: Python Java Back-end computer

Added by hannnndy on Thu, 24 Feb 2022 19:31:16 +0200