Soul source analysis (1) environment configuration

soul is a High-Performance Java API Gateway

GitHub:github.com/dromara/sou…

Official documentation: dromara.org/zh-cn/docs/…

1. Prepare the source code

1.1. The forkdromara/soulSource code to their own repositorycchenxi/soul

Clone the soul source code in your repository to local

git clone https://github.com/cchenxi/soul.git
Copy the code

1.3. Open the soul source code with IDEA

1.4. Compile the Soul source code

Execute the following maven command and wait for the compilation to complete

mvn clean package install -Dmaven.test.skip=true -Dmaven.javadoc.skip=true -Drat.skip=true -Dcheckstyle.skip=true
Copy the code

2. Startsoul

2.1. Startsoul-adminThe module

Soul-admin is the background management system of the soul gateway

Choose to use the MySQL database to store gateway data and modify the data source configuration to your own database configuration.

Run to start the class org. Dromara. Soul. Admin. SoulAdminBootstrap.

After the startup is successful, go to http://localhost:9095/ and go to the ↓ login page

Use the user name admin and password 123456 to log in.

2.2. Startsoul-bootstrapThe module

Soul-bootstrap is the core of the gateway system

Check the soul-Bootstrap configuration

You need to configure an IP and port for soul-admin

If the console displays the following information, soul-bootstrap is successfully started

The 2021-01-14 15:01:15. 17943-832 the INFO [the main] B.S.S.D.W.W ebsocketSyncDataConfiguration: you use websocket sync soul data....... The 2021-01-14 15:01:15. 17943-924 the INFO [the main] O.D.S.P.S.D.W.W ebsocketSyncDataService: websocket connection is successful..... The 2021-01-14 15:01:16. 17943-113 the INFO [main] O.S.B.A.E.W eb. EndpointLinksResolver: Exposing 2 endpoint(s) beneath base path '/actuator' log4j:WARN No appenders could be found for logger (com.alibaba.dubbo.common.logger.LoggerFactory). log4j:WARN Please initialize the log4j system properly. log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info. The 2021-01-14 15:01:17. 17943-150 the info [main] o.s.b.web.embedded.netty.NettyWebServer : Netty started on port(s): 9195 the 2021-01-14 15:01:17. 17943-154 the INFO [main] O.D.S.B.S oulBootstrapApplication: Started SoulBootstrapApplication in 5.508 seconds (JVM running for 6.762)Copy the code

3. Test HTTP request forwarding

For testing purposes, add the soul-Examples module to the SOUL POM

3.1. Start a service

Start the soul-examples-http project

Dependencies are introduced in the POM of soul-examples-HTTP

<dependency>
    <groupId>org.dromara</groupId>
    <artifactId>soul-spring-boot-starter-client-springmvc</artifactId>
    <version>${soul.version}</version>
</dependency>
Copy the code

Configure in application.yml

soul:
  http:
    adminUrl: http://localhost:9095
    port: 8188
    contextPath: /http
    appName: http
    full: false
Copy the code

If soul.http.full=false, the @SoulSpringMvcclient annotation needs to be configured on the specific HTTP interface

3.1.1. Test the HTTP service

Perform HTTP requests at http://localhost:8188/test/findByUserId? UserId =1 The following figure shows the result

3.1.2. Test gateway forwarding

Perform HTTP requests at http://localhost:9195/http/test/findByUserId? UserId =1 The following figure shows the result

Output the following information in the soul-Bootstrap console

