当前位置:网站首页>Four types of technical solutions shared by distributed sessions, and their advantages and disadvantages
Four types of technical solutions shared by distributed sessions, and their advantages and disadvantages
2022-07-29 09:23:00 【Life is cool to the end】
Distributed Session Shared 4 Such technical solutions , Compare with the advantages and disadvantages
What is? session
What is? session Consistency issues ?
Distributed session
Session Consistency solutions
1. What is? session
The server is Each user creates a session , Store information about users , So that multiple requests can be located in the same context . this
sample , When the user is in the Web When you jump between pages , Stored in Session The variables in the object will not be lost , But in the whole
Always exist in the user session .
When a user requests... From an application Web When the page , If the user does not have a session , be Web The server will automatically create a
Session object . When the session expires or is abandoned , The server will terminate the session .
Web In development ,web-server It can be automatically created for users of the same browser session, Provide data storage function .
The most common , Will send the user's login information 、 User information is stored in session in , To stay logged in .
2. What is? session Consistency issues ?
As long as the user doesn't restart the browser , Every time http Short connection request , In theory, the server can locate session, Keep talking .
3. Distributed session
Single server web Application ,session The information just needs to be in the server , It's the way we've been in touch most of the last few years , But in recent years
With the popularity of Distributed Systems , Single system can no longer meet the increasing demand of millions of users , The cluster deployment server is already in
Many companies use it , When high concurrent requests arrive at the server, they are distributed to a service in the cluster through load balancing
device , So it's possible This results in multiple requests from the same user being distributed to different servers in the cluster , There will be no access session
Data , therefore session Sharing of becomes a problem .
4.Session Consistency solutions 
1、session Copy
session Replication is a kind of server cluster used more in the early enterprise level session Management mechanism .
Application server on web Container of session Copy function , Synchronization between several servers in the cluster session object , Make each
All... Are saved on the server session Information , In this way, any machine down will not lead to session Data loss for , Server usage
session when , Get it directly from local .
brief introduction : Put... On a machine Session The data broadcast is copied to the rest of the machines in the cluster
session Copy use scene : Fewer machines , The network traffic is small
advantage : Implement a simple 、 Less configuration 、 When there are machines in the network Down Drop time does not affect user access
shortcoming : Broadcast copy to the rest of the machine has a certain time , Bring a certain amount of network overhead .
In this way, when the application cluster reaches thousands of units , There will be bottlenecks , Every computer needs to be backed up session, There is not enough memory
condition .
2、session binding
utilize hash Algorithm , such as nginx Of ip_hash, To make the same Ip The requests for are distributed to the same server .
session Binding uses scene : The number of machines is moderate 、 It's not very demanding on stability
advantage : Implement a simple 、 Convenient configuration 、 No extra network overhead
shortcoming : There are machines in the network Down Drop time 、 user Session Will lose 、 Easy to cause a single point of failure .
This way, Does not meet the high availability requirements for the system , Because once a server goes down , So the... On the machine session It's gone , After the user requests to switch to another machine, there is no session, Unable to complete business processing .
3、 utilize cookie Record session
session Record on the client side , Every time you request the server , take session Send it to the server in the request , After the server has finished processing, please
After seeking, the modified session Respond to clients , The client here is cookie.
shortcoming For example cookie Size limit , The amount of information that can be recorded is limited ;
Every request response needs to be delivered cookie, Affect performance , If the user turns off cookie, Access is not normal .
advantage :cookie Easy to use , High availability , Support linear scaling of application servers , And most of the things to record session The information is relatively small , So in fact , Many websites are more or less in use cookie Record session.
4、session The server
session The server can solve all the above problems , Using independently deployed session The server ( colony ) Unified management
session, Every time the server reads and writes session when , All visit session The server .
This solution is actually state separation of the application server , There are stateless application servers and stateful ones session The server , however
Then the architecture is designed according to the different characteristics of the two servers .
For stateful session The server , A simpler way is to use distributed caching (redis、memcached), Or store
In the database ( Such as MySQL) etc. . Pack on the basis of these products , Make it conform to session Storage and access requirements for .
If the business scenario is right for session Management has relatively high requirements , Such as the use of session Service grassroots single sign on (sso), User server, etc
function , We need to develop special session Service management platform .
session Server usage scenarios : There are many machines in the cluster 、 Complex network environment .
advantage : Good reliability
shortcoming : The implementation is complex 、 Stability depends on the stability of the cache 、Session When information is put into the cache, there should be a reasonable writing strategy .
边栏推荐
- 原型链继承和构造函数继承的 “毛病”
- (Video + graphic) introduction to machine learning series - Chapter 3 logical regression
- The gold content of PMP certificate has been increased again and included in the scope of Beijing work residence permit
- Introduction to translation professional qualification (level) examination
- "Defects" of prototype chain inheritance and constructor inheritance
- [centralized training] hcip cloud computing resource exchange post
- Unity Xchart3.0基本用法快速上手
- 多标签用户画像分析跑得快的关键在哪里?
- Simple unit testing idea
- 乱打日志的男孩运气怎么样我不知道,加班肯定很多
猜你喜欢

ERROR 1045 (28000): Access denied for user ‘ODBC‘@‘localhost‘ (using password: NO)

Quaternion and its simple application in unity

浅谈契约测试

A structured random inactivation UNET for retinal vascular segmentation

The use and Simulation of string function, character function and memory function

Use cpolar to publish raspberry pie web pages (improvement of cpolar function)

机器学习之分类模型评估指标及sklearn代码实现
[C language] DataGridView binding data

smart-webcomponents 14.2.0 Crack

Database system design: partition
随机推荐
How to export the old and new file names and locations to excel after file renaming
[Bert multi label text classification practice] I - overview of practical projects
STM32 application development practice tutorial: getting to know STM32 for the first time
The gold content of PMP certificate has been increased again and included in the scope of Beijing work residence permit
四元数与其在Unity中的简单应用
Implementation of DFA string recognition based on C language simulation
40余岁的边缘老技术,是未来乏力还是掘地而起?
QMainWindow 详解
Acwing game 59 [End]
多标签用户画像分析跑得快的关键在哪里?
Network knowledge summary
文件上传及拓展
Floweable foundation Chapter 1
C# 使用RestSharp库实现POST请求
【云驻共创】【HCSD大咖直播】亲授大厂面试秘诀
One click automated data analysis! Come and have a look at these treasure tool libraries
查看端口占用情况
Floweable advanced
如何为OpenHarmony做贡献
Flowable UI production flow chart