Data processing method and device and computer readable storage medium
By using Redis's serial number autoincrement algorithm in the gateway to generate message sequence numbers and processing message queues in the client, the problem of messy message order in WebSocket long connection is solved, and the message sending efficiency is improved.
Patent Information
- Application Number
- CN202411151984.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-21
- Publication Date
- 2024-12-06
AI Technical Summary
In the cloud environment, due to network complexity in the long WebSocket connection, the order of messages may be disordered, resulting in the data received by the client being large and small, and the time being inconsistent, affecting the message sending efficiency.
The gateway generates a message sequence number based on Redis's serial number autoincrement algorithm to ensure the uniqueness of the message and store a message queue in the client. If the message sequence number is continuous, it will be sent. If it is not continuous and the first sequence number is greater than the second sequence number Store in the queue, if it is discontinuous and the first sequence number is smaller than the second sequence number, it will be discarded to ensure the order of the data.
It effectively avoids the problem of data fluctuations and inconsistencies in time due to long-connected data disorder, and improves the efficiency of message sending of clients during long-connected communication.
Smart Images

Figure CN119094467A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data processing technology, and in particular to a data processing method, device and computer-readable storage medium. Background Art
[0002] There are many scenarios in Internet systems / products that require the front-end page to obtain server data in real time, such as real-time refresh of the number of remaining tickets for ticket grabbing, real-time acquisition of others' edited content for multi-person collaborative office work, and real-time monitoring of traffic changes. These scenarios usually use WebSocket persistent connections as the communication framework.
[0003] Due to the complex network environment in the cloud environment and the long message connection links, the order in which messages arrive at the client may be disordered, resulting in the client receiving data with inconsistent time and volume, which in turn affects the efficiency of message sending.
[0004] Therefore, how to improve the efficiency of client message sending during long connection communication is a problem that needs to be solved urgently. Summary of the invention
[0005] The main purpose of this application is to provide a data processing method, device and computer-readable storage medium, aiming to solve the technical problem of how to improve the efficiency of client message sending during long connection communication.
[0006] To achieve the above object, the present application provides a data processing method, which comprises the following steps:
[0007] When receiving the first message sequence number and the message to be sent sent by the server, the client obtains the second message sequence number corresponding to the pushed message, wherein the gateway generates the first message sequence number corresponding to the message to be sent based on the Redis sequence number self-increment algorithm;
[0008] If the second message sequence number is continuous with the first message sequence number, sending the message to be sent;
[0009] If the second message sequence number is not continuous with the first message sequence number and the first message sequence number is greater than the second message sequence number, storing the to-be-sent message in a message queue based on the first message sequence number;
[0010] If the second message sequence number is not continuous with the first message sequence number and the first message sequence number is smaller than the second message sequence number, the message to be sent is discarded.
[0011] Furthermore, if the second message sequence number is not continuous with the first message sequence number and the first message sequence number is greater than the second message sequence number, the step of storing the to-be-sent message in the message queue based on the first message sequence number includes:
[0012] If the second message sequence number is not continuous with the first message sequence number and the first message sequence number is greater than the second message sequence number, obtaining the third message sequence number of the current head message of the message queue;
[0013] If the first message sequence number is less than the third message sequence number, storing the message to be sent at the head of the message queue, so that the message to be sent is used as the current head message of the message queue;
[0014] If the first message sequence number is greater than the third message sequence number, the message to be sent is stored at the end of the message queue, and the messages in the message queue are sorted.
[0015] Furthermore, the data processing method further includes:
[0016] When receiving the aggregate message sent by the gateway, the server adds the message sending task corresponding to the aggregate message to the task slot corresponding to the time wheel;
[0017] The server accumulates the number of tasks for sending messages in the task slot;
[0018] If the number of tasks reaches the preset number, the server executes the message sending task in the task slot and clears the task slot;
[0019] If the delay time corresponding to the time wheel reaches a preset time length, the server executes the message sending task in the task slot and clears the task slot.
[0020] Furthermore, the step of adding the message sending task corresponding to the aggregate message to the task slot corresponding to the time wheel includes:
[0021] If the aggregate message is the first aggregate message received, the server establishes a time wheel;
[0022] The server adds the message sending task corresponding to the aggregate message to the task slot corresponding to the time wheel.
[0023] Furthermore, the data processing method further includes:
[0024] The client sends a first heartbeat message based on the long connection at a first preset time interval;
[0025] If the corresponding heartbeat response information from the server is not received, the first count is accumulated;
[0026] If the first number reaches a preset threshold, the long connection is disconnected, and a long connection reconstruction operation is performed at a second preset time interval.
[0027] Furthermore, the step of the client sending the first heartbeat information based on the long connection at a first preset time interval includes:
[0028] Determine whether the long connection is in a read-write idle state;
[0029] If the long connection is in a read-write idle state, a first heartbeat message is sent based on the long connection at a first preset time interval.
[0030] Furthermore, the data processing method further includes:
[0031] When the persistent connection survives, the server sends a second heartbeat message based on the persistent connection at a second preset time interval;
[0032] If the server does not receive the corresponding heartbeat response information from the client, the server will accumulate the second number;
[0033] If the second number reaches a preset threshold, the server disconnects the persistent connection and deletes the cache information corresponding to the persistent connection.
[0034] Furthermore, before the step of receiving the first message sequence number sent by the server and the message to be sent, the client obtains the second message sequence number corresponding to the pushed message, the data processing method further includes:
[0035] When receiving a business message from the business server, the gateway generates the first message sequence number corresponding to the business message based on the Redis sequence number auto-increment algorithm;
[0036] The gateway sends the first message sequence number and the service message to the server;
[0037] The server processes the business message and obtains the message to be sent corresponding to the business message;
[0038] The server sends the first message sequence number and the message to be sent to the client.
[0039] In addition, to achieve the above-mentioned purpose, the present application also provides a data processing device, which includes: a memory, a processor, and a data processing program stored in the memory and executable on the processor, and the data processing program implements the steps of the aforementioned data processing method when executed by the processor.
[0040] In addition, to achieve the above-mentioned purpose, the present application also provides a computer-readable storage medium, on which a data processing program is stored, and when the data processing program is executed by a processor, the steps of the aforementioned data processing method are implemented.
[0041] In the present application, when the client receives the first message sequence number sent by the server and the message to be sent, the client obtains the second message sequence number corresponding to the pushed message, wherein the gateway generates the first message sequence number corresponding to the message to be sent based on the Redis sequence number self-increment algorithm; then if the second message sequence number is continuous with the first message sequence number, the message to be sent is sent; then if the second message sequence number is not continuous with the first message sequence number and the first message sequence number is greater than the second message sequence number, the message to be sent is stored in the message queue based on the first message sequence number; if the second message sequence number is not continuous with the first message sequence number and the first message sequence number is less than the second message sequence number, the message to be sent is discarded; the message sequence number is generated by the Redis sequence number self-increment algorithm in the gateway to ensure the uniqueness of the sequence number of each day's message, so that the data received by the client is finally ordered, avoiding the problem of data fluctuations and inconsistency in time due to long connection data disorder, and improving the message sending efficiency of the client during long connection communication. BRIEF DESCRIPTION OF THE DRAWINGS
[0042] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0043] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0044] Figure 1 A flowchart of the first embodiment of the data processing method of the present application is provided;
[0045] Figure 2 A schematic diagram of a data processing method in an embodiment of the present application;
[0046] Figure 3 This is a schematic diagram of the module structure of the data processing device of this application.
[0047] The realization of the purpose, functional features and advantages of this application will be further explained in conjunction with embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0048] It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0049] In order to better understand the technical solution of the present application, a detailed description will be given below in conjunction with the accompanying drawings and specific implementation methods.
[0050] The main solution of the present application is: when receiving the first message sequence number sent by the server and the message to be sent, the client obtains the second message sequence number corresponding to the pushed message, wherein the gateway generates the first message sequence number corresponding to the message to be sent based on the Redis sequence number self-increment algorithm; if the second message sequence number is continuous with the first message sequence number, the message to be sent is sent; if the second message sequence number is not continuous with the first message sequence number and the first message sequence number is greater than the second message sequence number, the message to be sent is stored in the message queue based on the first message sequence number; if the second message sequence number is not continuous with the first message sequence number and the first message sequence number is less than the second message sequence number, the message to be sent is discarded.
[0051] At present, there are many scenarios in Internet systems / products that require the front-end page to obtain server-side data in real time, such as real-time refresh of the number of remaining tickets for ticket grabbing, real-time acquisition of other people's edited content for multi-person collaborative office, and real-time monitoring of traffic changes. These scenarios usually use WebSocket persistent connections as the communication framework.
[0052] Due to the complex network environment in the cloud environment and the long message connection link, the order in which each message arrives at the client may be disordered, resulting in the problem that the data received by the client is inconsistent and the time is inconsistent, which in turn affects the efficiency of message sending. Therefore, how to improve the efficiency of client message sending during long connection communication is a problem that needs to be solved urgently.
[0053] This application generates message sequence numbers through the Redis serial number self-increment algorithm in the gateway to ensure the uniqueness of the sequence numbers of each day's messages, so that the data received by the client is finally ordered, avoiding the problem of data fluctuations and inconsistent time due to long connection data disorder, and improving the client's message sending efficiency during long connection communication.
[0054] It should be noted that the execution subject of this embodiment may be a data processing device, or a computing service device with data processing, network communication and program running functions, such as a tablet computer, a personal computer, a mobile phone, etc., or a data processing device capable of realizing the above functions, etc., and this embodiment does not specifically limit this. The following takes the data processing device as the execution subject as an example to illustrate this embodiment and the following embodiments.
[0055] Based on this, this application proposes a data processing method of the first embodiment, please refer to Figure 1 , the data processing method includes steps S101 to S104:
[0056] Step S101, when receiving the first message sequence number sent by the server and the message to be sent, the client obtains the second message sequence number corresponding to the pushed message, wherein the gateway generates the first message sequence number corresponding to the message to be sent based on the Redis sequence number self-increment algorithm;
[0057] Please refer to Figure 2 , Figure 2 This is a framework diagram of the data processing method in the embodiment of the present application. The link of the data processing method is full-duplex, and the client can send and receive messages; the long connection service cluster is responsible for routing and broadcasting messages, and accurately delivering them to the corresponding clients; the server gateway is responsible for message forwarding, message aggregation, logging and message storage.
[0058] In this embodiment, the business service sends business request and other messages to the gateway (server gateway). The gateway receives the request from the business service and issues a unique serial number for the received message, that is, the gateway generates the first message serial number corresponding to the message to be sent based on the Redis serial number self-increment algorithm. Specifically, when the gateway receives the business message from the business service, the gateway generates the first message serial number corresponding to the business message based on the Redis serial number self-increment algorithm, and sends the first message serial number and the business message to the server; the server processes the business message and obtains the message to be sent corresponding to the business message; the server sends the first message serial number and the message to be sent to the client. Among them, the message serial number generated by the Redis serial number self-increment algorithm does not increase repeatedly, so that the first message serial number is not repeated.
[0059] In this embodiment, when the first message sequence number sent by the server and the message to be sent are received, the client obtains the second message sequence number corresponding to the pushed message. For example, the second message sequence number can be the maximum sequence number among the message sequence numbers of the messages currently pushed by the client, wherein the client maintains a message queue and the sequence number of the message just sent (i.e., the second message sequence number), and the client can directly obtain the second message sequence number.
[0060] Step S102, if the second message sequence number is continuous with the first message sequence number, sending the message to be sent;
[0061] In this embodiment, after obtaining the second message sequence number, the client determines whether the second message sequence number is continuous with the first message sequence number. If the second message sequence number is continuous with the first message sequence number, the to-be-sent message is sent to improve the message sending efficiency.
[0062] Step S103: if the second message sequence number is not continuous with the first message sequence number and the first message sequence number is greater than the second message sequence number, storing the to-be-sent message in a message queue based on the first message sequence number;
[0063] In this embodiment, if the second message sequence number is not continuous with the first message sequence number, the client determines at the same time whether the first message sequence number is greater than the second message sequence number. If the first message sequence number is greater than the second message sequence number, the client stores the message to be sent in the message queue based on the first message sequence number, and specifically stores the message to be sent in the message queue according to the first message sequence number and the third message sequence number of the current head message of the message queue, so as to store the message to be sent in the message pre-send queue (message queue) set by the client.
[0064] When a message to be sent is stored in a message queue, the enqueue timestamp of the message to be sent is determined. When there is a target message in the message queue whose timestamp has timed out (the enqueue duration has reached a preset time period), the client sends the target message. At the same time, according to the target message sequence number of the target message, the messages corresponding to the message sequence numbers with consecutive target message sequence numbers in the message queue are sent together. The batch sending is stopped only when the sequence number of the current head message in the queue is discontinuous and has not timed out.
[0065] Step S104: If the second message sequence number is not continuous with the first message sequence number and the first message sequence number is smaller than the second message sequence number, the message to be sent is discarded.
[0066] In this embodiment, if the second message sequence number is not continuous with the first message sequence number and the first message sequence number is smaller than the second message sequence number, it means that the message to be sent has a long delay and has lost its real-time performance, and the client discards the message to be sent.
[0067] In a feasible implementation manner, before step S101, the data processing method may further include steps S105 to S108:
[0068] Step S105, when receiving a service message from the service server, the gateway generates a first message sequence number corresponding to the service message based on the Redis sequence number self-increment algorithm;
[0069] Step S106, the gateway sends the first message sequence number and the service message to the server;
[0070] Step S107, the server processes the service message and obtains a message to be sent corresponding to the service message;
[0071] Step S108: The server sends the first message sequence number and the message to be sent to the client.
[0072] In this embodiment, the business service end sends messages such as business requests to the gateway (server gateway). The gateway receives the request from the business service end and issues a unique serial number for the received message, that is, the gateway generates a first message serial number corresponding to the message to be sent based on the Redis serial number self-increment algorithm. Specifically, when the gateway receives the business message from the business service end, the gateway generates a first message serial number corresponding to the business message based on the Redis serial number self-increment algorithm. The message serial number generated by the Redis serial number self-increment algorithm does not increment repeatedly, so that the first message serial number is not repeated.
[0073] Next, the gateway sends the first message sequence number and the service message to the server, and the server processes the service message to obtain a message to be sent corresponding to the service message; the server sends the first message sequence number and the message to be sent to the client.
[0074] The data processing method proposed in this embodiment is that when the client receives the first message sequence number sent by the server and the message to be sent, the client obtains the second message sequence number corresponding to the pushed message, wherein the gateway generates the first message sequence number corresponding to the message to be sent based on the Redis sequence number self-increment algorithm; then if the second message sequence number is continuous with the first message sequence number, the message to be sent is sent; then if the second message sequence number is not continuous with the first message sequence number and the first message sequence number is greater than the second message sequence number, the message to be sent is stored in the message queue based on the first message sequence number; if the second message sequence number is not continuous with the first message sequence number and the first message sequence number is less than the second message sequence number, the message to be sent is discarded; the message sequence number is generated by the Redis sequence number self-increment algorithm in the gateway to ensure the uniqueness of the sequence number of each day's message, so that the data received by the client is finally ordered, avoiding the problem of data fluctuations and inconsistency in time due to long connection data disorder, and improving the message sending efficiency of the client during long connection communication.
[0075] In a feasible implementation, step S103 may include steps S201 to S202:
[0076] Step S201, if the second message sequence number is not continuous with the first message sequence number and the first message sequence number is greater than the second message sequence number, then obtaining the third message sequence number of the current head message of the message queue;
[0077] Step S202: if the first message sequence number is smaller than the third message sequence number, the message to be sent is stored at the head of the message queue, so that the message to be sent is used as the current head message of the message queue;
[0078] Step S203: if the first message sequence number is greater than the third message sequence number, the message to be sent is stored at the end of the message queue, and the messages in the message queue are sorted.
[0079] In this embodiment, if the first message sequence number is greater than the second message sequence number, the client obtains the third message sequence number of the current head message of the message queue; the client determines whether the first message sequence number is less than the third message sequence number.
[0080] If the first message sequence number is less than the third message sequence number, the client stores the message to be sent at the head of the message queue to make the message to be sent the current head message of the message queue, that is, the message to be sent is the latest head message of the message queue.
[0081] In this embodiment, if the first message sequence number is greater than the third message sequence number, the client stores the message to be sent at the end of the message queue, that is, the message to be sent is the latest end message of the message queue.
[0082] Next, the client obtains the fourth message sequence number of each message in the message queue, wherein the fourth message sequence number includes the first message sequence number, and the fourth message sequence number may not include the third message sequence number.
[0083] After obtaining the fourth message sequence number, the client sorts the messages in the message queue based on the fourth message sequence number so that the messages in the message queue are re-sorted in order of message sequence numbers from small to large, wherein the message sequence number of the first message in the message queue after sorting is made smaller.
[0084] The data processing method proposed in this embodiment is as follows: if the second message sequence number is not continuous with the first message sequence number and the first message sequence number is greater than the second message sequence number, the third message sequence number of the current head message of the message queue is obtained; then if the first message sequence number is less than the third message sequence number, the message to be sent is stored at the head of the message queue to use the message to be sent as the current head message of the message queue; and then if the first message sequence number is greater than the third message sequence number, the message to be sent is stored at the end of the message queue, and the messages in the message queue are sorted, and the messages to be sent are stored in the message queue according to the message sequence number, so that the messages in the message queue are sorted messages, so as to improve the efficiency and accuracy of message sending by the client, and improve the message sending efficiency of the client during long connection communication.
[0085] In a feasible implementation manner, the data processing method may further include steps S301 to S304:
[0086] Step S301, upon receiving an aggregate message sent by a gateway, the server adds a message sending task corresponding to the aggregate message to a task slot corresponding to the time wheel;
[0087] Step S302, the server accumulates the number of tasks for message sending tasks in the task slot;
[0088] Step S303, if the number of tasks reaches a preset number, the server executes the message sending task in the task slot and clears the task slot;
[0089] Step S304: if the delay time corresponding to the time wheel reaches a preset time length, the server executes the message sending task in the task slot and clears the task slot.
[0090] In this embodiment, for scenarios with massive messages such as barrage, a message aggregation strategy can be used to send messages. Specifically, when receiving an aggregated message sent by a gateway, the server adds the message sending task corresponding to the aggregated message to the task slot corresponding to the time wheel. In a feasible implementation, step S301 may include steps S3011 to S3012:
[0091] Step S3011, if the aggregate message is the first aggregate message received, the server establishes a time wheel;
[0092] Step S3012: The server adds the message sending task corresponding to the aggregate message to the task slot corresponding to the time wheel.
[0093] In this embodiment, if the aggregate message received by the server is the first aggregate message received, the server establishes a time wheel, sets a preset duration of the time wheel and a preset number of task slots, and adds the message sending task corresponding to the aggregate message to the task slot corresponding to the time wheel.
[0094] It should be noted that if the aggregate message is not the first aggregate message, the server directly adds the message sending task of the aggregate message to the task slot corresponding to the time wheel.
[0095] Next, the server accumulates the number of message sending tasks in the task slot; if the number of tasks reaches a preset number, the server executes the message sending tasks in the task slot and clears the task slot to achieve aggregate message sending, which can reduce the number of communications, reduce bandwidth occupancy, facilitate use and improve resource utilization.
[0096] At the same time, when the delay time corresponding to the time wheel reaches the preset duration, the server executes the message sending task in the task slot and clears the task slot to realize the aggregate sending of messages, which can reduce the number of communications, reduce bandwidth occupancy, facilitate use and improve resource utilization.
[0097] It should be noted that after executing the message sending task in the task slot, when the server receives the aggregate message, the aggregate message is the first aggregate message.
[0098] The data processing method proposed in this embodiment adds the message sending task corresponding to the aggregate message to the task slot corresponding to the time wheel when receiving the aggregate message sent by the gateway; accumulates the task number of the message sending task in the task slot; if the task number reaches the preset number, executes the message sending task in the task slot and clears the task slot; if the delay time corresponding to the time wheel reaches the preset duration, executes the message sending task in the task slot and clears the task slot. In this way, the aggregate sending of messages can be realized, which can reduce the number of communications, reduce bandwidth occupancy, facilitate use and improve resource utilization.
[0099] In a feasible implementation manner, the data processing method may further include steps S401 to S403:
[0100] Step S401, the client sends a first heartbeat message based on a long connection at a first preset time interval;
[0101] Step S402, if the heartbeat response information corresponding to the server is not received, the first number is accumulated;
[0102] Step S403: if the first number reaches a preset threshold, the long connection is disconnected, and a long connection reconstruction operation is performed at a second preset time interval.
[0103] In this embodiment, in order to enhance the reliability of the long connection, a heartbeat mechanism is set on the client, and the client sends a first heartbeat message based on the long connection at a first preset time interval, that is, when the long connection survives, the client sends a first heartbeat message based on the long connection at a first preset time interval. In a feasible implementation, step S401 may also include steps S4011 to S4012:
[0104] Step S4011, determining whether the long connection is in a read-write idle state;
[0105] Step S4012: If the long connection is in a read-write idle state, a first heartbeat message is sent based on the long connection at a first preset time interval.
[0106] In this embodiment, the client can actually obtain the status of the long connection and determine whether the long connection is in a read-write idle state. If the long connection is in a read-write idle state, a first heartbeat message is sent based on the long connection at a first preset time interval to avoid the sending of the heartbeat message affecting the transmission of the message.
[0107] If the heartbeat response information corresponding to the server is not received, the client accumulates the first number. Specifically, if the heartbeat response information corresponding to the server is not received within the first preset time interval after sending the first heartbeat information, the client will add 1 to the first number and determine whether the first number reaches the preset threshold.
[0108] If the first number reaches the preset threshold, the client disconnects the persistent connection and performs the persistent connection reconstruction operation at a second preset time interval, i.e., reestablishes the persistent connection. If the reconnection is successful, the client will automatically restore to the state before the disconnection and support querying historical messages; if the reconnection fails, the client will trigger a callback to remind the user of the abnormality.
[0109] In a feasible implementation manner, the data processing method may further include steps S404 to S406:
[0110] Step S404, when the persistent connection survives, the server sends a second heartbeat message based on the persistent connection at a second preset time interval;
[0111] Step S405, if the server does not receive the heartbeat response information corresponding to the client, the server accumulates the second number;
[0112] Step S406: If the second number reaches a preset threshold, the server disconnects the persistent connection and deletes the cache information corresponding to the persistent connection.
[0113] In this embodiment, in order to enhance the reliability of the long connection, a heartbeat mechanism may also be set on the server side. Specifically, when the long connection is alive, the server side sends a second heartbeat message based on the long connection at a second preset time interval; wherein, the server side may determine whether the long connection is in a read-write idle state; if the long connection is in a read-write idle state, the server side sends a second heartbeat message based on the long connection at a second preset time interval.
[0114] If the server does not receive the heartbeat response information corresponding to the client, the server accumulates the second number; specifically, if the server does not receive the heartbeat response information corresponding to the client within the second preset time interval after sending the second heartbeat information, the client will add 1 to the second number and determine whether the second number reaches the preset threshold.
[0115] If the second number reaches a preset threshold, the server disconnects the persistent connection and deletes the cache information corresponding to the persistent connection, so as to save memory resources and maintain the health of the server cluster.
[0116] The data processing method proposed in this embodiment is that the client sends a first heartbeat message based on the long connection at a first preset time interval; then if the corresponding heartbeat response information of the server is not received, the first number is accumulated; then when the first number reaches a preset threshold, the long connection is disconnected, and the long connection reconstruction operation is performed at a second preset time interval. The reliability of the long connection is ensured by the heartbeat mechanism and disconnection reconnection, and the efficiency of message sending is further improved.
[0117] The data processing device provided in the embodiment of the present application adopts the data processing method in the above embodiment, which can solve the technical problem of how to improve the efficiency of message sending of the client during long connection communication. Compared with the prior art, the beneficial effects of the data processing device provided in the embodiment of the present application are the same as the beneficial effects of the data processing method provided in the above embodiment, and other technical features in the data processing device are the same as the features disclosed in the above embodiment method, which will not be repeated here.
[0118] The present application provides a data processing device, which includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the data processing method in the above-mentioned embodiment one.
[0119] Reference below Figure 3 , which shows a schematic diagram of the structure of a data processing device suitable for implementing an embodiment of the present application. The data processing device in the embodiment of the present application may include, but is not limited to, mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (Portable Application Descriptions), PMPs (Portable Media Players), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Figure 3 The data processing device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0120] like Figure 3As shown, the data processing device may include a processing device 1001 (e.g., a central processing unit, a graphics processor, etc.), which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM: Read Only Memory) 1002 or a program loaded from a storage device 1003 to a random access memory (RAM: Random Access Memory) 1004. In RAM1004, various programs and data required for the operation of the data processing device are also stored. The processing device 1001, ROM1002, and RAM1004 are connected to each other through a bus 1005. An input / output (I / O) interface 1006 is also connected to the bus. Generally, the following systems can be connected to the I / O interface 1006: an input device 1007 including, for example, a touch screen, a touch pad, a keyboard, a mouse, an image sensor, a microphone, an accelerometer, a gyroscope, etc.; an output device 1008 including, for example, a liquid crystal display (LCD: Liquid Crystal Display), a speaker, a vibrator, etc.; a storage device 1003 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 1009. The communication device 1009 can allow the data processing device to communicate with other devices wirelessly or by wire to exchange data. Although the data processing device with various systems is shown in the figure, it should be understood that it is not required to implement or have all the systems shown. More or fewer systems can be implemented or have alternatively.
[0121] In particular, according to the embodiments disclosed in the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present application include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication device, or installed from a storage device 1003, or installed from a ROM 1002. When the computer program is executed by the processing device 1001, the above-mentioned functions defined in the method of the embodiment disclosed in the present application are executed.
[0122] The data processing device provided by the present application adopts the data processing method in the above embodiment, which can solve the technical problem of how to improve the efficiency of message sending by the client during long connection communication. Compared with the prior art, the beneficial effects of the data processing device provided by the present application are the same as the beneficial effects of the data processing method provided by the above embodiment, and the other technical features in the data processing device are the same as the features disclosed in the method of the previous embodiment, which will not be repeated here.
[0123] It should be understood that the various parts disclosed in this application can be implemented by hardware, software, firmware or a combination thereof. In the description of the above embodiments, specific features, structures, materials or characteristics can be combined in any one or more embodiments or examples in a suitable manner.
[0124] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
[0125] The present application provides a computer-readable storage medium having computer-readable program instructions (ie, computer programs) stored thereon, wherein the computer-readable program instructions are used to execute the data processing method in the above-mentioned embodiment.
[0126] The computer-readable storage medium provided in the present application may be, for example, a USB flash drive, but is not limited to electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, systems or devices, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In this embodiment, the computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, system or device. The program code contained on the computer-readable storage medium may be transmitted using any appropriate medium, including but not limited to: wires, optical cables, RF (Radio Frequency), etc., or any suitable combination of the above.
[0127] The computer-readable storage medium may be included in the data processing device; or may exist independently without being installed in the data processing device.
[0128] The above-mentioned computer-readable storage medium carries one or more programs. When the above-mentioned one or more programs are executed by the data processing device, the data processing device: when receiving the first message sequence number sent by the server and the message to be sent, the client obtains the second message sequence number corresponding to the pushed message, wherein the gateway generates the first message sequence number corresponding to the message to be sent based on the Redis sequence number self-increment algorithm; if the second message sequence number is continuous with the first message sequence number, the message to be sent is sent; if the second message sequence number is not continuous with the first message sequence number and the first message sequence number is greater than the second message sequence number, the message to be sent is stored in the message queue based on the first message sequence number; if the second message sequence number is not continuous with the first message sequence number and the first message sequence number is greater than the second message sequence number, the message to be sent is discarded.
[0129] Computer program code for performing the operations of the present application may be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, C++, and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0130] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present application. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0131] The modules involved in the embodiments described in this application may be implemented by software or hardware, wherein the name of the module does not constitute a limitation on the unit itself in some cases.
[0132] The readable storage medium provided in this application is a computer-readable storage medium, which stores computer-readable program instructions (i.e., computer programs) for executing the above-mentioned data processing method, and can solve the technical problem of how to improve the efficiency of message sending by the client during long connection communication. Compared with the prior art, the beneficial effects of the computer-readable storage medium provided in this application are the same as the beneficial effects of the data processing method provided in the above-mentioned embodiment, and will not be repeated here.
[0133] An embodiment of the present application provides a computer program product, including a computer program, which implements the steps of the above-mentioned data processing method when executed by a processor.
[0134] The computer program product provided by the present application can solve the technical problem of how to improve the efficiency of message sending by the client during long connection communication. Compared with the prior art, the beneficial effects of the computer program product provided by the embodiment of the present application are the same as the beneficial effects of the data processing method provided by the above embodiment, which will not be repeated here.
[0135] The above are only preferred embodiments of the present application, and are not intended to limit the patent scope of the present application. Any equivalent structure or equivalent process transformation made using the contents of the present application specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present application.
Claims
1. A data processing method, It is characterized in that The data processing method comprises the following steps: When receiving the first message sequence number and the message to be sent sent by the server, the client obtains the second message sequence number corresponding to the pushed message, wherein the gateway generates the first message sequence number corresponding to the message to be sent based on the Redis sequence number self-increment algorithm; If the second message sequence number is continuous with the first message sequence number, sending the message to be sent; If the second message sequence number is not continuous with the first message sequence number and the first message sequence number is greater than the second message sequence number, storing the to-be-sent message in a message queue based on the first message sequence number; If the second message sequence number is not continuous with the first message sequence number and the first message sequence number is smaller than the second message sequence number, the message to be sent is discarded.
2. The data processing method according to claim 1, It is characterized in that If the second message sequence number is not continuous with the first message sequence number and the first message sequence number is greater than the second message sequence number, the step of storing the to-be-sent message in the message queue based on the first message sequence number includes: If the second message sequence number is not continuous with the first message sequence number and the first message sequence number is greater than the second message sequence number, obtaining the third message sequence number of the current head message of the message queue; If the first message sequence number is less than the third message sequence number, storing the message to be sent at the head of the message queue, so that the message to be sent is used as the current head message of the message queue; If the first message sequence number is greater than the third message sequence number, the message to be sent is stored at the end of the message queue, and the messages in the message queue are sorted.
3. The data processing method according to claim 1, It is characterized in that The data processing method further includes: When receiving the aggregate message sent by the gateway, the server adds the message sending task corresponding to the aggregate message to the task slot corresponding to the time wheel; The server accumulates the number of tasks for sending messages in the task slot; If the number of tasks reaches the preset number, the server executes the message sending task in the task slot and clears the task slot; If the delay time corresponding to the time wheel reaches a preset duration, the server executes the message sending task in the task slot and clears the task slot.
4. The data processing method according to claim 3, It is characterized in that The step of adding the message sending task corresponding to the aggregate message to the task slot corresponding to the time wheel includes: If the aggregate message is the first aggregate message received, the server establishes a time wheel; The server adds the message sending task corresponding to the aggregate message to the task slot corresponding to the time wheel.
5. The data processing method according to claim 1, It is characterized in that The data processing method further includes: The client sends a first heartbeat message based on the long connection at a first preset time interval; If the corresponding heartbeat response information from the server is not received, the first count is accumulated; If the first number reaches a preset threshold, the long connection is disconnected, and a long connection reconstruction operation is performed at a second preset time interval.
6. The data processing method according to claim 5, It is characterized in that The step of the client sending the first heartbeat information based on the long connection at a first preset time interval includes: Determine whether the long connection is in a read-write idle state; If the long connection is in a read-write idle state, a first heartbeat message is sent based on the long connection at a first preset time interval.
7. The data processing method according to claim 6, It is characterized in that The data processing method further includes: When the persistent connection survives, the server sends a second heartbeat message based on the persistent connection at a second preset time interval, wherein the second preset time interval is greater than the first preset time interval; If the server does not receive the corresponding heartbeat response information from the client, the server will accumulate the second number; If the second number reaches a preset threshold, the server disconnects the persistent connection and deletes the cache information corresponding to the persistent connection.
8. The data processing method according to any one of claims 1 to 7, It is characterized in that Before the step of obtaining the second message sequence number corresponding to the pushed message by the client upon receiving the first message sequence number sent by the server and the message to be sent, the data processing method further includes: When receiving a business message from the business server, the gateway generates the first message sequence number corresponding to the business message based on the Redis sequence number auto-increment algorithm; The gateway sends the first message sequence number and the service message to the server; The server processes the business message and obtains the message to be sent corresponding to the business message; The server sends the first message sequence number and the message to be sent to the client.
9. A data processing device, It is characterized in that The data processing device comprises: a memory, a processor, and a data processing program stored in the memory and executable on the processor, wherein the data processing program implements the steps of the data processing method according to any one of claims 1 to 8 when executed by the processor.
10. A computer-readable storage medium, It is characterized in that The computer-readable storage medium stores a data processing program, and when the data processing program is executed by a processor, the steps of the data processing method according to any one of claims 1 to 8 are implemented.
