当前位置:网站首页>Websocket (WS) cluster solution
Websocket (WS) cluster solution
2022-06-25 15:24:00 【Running pig ZC】
WebSocket(ws) Clustering solutions
1: Preface
In a particular scenario , It is necessary to realize the purpose that the server actively pushes data to the client , Now ws It's coming out. . The following model

however This kind of existence, this single point problem , So how to solve this single point problem , It's simple , We go straight through nginx Just configure the cluster , as follows (nginx It's supporting ws Clustered )

The configuration is as follows
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}

2: problem
Now the project has been deployed , Is there a problem ? Next, let's analyze
because Load balancing Why , The following may occur
client1 adopt http Request server A, Then you need the server to pass ws Push data to client2, But at this point ,client2 Connected to another server B, Due to server A and client2 There is no maintenance between ws, So the data cannot pass through the server A Push to client2 Of , Or through the server B Push the data over , We need a bridge to connect , Let the server B Know you want to push data to client2

3: Solutions
3.1:jvm Communication problems between
By what means can we achieve notification ,http?tcp? Or something like a message queue
3.2: Convention on data format of communication
stay jvm Data transmission before ,jvm2 Received on jvm1 When the data in , You should agree on a data format ( agreement ), How to analyze , How to send , The message sent specifies the machine name , To every one. jvm Match a message queue
{
"to":"serverB",
"data": " How are you? ~"
}
3.3:client2 Which server to connect to
Can pass client2 When connecting to the server redis Go and get a registry ,<client2, jvmName>
3.4:client2 Is it in me http On the requested machine
Can pass client2 When connecting to the server, at present jvm Add a key value pair to the cache <client2, wsclient>
3.5: Overall flow chart

4: summary
If you can't solve the problem in a certain dimension , Can we go up a dimension to think , Generally speaking, it is OK , Many problems are solved in this way , For example, the classic distributed lock , It is solved through dimension upgrading .
边栏推荐
- System Verilog - thread
- Common classes in QT
- iconv_ Open returns error code 22
- One question per day, punch in
- google_ Breakpad crash detection
- Brain tree (I)
- Core mode and immediate rendering mode of OpenGL
- 55 specific ways to improve program design (1)
- Go language template text/template error unexpected EOF
- Yolov3 spp Darknet version to caffemodel and then to OM model
猜你喜欢

‘make_ unique’ is not a member of ‘std’

Image segmentation based on deep learning: network structure design

Learning notes on February 5, 2022 (C language)

Yolov5 Lite: fewer parameters, higher accuracy and faster detection speed

Introduction to flexible array

CV pre training model set

Review of arrays and pointers triggered by a topic

QT loading third-party library basic operation

QT set process startup and self startup

Learning notes on February 8, 2022 (C language)
随机推荐
3. Sequential structure multiple choice questions
Cross compilation correlation of curl Library
Real variable instance
System Verilog — interface
Qmake uses toplevel or topbuilddir
Detailed summary of reasons why alertmanager fails to send alarm messages at specified intervals / irregularly
One question per day, punch in
Detailed description of crontab command format and summary of common writing methods
QT opens the print dialog box in a text editor
Basic knowledge of pointer
(1) Introduction
iconv_ Open returns error code 22
Sampling method and descriptive statistical function in R language
Time stamp calculation and audio-visual synchronization of TS stream combined video by ffmpeg protocol concat
JS select all exercise
55 specific ways to improve program design (1)
(2) Relational database
Efficient pytorch: how to eliminate training bottlenecks
System Verilog - function and task
Dynamic memory allocation