CN111651320A - High-concurrency connection method and system - Google Patents

High-concurrency connection method and system Download PDF

Info

Publication number
CN111651320A
CN111651320A CN202010431472.8A CN202010431472A CN111651320A CN 111651320 A CN111651320 A CN 111651320A CN 202010431472 A CN202010431472 A CN 202010431472A CN 111651320 A CN111651320 A CN 111651320A
Authority
CN
China
Prior art keywords
connection
read
thread
user
event
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202010431472.8A
Other languages
Chinese (zh)
Inventor
李先楚
邓伟
张志平
胡道生
夏曙东
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Transwiseway Information Technology Co Ltd
Original Assignee
Beijing Transwiseway Information Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Transwiseway Information Technology Co Ltd filed Critical Beijing Transwiseway Information Technology Co Ltd
Priority to CN202010431472.8A priority Critical patent/CN111651320A/en
Publication of CN111651320A publication Critical patent/CN111651320A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/30Monitoring
    • G06F11/3003Monitoring arrangements specially adapted to the computing system or computing system component being monitored
    • G06F11/3006Monitoring arrangements specially adapted to the computing system or computing system component being monitored where the computing system is distributed, e.g. networked systems, clusters, multiprocessor systems
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/30Monitoring
    • G06F11/3051Monitoring arrangements for monitoring the configuration of the computing system or of the computing system component, e.g. monitoring the presence of processing resources, peripherals, I/O links, software programs
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/54Interprogram communication
    • G06F9/546Message passing systems or structures, e.g. queues

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • Computing Systems (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Quality & Reliability (AREA)
  • Software Systems (AREA)
  • Mathematical Physics (AREA)
  • Debugging And Monitoring (AREA)

Abstract

The application discloses a high concurrency connection method and a high concurrency connection system, which comprise the following steps: constructing a connection manager, and creating a state detection thread, an event monitoring thread and a data processing thread; detecting the connection state of each user in the connection manager by the state detection thread, and adding a socket corresponding to the user with the connection state being an online state into the asynchronous input/output event monitoring list; the event monitoring thread carries out read-write operation on the socket triggered by the read-write event in the asynchronous input and output event monitoring list, and stores read-write data received from the server side into a data queue; and the data processing thread processes the data in the data queue, and an asynchronous input and output model is adopted in the operation process among the three threads. By adopting the asynchronous input and output model to process data, hundreds of thousands of concurrent connection requests can be initiated by only using one server, so that the number of the servers to be used is reduced to the maximum extent, and the cost and the corresponding expenditure of the servers are reduced.

Description

High-concurrency connection method and system
Technical Field
The present application relates to the field of network testing technologies, and in particular, to a method and a system for high concurrency connection.
Background
At present, most clients realize multiple connection requests in a mode of starting one thread for each connection, and the creation of each thread brings great memory overhead; for example, for a 4G memory server, a maximum of 2000 threads can be created, and thus a maximum of 2000 long connections can be established. If more connections need to be created, the number of servers can only be increased, which, however, increases the costs correspondingly. Although current clustering and distribution technologies can load concurrency on multiple machines, and solve the high concurrency bottleneck problem by extending tens of servers, multiple servers are still required, increasing the cost of the servers and the corresponding expenses.
In view of the foregoing, it would be desirable to provide a method and system that reduces the number of servers used, the cost of the servers, and the associated costs.
Disclosure of Invention
In order to solve the above problems, the present application provides a high concurrency connection method and system.
In one aspect, the present application provides a high concurrency connection method, including:
constructing a connection manager, and creating a state detection thread, an event monitoring thread and a data processing thread;
the state detection thread detects the connection state of each user in the connection manager, and a socket corresponding to the user with the connection state being an online state is added into an asynchronous input/output event monitoring list;
the event monitoring thread carries out read-write operation on a socket triggered by a read-write event in the asynchronous input and output event monitoring list, wherein the read operation is to store read-write data received from the server side into a data queue;
and the data processing thread processes the data in the data queue, and the operation processes among the state detection thread, the event monitoring thread and the data processing thread adopt an asynchronous input and output model.
Preferably, the build connection manager comprises:
building a connection manager and initializing the building connection manager;
the connection manager creates sockets circularly according to the number of users, initiates connection to the server side, obtains and stores user connection information.
Preferably, the user connection information includes a user connection state.
Preferably, after the state detection thread detects the connection state of each user in the connection manager, the method further includes:
and newly initiating connection for the user with the connection state being the offline state.
Preferably, the performing, by the event listening thread, a read-write operation on a socket triggered by a read-write event in the asynchronous input/output event listening list, where the read operation is to store read-write data received from the server into the data queue includes:
when the event monitoring thread monitors a read-write event, finding a user corresponding to the read-write event in the asynchronous input and output event monitoring list according to the socket;
updating the connection state of the user to be an active state, and calling a callback function to process a read-write event;
and if the read-write event is processed as a read operation, storing the data received from the server side into a data queue.
Preferably, if the read-write event is processed as a write operation, the data to be sent corresponding to the user is sent to the server.
Preferably, if the connection state of the user is an abnormal closing state or a normal closing state, the state detection thread deletes the socket corresponding to the user from the asynchronous input/output event listening list.
Preferably, the connection manager includes: IP address, port, ID, socket, and connection status.
Preferably, the socket is created using a triplet including an IP address, protocol and port.
In a second aspect, the present application provides a high concurrent connection system for operating the above high concurrent connection method, including: and a server for setting a plurality of virtual IPs or installing a plurality of network cards.
The application has the advantages that: by adopting an asynchronous input and output model and using a state detection thread, an event monitoring thread and a data processing thread to process data, hundreds of thousands of concurrent connection requests can be initiated by only using one server, so that the number of servers to be used is reduced to the maximum extent, and the cost and the corresponding expenditure of the servers are reduced.
Drawings
Various other advantages and benefits will become apparent to those of ordinary skill in the art upon reading the following detailed description of the preferred embodiments. The drawings are only for purposes of illustrating preferred embodiments and are not to be construed as limiting the application. Also, like reference numerals are used to denote like parts throughout the drawings. In the drawings:
fig. 1 is a schematic diagram illustrating steps of a high concurrency connection method provided by the present application;
fig. 2 is a schematic flowchart of a high concurrent connection method provided in the present application.
Detailed Description
Exemplary embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. While exemplary embodiments of the present disclosure are shown in the drawings, it should be understood that the present disclosure may be embodied in various forms and should not be limited to the embodiments set forth herein. Rather, these embodiments are provided so that this disclosure will be thorough and complete, and will fully convey the scope of the disclosure to those skilled in the art.
According to an embodiment of the present application, a high concurrency connection method is provided, as shown in fig. 1, including:
s101, constructing a connection manager, and creating a state detection thread, an event monitoring thread and a data processing thread;
s102, detecting the connection state of each user in the connection manager by a state detection thread, and adding a socket corresponding to the user with the connection state being in an ONLINE (ONLINE) state into an asynchronous input/output event monitoring list;
s103, the event monitoring thread performs read-write operation on the socket triggered by the read-write event in the asynchronous input and output event monitoring list, wherein the read operation is to store read-write data received from the server side into a data queue;
and S104, the data processing thread processes the data in the data queue, and an asynchronous input and output model is adopted in the operation process among the state detection thread, the event monitoring thread and the data processing thread.
The connection manager is constructed by the main thread when the program is started, and the construction of the connection manager comprises the following steps:
constructing a connection manager and initializing the connection manager;
the connection manager creates sockets circularly according to the number of users, initiates connection to the server side, obtains and stores user connection information.
The user connection information includes a user connection status.
And the data processing thread performs business logic processing on the data in the data queue.
The state detection thread periodically or periodically detects the connection state of each user in the connection manager.
After the state detection thread detects the connection state of each user in the connection manager, the method further comprises the following steps:
and newly initiating connection for the user of which the connection state is the OFFLINE (OFFLINE) state.
The event monitoring thread performs read-write operation on the socket triggered by the read-write event in the asynchronous input and output event monitoring list, wherein the read operation is that the step of storing read-write data received from the server end into the data queue comprises the following steps:
when the event monitoring thread monitors a read-write event, finding a user corresponding to the read-write event in the asynchronous input and output event monitoring list according to the socket;
updating the connection state of the user to be an active state, and calling a callback function to process a read-write event;
and if the read-write event is processed as a read operation, storing the data received from the server side into a data queue.
And if the read-write event processing is write operation, sending the data to be sent corresponding to the user to the server. And if the connection state of the user is an abnormal closing state or a normal closing state, deleting the socket corresponding to the user from the asynchronous input and output event monitoring list by the state detection thread. If the event monitoring thread does not detect the read-write event for a long time, the connection state of the user corresponding to the read-write event is updated to be an abnormal closing state.
The connection manager includes: IP address, port, ID, socket, and connection status.
A socket is created using a triplet that includes an IP address, protocol, and port.
In the embodiment of the application, each connection is regarded as one user behavior and managed as one user, and all user connections represent connections.
Embodiments of the present application can be used to test high concurrent connections, for example: the system comprises a chat server, a game server, a vehicle access server, an audio and video server and the like. When testing such devices, it is difficult to initiate connection requests by organizing hundreds of thousands of people, so a high concurrent connection client is required to be used as a simulation tool to initiate hundreds of thousands of concurrent connection requests, and verify the ability of a server to process a large number of users online at the same time.
Next, examples of the present application will be further described, as shown in fig. 2.
The implementation mode of the application adopts an asynchronous input and output model and an event monitoring mechanism, can realize high concurrent connection request and data processing by using a small number of threads, is not limited by the number of threads of a server, and can break through 65535 connection numbers.
The server constructs a connection manager, which comprises: IP, port, ID, socket, connection status, etc.
Creating 1 state detection thread for detecting connection state, 1 event monitoring thread for event monitoring processing and a plurality of data processing threads, wherein each thread is responsible for respective task.
The connection manager initiates each user connection in a loop: and creating a socket by utilizing the triple (IP, protocol and port) and establishing connection with a server (to-be-tested terminal). The state detection thread adds the socket to the asynchronous input output event listening list and puts each user connection into the connection manager for management.
The event listening thread waits for the generation of an event. When the event monitoring thread monitors that the read-write event comes, the event monitoring thread respectively processes the read event and the write event by using a callback function, finds a user corresponding to the read-write event in an asynchronous input/output event monitoring list according to the socket, marks the state of the user as an active state, and hands the user to a data processing thread for corresponding data processing.
In the state detection thread, the event monitoring thread and the data processing thread, all processing operations performed on data by the three threads are asynchronous operations, so that delay and waste of server memory resources caused by serial operations from connection creation to connection, completion of connection, read-write actions, data acquisition and data processing can be avoided.
In a second aspect, according to an embodiment of the present application, there is also provided a high concurrent connection system for operating the above high concurrent connection method, including: and setting hardware equipment such as a plurality of virtual IPs or a server provided with a plurality of network cards.
Because the single network card server only has one real IP, the ports are fixed to 65535, and the single network card server serving as the client can only simultaneously initiate 65535 connection requests theoretically, and cannot meet the test requirements of a chat server, a game server, a vehicle access server, an audio and video server and the like.
The implementation mode of the application can realize hundreds of thousands of high concurrent connection requests by installing a plurality of network cards or establishing a plurality of virtual IPs (N). By creating a socket binding IP and port, a single server can initiate hundreds of thousands of connection requests (65535 multiplied by N).
The embodiment of the application can also increase and decrease the number of concurrent connections through simple configuration according to business needs.
In the method, the asynchronous input and output model is adopted in the whole process of processing the data by the state detection thread, the event monitoring thread and the data processing thread, and hundreds of thousands of concurrent connection requests can be initiated by only using one server, so that the number of the servers needing to be used is reduced to the maximum extent, and the cost and the corresponding expenditure of the servers are reduced. According to the implementation mode, resources of a single server can be excavated to a greater extent, vertical expansion is tried, and then horizontal expansion is carried out, so that expenses related to the server can be effectively saved, such as hardware resources, a machine room, operation and maintenance, electric power and the like.
The above description is only for the preferred embodiment of the present application, but the scope of the present application is not limited thereto, and any changes or substitutions that can be easily conceived by those skilled in the art within the technical scope of the present application should be covered within the scope of the present application. Therefore, the protection scope of the present application shall be subject to the protection scope of the claims.

Claims (10)

1. A method for high concurrency linking, comprising:
constructing a connection manager, and creating a state detection thread, an event monitoring thread and a data processing thread;
the state detection thread detects the connection state of each user in the connection manager, and a socket corresponding to the user with the connection state being an online state is added into an asynchronous input/output event monitoring list;
the event monitoring thread carries out read-write operation on a socket triggered by a read-write event in the asynchronous input and output event monitoring list, wherein the read operation is to store read-write data received from the server side into a data queue;
and the data processing thread processes the data in the data queue, and the operation processes among the state detection thread, the event monitoring thread and the data processing thread adopt an asynchronous input and output model.
2. The method of claim 1, wherein the building a connection manager comprises:
building a connection manager and initializing the building connection manager;
the connection manager creates sockets circularly according to the number of users, initiates connection to the server side, obtains and stores user connection information.
3. The method of claim 2, wherein the user connection information comprises a user connection status.
4. The method of claim 1, after the state detection thread detects the connection state of each user in the connection manager, further comprising:
and newly initiating connection for the user with the connection state being the offline state.
5. The method of claim 1, wherein the event listening thread performs a read/write operation on a socket triggered by a read/write event in the asynchronous input/output event listening list, wherein the read operation is to store read/write data received from the server into the data queue, and the read operation comprises:
when the event monitoring thread monitors a read-write event, finding a user corresponding to the read-write event in the asynchronous input and output event monitoring list according to the socket;
updating the connection state of the user to be an active state, and calling a callback function to process a read-write event;
and if the read-write event is processed as a read operation, storing the data received from the server side into a data queue.
6. The method of claim 5,
and if the read-write event processing is write operation, sending the data to be sent corresponding to the user to a server.
7. The method of claim 1, wherein if the connection status of the user is an abnormal shutdown status or a normal shutdown status, the status detection thread deletes the socket corresponding to the user from the asynchronous input output event listening list.
8. The method of claim 1, wherein the connection manager comprises: IP address, port, ID, socket, and connection status.
9. The method of claim 1, wherein the socket is created using a triplet including an IP address, protocol, and port.
10. A high concurrency connection system for operating the high concurrency connection method according to any one of claims 1 to 9, comprising: and a server for setting a plurality of virtual IPs or installing a plurality of network cards.
CN202010431472.8A 2020-05-20 2020-05-20 High-concurrency connection method and system Pending CN111651320A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010431472.8A CN111651320A (en) 2020-05-20 2020-05-20 High-concurrency connection method and system

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010431472.8A CN111651320A (en) 2020-05-20 2020-05-20 High-concurrency connection method and system

Publications (1)

Publication Number Publication Date
CN111651320A true CN111651320A (en) 2020-09-11

Family

ID=72350763

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010431472.8A Pending CN111651320A (en) 2020-05-20 2020-05-20 High-concurrency connection method and system

Country Status (1)

Country Link
CN (1) CN111651320A (en)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112188090A (en) * 2020-09-22 2021-01-05 深圳大学 Camera system multithread control method, device, server and storage medium
CN112995198A (en) * 2021-03-29 2021-06-18 中信银行股份有限公司 Short-connection communication method and device based on socket
CN116820430A (en) * 2023-08-28 2023-09-29 苏州浪潮智能科技有限公司 Asynchronous read-write method, device, computer equipment and storage medium

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103164256A (en) * 2011-12-08 2013-06-19 深圳市快播科技有限公司 Processing method and system capable of achieving one machine supporting high concurrency
CN110099035A (en) * 2018-01-31 2019-08-06 上海甚术网络科技有限公司 A kind of web advertisement data high concurrent access method of servicing

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103164256A (en) * 2011-12-08 2013-06-19 深圳市快播科技有限公司 Processing method and system capable of achieving one machine supporting high concurrency
CN110099035A (en) * 2018-01-31 2019-08-06 上海甚术网络科技有限公司 A kind of web advertisement data high concurrent access method of servicing

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
林存燕: "Python 高性能网络编程并发框架研究" *

Cited By (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112188090A (en) * 2020-09-22 2021-01-05 深圳大学 Camera system multithread control method, device, server and storage medium
CN112188090B (en) * 2020-09-22 2022-05-31 深圳大学 Camera system multithread control method, device, server and storage medium
CN112995198A (en) * 2021-03-29 2021-06-18 中信银行股份有限公司 Short-connection communication method and device based on socket
CN112995198B (en) * 2021-03-29 2023-04-28 中信银行股份有限公司 Short-connection communication method and device based on socket
CN116820430A (en) * 2023-08-28 2023-09-29 苏州浪潮智能科技有限公司 Asynchronous read-write method, device, computer equipment and storage medium
CN116820430B (en) * 2023-08-28 2024-01-09 苏州浪潮智能科技有限公司 Asynchronous read-write method, device, computer equipment and storage medium

Similar Documents

Publication Publication Date Title
CN108600029B (en) Configuration file updating method and device, terminal equipment and storage medium
CN106331098B (en) Server cluster system
CN111651320A (en) High-concurrency connection method and system
CN112463144B (en) Distributed storage command line service method, system, terminal and storage medium
CN107666493B (en) Database configuration method and equipment thereof
CN113452774B (en) Message pushing method, device, equipment and storage medium
CN112583931A (en) Message processing method, message middleware, electronic device and storage medium
CN112217847A (en) Micro service platform, implementation method thereof, electronic device and storage medium
CN111198662A (en) Data storage method and device and computer readable storage medium
CN111181765A (en) Task processing method and device
CN103490945A (en) Method for detecting maximum telnet user quantity
CN111541762A (en) Data processing method, management server, device and storage medium
CN112153126A (en) Deployment and node management method and system for K8S cluster
WO2020233001A1 (en) Distributed storage system comprising dual-control architecture, data reading method and device, and storage medium
CN113342893B (en) Node synchronization method and device based on block chain, storage medium and server
CN114697391A (en) Data processing method, device, equipment and storage medium
CN102118274A (en) State monitoring method, device and system
CN105677589A (en) Access control method, access control device and access control system
CN112073499A (en) Dynamic service method of multi-machine type cloud physical server
CN116016209A (en) Network automation method and device
CN114840495A (en) Database cluster split-brain prevention method, storage medium and device
CN110935168B (en) Distributed ID generation method, device and equipment for global uniform architecture
CN113204459A (en) U shield testing method, device, equipment and medium
CN112003727A (en) Multi-node server power supply testing method, system, terminal and storage medium
CN112333262A (en) Data updating prompting method and device, computer equipment and readable storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination