当前位置:网站首页>Distributed cluster architecture scenario optimization solution: session sharing problem
Distributed cluster architecture scenario optimization solution: session sharing problem
2022-07-28 06:03:00 【Brother Tao】
Distributed cluster architecture scenario optimization solution :Session Sharing issues
Session Sharing issues
Session Sharing and Session Keep or call Session Uniformity

1、 Session Problem cause analysis
The reason for this problem , Basically, it's because Http Protocols are stateless protocols . The data generated by the client and server in a session will not be preserved , So the second request server can't realize that you've been here , Http Why should it be designed as a stateless protocol ? In the early days, it was static pages, and it didn't matter whether there was a state or not , Later, there are more dynamic contents , You need to be in a state , There are two ways to keep Http Technology of state , That's it Cookie and Session. And the above problem of keeping logging in , The analysis is shown in the figure below :
scene :Nginx Default polling policy

2、 solve Session A consistent solution
1、Nginx Of IP_Hash Strategy ( have access to )
Same client IP All requests will be routed to the same target server , Also called session stickiness
advantage :
- Simple configuration , Do not invade the application , No additional code changes are required
shortcoming :
- Server restart Session The loss of
- There is a risk of high single point load
- Single point problem
2、Session Copy ( Not recommended )
Multiple tomcat By modifying the configuration file , achieve Session Copy between

advantage :
- Do not invade the application
- It is convenient for the horizontal expansion of the server
- It can adapt to various load balancing strategies
- Server restart or downtime will not cause Session The loss of
shortcoming :
- Low performance
- Memory consumption
- Can't store too much data , Otherwise, the more data, the more performance will be affected
- Delay
3、Session share ,Session Centralized storage ( recommend )
Session The essence of is caching , that Session Why not hand over the data to professional caching middleware ? such as Redis

advantage :
- It can adapt to various load balancing strategies
- Server restart or downtime will not cause Session The loss of
- Strong expansion ability
- Suitable for large number of clusters
shortcoming :
- Intrusion into applications , And are introduced Redis Interactive code
Spring Session Make based on Redis Of Session Sharing applications is very simple
1) introduce Jar
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-data-redis</artifactId>
</dependency>
2) To configure redis
spring.redis.database=0
spring.redis.host=127.0.0.1
spring.redis.port=6379
3) adding annotations

3、 Source code


Observe its parent class , In the parent class Filter


This Filter Namely SpringSession At the core

In the filter HttpServletRequest packing

It's essentially a HtppRequest, Have the same approach , look for getSession



go back to SessionRepositoryFilter Of doFilterInternal Method




Schematic diagram

边栏推荐
猜你喜欢

路由器与交换机的区别

进程线程协程的区别

Flex elastic box item properties

Create a virtual environment using pycharm

Flink CDC (Mysql为例)

记录下在线扩容服务器遇到的问题 NOCHANGE: partition 1 is size 419428319. it cannot be grown

On how digital collections and entities can empower each other

1:为什么数据库要分库分表

项目不报错,正常运行,无法请求到服务

Prime_Series靶场从探测到提权
随机推荐
JS promise implementation logic
It's not easy to travel. You can use digital collections to brush the sense of existence in scenic spots
Use Python to encapsulate a tool class that sends mail regularly
Cookie、Session和Token的区别与联系
Linux(centOs7) 下安装redis
Structured streaming in spark
1: Enable slow query log and find slow SQL
【二】redis基础命令与使用场景
DataX installation and use
Chapter IX sub query (key)
Service reliability guarantee -watchdog
数字藏品的生意没那么好做
svn incoming内容无法更新下来,且提交报错:svn: E155015: Aborting commit: XXX remains in conflict
常见WAF拦截页面总结
服务可靠性保障-watchdog
1:开启慢查询日志 与 找到慢SQL
Notice of attack: [bean Bingbing] send, sell, cash, draw, prize, etc
mysql 触发器
微信小程序手机号正则校验规则
极客大挑战2019-SQL注入五题PW