当前位置:网站首页>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 .
边栏推荐
猜你喜欢

I don't know how lucky the boy who randomly typed logs is. There must be a lot of overtime

Parameter initialization

Emmet syntax

Asp graduation project - based on C # +asp Design and implementation of enterprise investment value analysis system based on. Net + sqlserver (graduation thesis + program source code) -- enterprise in

云原生管理实践:业务引领的DevOps持续交付体系
The biggest upgrade of Bluetooth over the years: Bluetooth Le audio is about to appear in all kinds of digital products
![[Bert multi label text classification practice] I - overview of practical projects](/img/47/3e6cf5d49e41a03ea7f9b6eb295e1d.png)
[Bert multi label text classification practice] I - overview of practical projects

Basic part 2 of flowable

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

Gutcloud technology restcloud completed the pre-A round of financing of tens of millions of yuan
随机推荐
Flowable UI制作流程图
(Video + graphic) introduction to machine learning series - Chapter 3 logical regression
MySQL事务与MVCC如何实现的隔离级别
smart-webcomponents 14.2.0 Crack
【机器学习】逻辑回归代码练习
Unity Xchart3.0基本用法快速上手
23 postgraduate entrance examination people hold on! The first wave of exam abandonment peak has arrived!
【集中培训】HCIP-Cloud Computing 资源交流帖
One article tells you the salary after passing the PMP Exam
Implementation of DFA string recognition based on C language simulation
LeetCode刷题(6)
【Unity入门计划】常用学习网址收藏
Configuration file settings for remote connection to Windows version server redis
Data representation and calculation (base)
Retinal Vessel Segmentation via a Semantics and Multi-Scale Aggregation Network
The use and Simulation of string function, character function and memory function
Travel notes in 2022 (ongoing)
Introduction to translation professional qualification (level) examination
[C language] DataGridView binding data
File upload and expansion