Spring cloud+zuul, session sharing performance is not high,

What I want to say today is that I don’t use zuul for spring cloud load balancing, but nginx+spring boot (multi-tomcat implementation).

Why not use zuul? Using zuul really facilitates our development. It integrates spring session so that multiple microservices can share session. However, it is precisely because of this mechanism that redis is queried at least twice or multiple times for each request, which increases the pressure of redis and the N communication links of the system.

The session sharing mechanism of spring cluod is like this. Zuul passes the sessionId cookie to the next microservice A. Microservice A obtains the sessionId through the cookie value, and then queries redis according to the sessionId to read all session values; when microservice A When calling microservice B, the cookie is also passed to microservice B, and microservice B obtains all session values ​​from redis through the same process. That is, before our microservice uses the session, our framework reads redis two or three times or more.

In this way, redis may become the bottleneck of the system, because each request must read and write redis several times. Regardless of the bottleneck or delay, this mechanism is a bit not good. In my understanding, microservices should only do the work of microservices and should not have state. You should not manage the session, and the work of managing the session should be implemented by the web layer, even if the microservices of spring cloud are implemented through web services.

The framework I want to talk about below is that a spring boot web service gateway is placed before the microservice, and the microservice is called through the web service. All session reading and writing work is achieved through the pre-web layer. The session value needed by the microservice is read out in the pre-web layer (such as a verification code or user ID), and then passed as a parameter to the next level of microservice. The microservice no longer needs to go to redis to read the session. Instead, it gets the session from the interface parameters. The following is my recommended architecture.

Regarding the nginx code and spring cloud architecture diagram, please refer to the original text below:

https://www.yunedit.com/xueyuan/jx/1007

Guess you like

Origin blog.csdn.net/handsome0916/article/details/93581825