The 2021-01-14 20:42:57. 29812-123 the INFO [work - threads - 11] O.D.S oul. Plugin. Base. AbstractSoulPlugin: divide selector success match , The selector name: / HTTP 2021-01-14 20:42:57. 29812-125 the INFO/work - threads - 11 O.D.S oul. Plugin. Base. AbstractSoulPlugin: divide selector success match , Selector name :/ HTTP /test/** 2021-01-14 20:42:57.126 INFO 29812 -- [work-threads-11] selector name :/ HTTP /test/** 2021-01-14 20:42:57.126 INFO 29812 -- [work-threads-11] O.D.S.P lugin. Httpclient. WebClientPlugin: The request urlPath is http://172.27.121.155:8188/test/findByUserId? userId=1, retryTimes is 0Copy the code

You can observe that the gateway can forward the request normally.

3.2. Start two services to simulate load balancing

Select Allow Parallel Run, change port to 8189, and start the soul-examples-HTTP project again

3.2.1. Test the HTTP service

Perform HTTP requests at http://localhost:8189/test/findByUserId? UserId =1 The following figure shows the result

3.2.2. Test load balancing

Configure the services for ports 8188 and 8189 into the selector

Many times to perform HTTP requests at http://localhost:9195/http/test/findByUserId? UserId =1 The following figure shows the result

Output the following information in the soul-Bootstrap console

The 2021-01-14 20:48:34. 29812-460 the INFO [21] work - threads - O.D.S oul. Plugin. Base. AbstractSoulPlugin: divide selector success match , The selector name: / HTTP 2021-01-14 20:48:34. 460 INFO - 29812 [21] work - threads - O.D.S oul. Plugin. Base. AbstractSoulPlugin: divide selector success match , Selector Name :/ HTTP /test/** 2021-01-14 20:48:34.460 INFO 29812 -- [work-threads-21] O.D.S.P lugin. Httpclient. WebClientPlugin: The request urlPath is http://172.27.121.155:8189/test/findByUserId? userId=1, RetryTimes is 0 2021-01-14 20:48:35. 29812-147 the INFO/work - threads - 22 O.D.S oul. Plugin. Base. AbstractSoulPlugin: divide selector success match , The selector name: / HTTP 2021-01-14 20:48:35. 29812-147 the INFO/work - threads - 22 O.D.S oul. Plugin. Base. AbstractSoulPlugin: divide selector success match , Selector Name :/ HTTP /test/** 2021-01-14 20:48:35.147 INFO 29812 -- [work-threads-22] selector Name :/ HTTP /test/** 2021-01-14 20:48:35.147 INFO 29812 -- [work-threads-22] O.D.S.P lugin. Httpclient. WebClientPlugin: The request urlPath is http://172.27.121.155:8188/test/findByUserId? userId=1, RetryTimes is 0 2021-01-14 20:48:38. 29812-755 the INFO/work - threads - 23 O.D.S oul. Plugin. Base. AbstractSoulPlugin: divide selector success match , The selector name: / HTTP 2021-01-14 20:48:38. 29812-756 the INFO/work - threads - 23 O.D.S oul. Plugin. Base. AbstractSoulPlugin: divide selector success match , Selector Name :/ HTTP /test/** 2021-01-14 20:48:38.756 INFO 29812 -- [work-threads-23] selector Name :/ HTTP /test/** 2021-01-14 20:48:38.756 INFO 29812 -- [work-threads-23] O.D.S.P lugin. Httpclient. WebClientPlugin: The request urlPath is http://172.27.121.155:8188/test/findByUserId? userId=1, RetryTimes is 0 2021-01-14 20:48:39. 29812-609 the INFO/work - threads - 24 O.D.S oul. Plugin. Base. AbstractSoulPlugin: divide selector success match , The selector name: / HTTP 2021-01-14 20:48:39. 29812-609 the INFO/work - threads - 24 O.D.S oul. Plugin. Base. AbstractSoulPlugin: divide selector success match , Selector Name :/ HTTP /test/** 2021-01-14 20:48:39.609 INFO 29812 -- [work-threads-24] O.D.S.P lugin. Httpclient. WebClientPlugin: The request urlPath is http://172.27.121.155:8189/test/findByUserId? userId=1, RetryTimes is 0 2021-01-14 20:48:40. 29812-317 the INFO/work - threads - 25 O.D.S oul. Plugin. Base. AbstractSoulPlugin: divide selector success match , The selector name: / HTTP 2021-01-14 20:48:40. 29812-317 the INFO/work - threads - 25 O.D.S oul. Plugin. Base. AbstractSoulPlugin: divide selector success match , Selector Name :/ HTTP /test/** 2021-01-14 20:48:40.317 INFO 29812 -- [work-threads-25] selector Name :/ HTTP /test/** 2021-01-14 20:48:40.317 INFO 29812 -- [work-threads-25] O.D.S.P lugin. Httpclient. WebClientPlugin: The request urlPath is http://172.27.121.155:8188/test/findByUserId? userId=1, RetryTimes is 0 2021-01-14 20:48:40. 29812-976 the INFO [] - work - threads - 1 O.D.S oul. Plugin. Base. AbstractSoulPlugin: divide selector success match , The selector name: / HTTP 2021-01-14 20:48:40. 976 INFO - 29812 [- work - threads - 1] O.D.S oul. Plugin. Base. AbstractSoulPlugin: divide selector success match , Selector Name :/ HTTP /test/** 2021-01-14 20:48:40.977 INFO 29812 -- [-work-threads-1] O.D.S.P lugin. Httpclient. WebClientPlugin: The request urlPath is http://172.27.121.155:8188/test/findByUserId? userId=1, retryTimes is 0Copy the code

It can be observed that both requests are forwarded to port 8188 and port 8189, enabling load balancing

3.2.3. Pressure test

Simply pressure test the requests in direct connection and gateway

➜ soul git: (master) ✗ WRK - t8 - c40 - d30s http://localhost:8189/test/findByUserId\? userId\=1 Running 30s test @ http://localhost:8189/test/findByUserId? UserId =1 8 threads and 40 connections Thread Stats Avg Stdev Max +/- Stdev Latency 6.628ms 2.628ms 2.628ms Req/Sec 2.05K 493.86 2.84K 74.82% 486269 requests in 30.05s, 51.01MB Read requests /Sec: 16179.68 Transfer/ Sec: 1.70 MB ➜ soul git: (master) ✗ WRK - t8 - c40 - d30s http://localhost:9195/http/test/findByUserId\? userId\=1 Running 30s test @ http://localhost:9195/http/test/findByUserId? UserId =1 8 threads and 40 connections Thread Stats Avg Stdev Max +/- Stdev Latency 14.37ms 18.11ms 255.66ms 93.06% Req/Sec 459.41 139.11 1.01K 74.23% 109533 requests in 30.09s, 11.49MB read requests /Sec: 3639.60 Transfer/ Sec: 390.98KBCopy the code

It can be found that the performance is somewhat degraded after using the gateway, mainly because of the additional layer of forwarding.

Problem of 3.2.4.

When port 8189 is started, the registered client port is still 8188

The soul.http. Port is not changed with the help of the group

The modified configuration is as follows