当前位置:网站首页>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

边栏推荐
- MYSQL的select语句查询;运算符课后练习
- Flex elastic box
- tcp和udp的区别和联系
- DataX installation and use
- 【三】redis特点功能
- Wechat official account - authorized login
- 幂等性组件
- Manually create a simple RPC (< - < -)
- Sales notice: on July 22, the "great heat" will be sold, and the [traditional national wind 24 solar terms] will be sold in summer.
- CTF常见加密方式JS
猜你喜欢

数字藏品成文旅产业新热点

南京邮电大学CTF题目writeup (二) 含题目地址

数藏如何实现WEB3.0社交

南京邮电大学CTF题目writeup (一) 含题目地址

出游不易,看景区用数字藏品刷存在感

分布式锁-Redis实现

mysql分页出现问题

Create a virtual environment using pycharm

Books - mob

Sales notice: on July 22, the "great heat" will be sold, and the [traditional national wind 24 solar terms] will be sold in summer.
随机推荐
数据处理之增删改;约束
Installation and use of sqoop
极客大挑战2019-SQL注入五题PW
Trino function tag
Progressive enhancement and graceful degradation
regular expression
1:开启慢查询日志 与 找到慢SQL
Books - Templeton teaches you reverse
JS!!
微信小程序手机号正则校验规则
Books - investment ideas and Strategies
Digital collections strengthen reality with emptiness, enabling the development of the real economy
MYSQL的select语句查询;运算符课后练习
文旅头部结合数字藏品效应显著,但如何支撑用户持续购买力
(PHP graduation project) obtained based on PHP student homework submission management system
常见WAF拦截页面总结
Sales notice: on July 22, the "great heat" will be sold, and the [traditional national wind 24 solar terms] will be sold in summer.
南京邮电大学CTF题目writeup (一) 含题目地址
2:为什么要读写分离
JS simple publish and subscribe class