Data processing methods, servers, computing devices, storage media, and software products
By generating and storing data packets through a logical thread, and sending them through a network thread when the identifier changes, the instability caused by direct network output from the logical thread is resolved, thus improving the stability and efficiency of business processing.
Patent Information
- Application Number
- CN202611234777.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-14
- Publication Date
- 2026-11-17
AI Technical Summary
In existing technologies, logical threads directly perform network input/output operations after completing business processing, resulting in unstable business processing time, which is greatly affected by fluctuations in network environment and number of connections.
The logic thread generates data packets to be sent and stores them in the shared space, updates the logical unit identifier, and the network thread retrieves them from the shared space and caches them in the buffer when the identifier changes, and sends them to the client in a centralized manner. The logic thread does not directly perform network output operations.
This reduces the number of network output operations, lowers communication latency and system call overhead, and improves the stability of frame latency in business processing.
Smart Images

Figure CN123114789A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of software technology for creating digital cultural products, and in particular to a data processing method. This application also relates to a server, a computing device, a computer-readable storage medium, and a computer program product. Background Technology
[0002] With the development of internet technology, in the fields of digital cultural product creation software and digital cultural creative software, the server side of large-scale multiplayer online applications often needs to maintain network communication for thousands of client connections simultaneously. The server typically adopts a multi-threaded architecture, where logic threads are responsible for advancing business processing round by round according to business logic units, and network threads are responsible for handling network input / output operations with clients. In each round of business processing, the logic threads generate a large number of data packets that need to be sent to each client; these data packets need to be sent to the corresponding clients through the network threads.
[0003] However, in existing technologies, logical threads often directly perform network input / output operations to send data packets after completing business processing. This results in the network output delay being included in the business processing time. The network output delay fluctuates greatly due to factors such as network environment and number of connections, leading to unstable frame processing time. Summary of the Invention
[0004] In view of this, embodiments of this application provide a data processing method to address the technical deficiencies existing in the prior art. Embodiments of this application also provide a server, a computing device, a computer-readable storage medium, and a computer program product.
[0005] According to a first aspect of the embodiments of this application, a data processing method is provided, applied to a server including logical threads and network threads, the method comprising: Through a logical thread, generate the data packets to be sent to the client and send them to the shared space; in response to the completion of the generation of each data packet to be sent within a business logic unit, update the logical unit identifier recorded in the shared space; The network thread detects whether the logical unit identifier has changed. If the logical unit identifier has changed, the data packets to be sent are obtained from the shared space and cached in the buffer. The data packets to be sent stored in the buffer are then sent to the corresponding clients.
[0006] According to a second aspect of the embodiments of this application, a server is provided, comprising: The network thread is configured to generate the data packets to be sent for the client and send them to the shared space; in response to the completion of the generation of each data packet to be sent within a business logic unit, the logic unit identifier recorded in the shared space is updated; The logical thread is configured to retrieve data packets to be sent from the shared space and cache them in a buffer, detect whether the logical unit identifier has changed, and if the logical unit identifier has changed, send each data packet to be sent stored in the buffer to the corresponding client.
[0007] According to a third aspect of the embodiments of this application, a computing device is provided, comprising: Memory and processor; The memory is used to store computer-executable instructions, and the processor executes the computer-executable instructions to implement the steps of the above data processing method.
[0008] According to a fourth aspect of the embodiments of this application, a computer-readable storage medium is provided that stores computer-executable instructions, which, when executed by a processor, implement the steps of the above-described data processing method.
[0009] According to a fifth aspect of the embodiments of this specification, a computer program product is provided, including a computer program / instructions that, when executed by a processor, implement the steps of the above-described data processing method.
[0010] The data processing method provided in this application is applied to a server that includes both logical threads and network threads. After the logical thread generates each data packet to be sent within a business logic unit, it only needs to update the logical unit identifier. The network thread detects whether the logical unit identifier has changed. If the logical unit identifier has changed, it retrieves the data packets to be sent from the shared space and caches them in a buffer. Then, it sends each data packet to be sent stored in the buffer to the corresponding client. This eliminates the need for direct network input / output operations, and the processing time no longer includes network output latency. The frame processing time is more stable, reducing the number of network output operations and lowering communication latency and system call overhead. Attached Figure Description
[0011] Figure 1 This is a flowchart of a data processing method provided in an embodiment of this application; Figure 2 This is a flowchart illustrating a data processing method for a server-side application in a large-scale multi-user application, provided by an embodiment of this application. Figure 3 This is a schematic diagram of the structure of a server provided in one embodiment of this application; Figure 4 This is a structural block diagram of a computing device provided in one embodiment of this application. Detailed Implementation
[0012] Many specific details are set forth in the following description to provide a full understanding of this application. However, this application can be implemented in many other ways different from those described herein, and those skilled in the art can make similar extensions without departing from the spirit of this application; therefore, this application is not limited to the specific embodiments disclosed below.
[0013] The terminology used in one or more embodiments of this application is for the purpose of describing particular embodiments only and is not intended to be limiting of the one or more embodiments of this application. The singular forms “a,” “the,” and “the” used in one or more embodiments of this application and the appended claims are also intended to include the plural forms unless the context clearly indicates otherwise. It should also be understood that the term “and / or” used in one or more embodiments of this application refers to and includes any or all possible combinations of one or more associated listed items.
[0014] It should be understood that although the terms first, second, etc., may be used to describe various information in one or more embodiments of this application, such information should not be limited to these terms. These terms are only used to distinguish information of the same type from one another. For example, first may also be referred to as second without departing from the scope of one or more embodiments of this application, and similarly, second may also be referred to as first.
[0015] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, data stored, data displayed, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties. Furthermore, the collection, use and processing of the relevant data must comply with the relevant laws, regulations and standards of the relevant regions, and corresponding operation entry points are provided for users to choose to authorize or refuse.
[0016] First, the terminology used in one or more embodiments of the present invention will be explained.
[0017] Atomic operations: One or more operations that cannot be interrupted in a concurrent environment. They either all succeed or none succeed. The execution process is uninterrupted, ensuring data consistency.
[0018] Non-atomic operations: Operation sequences consisting of multiple steps that may be interrupted or interfered with by other threads during execution, which can easily lead to data races or inconsistent states.
[0019] Circular array: A linear data structure that logically connects the first and last elements of an array to form a ring. It uses pointers to the first and last elements to reuse a fixed memory space, efficiently implementing a first-in-first-out queue without moving data. It is often used in scenarios such as audio buffering and streaming data processing.
[0020] This application provides a data processing method. This application also relates to a server, a computing device, a computer-readable storage medium, and a computer program product. These will be described in detail in the following embodiments.
[0021] Figure 1 This is a flowchart of a data processing method provided in an embodiment of this application, which specifically includes the following steps: Step 102: Generate the data packets to be sent for the client through the logical thread and send them to the shared space; in response to the completion of the generation of each data packet to be sent within a business logic unit, update the logical unit identifier recorded in the shared space; A logic thread is an execution unit on the server side responsible for processing business logic. It proceeds sequentially according to the business logic units, generating data packets to be sent and writing them to the shared space. It does not directly perform network input / output operations. For example, a logic thread can be the main thread in a game server responsible for scene calculation and event processing; or it can be a business processing thread on an application server, processing user requests and generating response data in an event-driven manner.
[0022] The data packet to be sent is data content generated by the logic thread and needs to be sent to the client via the network thread. It is used to carry business data pushed by the server to the client. For example, the data packet to be sent can be a protocol packet containing a protocol type identifier, a target client identifier, and protocol content data. For example, multiple data packets to be sent can be aggregated in the network thread and sent at once to reduce the number of system calls.
[0023] Shared space is a data storage area accessed by both logical threads and network threads, used for asynchronous data exchange between the two threads. The logical thread writes data packets, and the network thread reads them. For example, shared space can be a shared buffer in memory.
[0024] A business logic unit is the basic execution unit for a logic thread to perform business processing. Within a business logic unit, the logic thread completes a full round of business calculations, generating all the data packets to be sent to each client in that round. For example, in a game server, a business logic unit can be a processing cycle of one frame of game logic, during which the logic thread processes all player inputs, updates the game state, and generates the corresponding downlink data packets. For example, in an application server, a business logic unit can be a complete request processing batch processing cycle.
[0025] The logical unit identifier is a variable in the shared space that records the number of business logic units completed by the logical thread. The network thread determines whether there are new data packets to process by detecting changes in this identifier. For example, the logical unit identifier can be a network frame number, which the logical thread increments and publishes to the shared space after each round of business processing. For example, the logical unit identifier can also be a Boolean flag, which the logical thread flips after completing the current round of processing. The network thread detects the flip and begins acquiring and sending data packets for the current round.
[0026] The logic thread generates data packets to be sent to the client and sends them to the shared space. Specifically, in each round of business processing, the logic thread generates data packets that need to be sent to each client according to the business logic, and writes these data packets into the shared space between the logic thread and the network thread according to the preset queue sending rules.
[0027] One alternative implementation involves the logic thread encapsulating each data packet to be sent into a command object and writing it into the shared space via a lock-free circular buffer. During writing, only a simple write operation needs to be performed, without the need for locking or waiting for a response from the network thread. For example, the main thread of the game server generates movement synchronization packets and skill notification packets after processing player actions in each frame, and writes these packets one by one into the circular buffer of the shared space.
[0028] In response to the completion of the generation of each data packet to be sent within a business logic unit, the logical unit identifier recorded in the shared space is updated. Specifically, after the logic thread completes the generation and writing of all data packets to be sent within the current business logic unit, it updates the logical unit identifier recorded in the shared space through an atomic operation to inform the network thread that the data of the current business logic unit is ready.
[0029] One possible implementation is that the logic thread maintains a frame number counter, increments the frame number after each round of business processing, and publishes the new frame number to the logic unit identifier variable in the shared space through an atomic write operation with release semantics; for example, the main thread completes the status update of all players and the generation of downlink protocol packets in the current frame, increments the network frame number from 5 to 6 and writes it to the shared space through an atomic storage operation.
[0030] By having the logic thread update the logic unit identifier only after generating each data packet to be sent within a business logic unit, and handing over the actual network transmission of the data packets to the network thread, the business processing time of the logic thread no longer includes the network output delay. Fluctuations in the network environment and changes in the number of connections will not affect the stability of the logic frame, thus achieving complete decoupling between business processing and network transmission.
[0031] In one optional embodiment of this specification, the logical thread is configured to have a test read position; the logical thread generates the data packet to be sent corresponding to the client and sends it to the shared space, including: Generate the data packets to be sent for the client using a logical thread; Based on the preset queue sending rules, the system compares its own write position with the test read position. If the comparison result meets the queue sending rules, the data packet to be sent is sent to the shared space. If the comparison result does not conform to the queue sending rules, obtain the read position of the network thread in the shared space, and update the test read position based on the read position; Based on the queue sending rules, the system compares its own write position with the updated test read position to obtain the update comparison result; if the update comparison result conforms to the queue sending rules, the data packet to be sent is sent to the shared space. If the update comparison results do not conform to the queue sending rules, the sending operation is paused.
[0032] The test read position is a variable maintained locally by the logical thread to cache the current read position of the network thread in the shared memory. The test read position is used to quickly determine whether the shared memory is full when the logical thread writes a data packet to be sent, avoiding the need to access the actual read position of the network thread across cores for each write operation, thereby reducing cache miss latency caused by cross-core memory access. For example, the test read position can be an integer variable local to the logical thread, recording a snapshot of the network thread's read position last obtained from the shared memory; for example, the test read position is only updated locally by the logical thread, and the network thread does not access or modify this variable.
[0033] The write position is a pointer to the end of the data currently written by the logical thread in the shared space. It is used to record the starting index that the logical thread should use when writing data to the shared space next. Each time the logical thread writes a data packet to be sent, the write position moves forward accordingly. For example, the write position can be a write pointer maintained by the producer in a lock-free circular buffer, and the logical thread uses the write pointer to determine the slot for storing the next data packet.
[0034] Queue sending rules are predefined conditions used to determine whether a logical thread can currently write data packets to the shared space. These rules determine whether there is free space available for writing by comparing the write position with the read position. For example, a queue sending rule could be that the write position plus one is not equal to the read position, meaning writing is allowed when the queue is not full; alternatively, a queue sending rule could be that writing is allowed when the distance between the write position and the read position is less than the total queue capacity.
[0035] The logic thread generates the data packets to be sent to the client. Specifically, in each round of business processing, the logic thread generates the data packets that need to be sent to each client according to the business logic.
[0036] Based on the preset queue sending rules, the write position is compared with the test read position. If the comparison result meets the queue sending rules, the data packet to be sent is sent to the shared space. Specifically, before writing the data packet to be sent to the shared space, the logic thread first compares the test read position in the local cache with its own write position to determine whether there is any free space in the shared space. If there is free space according to the test read position in the local cache, the data packet to be sent is directly written to the shared space and the write position is updated.
[0037] One optional implementation involves using a lock-free circular buffer where the queue sending rule is that if the write position plus one is not equal to the test read position, the queue is not full. The logic thread checks the relationship between the current write position and the test read position; if this condition is met, the write operation is performed. Since the test read position is a local variable of the logic thread, this judgment process does not involve cross-core memory access, resulting in extremely low overhead. In most cases, the write speed of the logic thread is basically matched with the read speed of the network thread, and the test read position remains consistent with the actual read position. The logic thread can complete the write operation without accessing the actual read position of the network thread.
[0038] If the comparison result does not conform to the queue sending rules, obtain the read position of the network thread in the shared space, and update the test read position based on the read position. Specifically, when the logic thread determines that the queue may be full and cannot be written based on the test read position in the local cache, it can load the latest actual read position of the network thread from the shared space through an atomic operation with get semantics, and update the local test read position with this value.
[0039] One possible implementation is that the logical thread performs an atomic load operation to read the read position of the network thread from the shared memory, assigns the value to the local test read position variable, and completes the refresh of the local cache; for example, the logical thread finds that the write position plus one equals the test read position, and judges that the queue may be full. At this time, it performs an atomic load operation to obtain the actual read position of the network thread, and finds that the network thread has consumed some data forward, and there is still free space in the actual queue.
[0040] Based on the queue sending rules, the write position is compared with the updated test read position to obtain the update comparison result. If the update comparison result meets the queue sending rules, the data packet to be sent is sent to the shared space. Specifically, the logic thread can use the updated test read position to perform the queue full check again. If there is free space after the update, the write operation is performed.
[0041] If the update comparison result does not conform to the queue sending rules, the sending operation is paused. Specifically, if the queue is still determined to be full after the update, it means that the network thread has not yet finished consuming the data in the queue. The logic thread then pauses the writing of the current data packet and waits for the next sending opportunity or takes other processing strategies.
[0042] This specification describes an implementation scenario applied to a data processing scenario in a large-scale multiplayer online game server. Data is transferred between the server's logic thread and network thread via a lock-free circular buffer. The logic thread maintains a test read position variable locally, initialized to zero. In the current frame, the logic thread generates a data packet to be sent and writes it to the shared space. The logic thread reads its own write position as 100, its local test read position as 50, and the total queue capacity as one million. According to the queue sending rules, the write position is incremented by one and the modulo operation is performed on the queue capacity, which is 101. This is not equal to the test read position of 50, so the queue is not full. The logic thread directly writes the data packet to be sent to slot 100 of the shared space and updates the write position to 101. The entire judgment and writing process only accesses the local variable and does not access the network thread's read position across cores.
[0043] In the next frame, the logical thread's write position is 999999, and the test read position is 0. The logical thread calculates the write position, adds one, and takes the modulo, which equals 0, the test read position. Based on the queue sending rules, it determines that the queue may be full. The logical thread uses an atomic load operation with get semantics to read the latest actual read position from the shared space from the network thread. It finds that the network thread has consumed data up to position 500, and the actual queue still has a lot of free space. The logical thread updates the test read position to 500, and again checks the write position, adding one and taking the modulo, which equals 0, not the updated test read position 500. The queue is not full, and the data packet to be sent is written to the shared space. Through the position caching mechanism, the logical thread only performs cross-core read operations when the queue is close to full; in most cases, data writing can be completed simply by accessing local variables.
[0044] By maintaining a local cache of the network thread's read position for testing read positions within the logic thread, the logic thread only needs to access a local variable to determine if there is free space in the queue during most write operations. Only when the queue is nearly full does it atomically retrieve the network thread's actual read position across cores. This mechanism reduces the frequency of cross-core memory access from every write operation to only when the queue is nearly full, significantly reducing the latency overhead of cross-core cache misses and improving the efficiency and throughput of data transfer between threads.
[0045] Step 104: Detect whether the logical unit identifier has changed through the network thread. If the logical unit identifier has changed, obtain the data packets to be sent from the shared space and cache them in the buffer. Send each data packet to be sent stored in the buffer to the corresponding client.
[0046] A network thread is an execution unit on the server side used to handle network communication with clients. The network thread is responsible for detecting changes in the logical unit identifiers in the shared space. When an identifier changes, it retrieves data packets to be sent from the shared space and sends them in batches to the corresponding clients. This centralized execution of network output operations ensures that the processing time of the logical thread no longer includes network output latency. For example, a network thread could be a network communication thread on the server side responsible for managing all client connections and delivering data packets.
[0047] A buffer is a data storage area maintained internally by the network thread to temporarily store data packets to be sent, retrieved from the shared space. The buffer is used to batch-fetch data packets from the shared space to the network thread's local storage, and then send them uniformly to the corresponding clients, reducing frequent access to the shared space. For example, the buffer can be a memory area allocated locally by the network thread; alternatively, it can be a data packet aggregation buffer corresponding to each client connection. The network thread distributes data packets read from the shared space to the corresponding client's buffer according to the target client identifier, accumulating the data packets from each client by classifying and temporarily storing them according to the target client, so that data aggregation can be performed during subsequent unified sending, merging multiple data packets from the same client within the same business logic unit into a single network sending operation.
[0048] For example, the network thread maintains an aggregation buffer for each connection channel, accumulating the data packets to be sent from the shared space into the aggregation buffer. The aggregation buffer triggers a refresh send operation when either of the following conditions is met: First, when the available space in the aggregation buffer is insufficient, for example, when the accumulated data volume is close to the maximum transmission unit size, the network thread actively merges the accumulated data packets to be sent into a single network send call to aggregate and send multiple downlink protocol packets within the same business logic unit of the same connection channel; second, when the network thread detects that the network frame number of the connection channel has advanced to a new frame value while traversing the connection channel, and the current frame has not yet undergone a refresh send operation for that connection channel, the network thread forcibly sends the cached data packets to be sent in the aggregation buffer. The refresh send operation is executed based on the first of the two conditions triggered. After execution, the data already sent in the aggregation buffer is cleared, and the refresh frame number recorded for that connection channel is updated to the current network frame number.
[0049] The network thread detects whether the logical unit identifier has changed. If the logical unit identifier has changed, it retrieves the data packets to be sent from the shared space and caches them in the buffer. Specifically, the network thread can read the logical unit identifier in the shared space through an atomic loading operation in its own processing loop and compare it with the identifier value of the previous round cached locally. If the identifier value has changed, it means that the logical thread has completed a new round of business processing and generated new data packets to be sent. The network thread then reads these data packets from the shared space and distributes them to the corresponding client's buffer for accumulation according to the target client identifier carried by each data packet.
[0050] One possible implementation is that the network thread maintains a local variable to record the identifier of the logical unit processed in the previous cycle. At the beginning of each loop, it reads the latest logical unit identifier published by the logical thread in the shared space through an atomic load operation with retrieval semantics. If the two are the same, it means that the logical thread has not yet completed the new round of business processing, and the network thread skips the data retrieval step. If the two are different, the network thread updates the local record with the latest identifier value, and then reads the data packets to be sent one by one from the shared space, and caches them in the buffer of the corresponding client connection according to the user identifier carried by each data packet.
[0051] The data packets to be sent stored in the buffer are sent to the corresponding clients. Specifically, after the network thread has read and cached all the data packets to be sent in the current business logic unit, it can traverse each client connection and send the data packets accumulated in the corresponding buffer to the client at once through the operating system network interface for each connection.
[0052] One optional implementation involves the network thread checking whether the frame number of each client connection matches the current network frame number during the processing loop. If they do not match, a refresh operation is triggered for that connection, merging multiple data packets aggregated in the buffer into a single network send call. Multiple downlink protocol packets within the same frame from the same connection are aggregated and sent at once, significantly reducing the number of system calls. Alternatively, during the processing loop of the network thread traversing each connection channel, the network frame number at the time of the last refresh send is recorded for each connection channel. When the current network frame number is detected to be greater than the recorded frame number, it indicates that a new frame has been advanced but the current frame has not yet been refreshed for that connection. In this case, a second refresh operation is triggered, merging the existing data packets in the aggregation buffer into a single network send call and updating the recorded frame number to the current network frame number.
[0053] By detecting changes in the logical unit identifier via a network thread and then batch acquiring and sending data packets, the timing of data packet transmission is completely decoupled from the business processing of the logical thread. The logical thread does not participate in any network output operations, and the frame latency of business processing is no longer affected by network latency fluctuations, thus improving the stability of frame latency. At the same time, the centralized batch sending by the network thread reduces the number of network output operations, thereby reducing communication latency and system call overhead.
[0054] In one optional embodiment of this specification, the network thread is configured to have a test write position; retrieving data packets to be sent from the shared space and buffering them includes: Based on the preset queue receiving rules, the system compares its own read position with the test write position. If the comparison result meets the queue receiving rules, the system retrieves the data packet to be sent from the shared space and caches it in the buffer. If the comparison result does not conform to the queue receiving rules, obtain the write position of the logical thread in the shared space, and update the test write position based on the write position; Based on the queue receiving rules, the system compares its own read position with the updated test write position to obtain the update comparison result; if the update comparison result conforms to the queue receiving rules, the system retrieves the data packet to be sent from the shared space and caches it in the buffer. If the update comparison results do not conform to the queue receiving rules, the acquisition operation is paused.
[0055] The test write position is a variable maintained locally by the network thread to cache the current write position of the logical thread in the shared memory. The test write position is used by the network thread to quickly determine whether there is data to be read in the shared memory when reading data packets to be sent, avoiding the need to access the actual write position of the logical thread across cores for each read operation, thereby reducing cache miss latency caused by cross-core memory access. For example, the test write position can be an integer variable local to the network thread, recording a snapshot of the logical thread's write position last obtained from the shared memory.
[0056] The read position is a pointer to the location of data currently read by the network thread in the shared memory. It records the starting index to be used when the network thread reads data from the shared memory again. The read position moves forward accordingly each time the network thread reads a data packet to be sent.
[0057] Queue reception rules are predefined rules used to determine whether a network thread can currently read data packets to be sent from the shared space. For example, a queue reception rule could be that the read position is not equal to the write position, meaning reading is allowed when the queue is not empty.
[0058] Based on preset queue reception rules, the network thread compares its read position with the test write position. If the comparison matches the queue reception rules, it retrieves the data packet to be sent from the shared space and caches it in the buffer. Specifically, the network thread can first use the locally cached test write position to determine if the queue is not empty. If not empty, it directly reads the data packet; this judgment process does not involve cross-core memory access. If the comparison does not match the queue reception rules, it retrieves the logical thread's write position in the shared space and updates the test write position. Specifically, when the local cache determines that the queue may be empty, it uses an atomic operation to retrieve the logical thread's actual write position across cores to refresh the local cache, then checks again before executing a read or pausing. This mechanism forms a symmetrical design with the logical thread's test read position, ensuring that in most cases, the network thread only needs to access local variables to complete data reading.
[0059] By maintaining the test write position cache locally on the network thread, the write position of the logical thread is cached. The actual write position is only retrieved across cores when the queue is nearly empty. This forms a symmetrical and complementary mechanism with the test read position mechanism on the logical thread side, and together they significantly reduce the cross-core cache miss latency of data transfer between threads.
[0060] In one optional embodiment of this specification, the data packet to be sent carries the user identifier of the corresponding client; obtaining the data packet to be sent from the shared space and caching it in the buffer includes: Retrieve data packets to be sent from the shared space; Based on the user identifier, determine the buffer to which the client belongs for each data packet to be sent; Each data packet to be sent is cached in the buffer belonging to the corresponding client.
[0061] A user identifier is information carried in the data packet to be sent to identify the target client. The user identifier is used to allocate data packets to the corresponding client's buffer after they are retrieved from the shared space, ensuring that each data packet is ultimately delivered accurately to the correct client connection. For example, a user identifier can be a unique identifier for the client connection, a player character identifier, or a session identifier.
[0062] A buffer is a storage area maintained internally by the network thread for each client to temporarily store data packets to be sent. The buffer is used to group and cache data packets by client; all data packets to be sent from the same client are grouped into the same buffer, and subsequent transmissions can deliver them to that client in batches. For example, the network thread can maintain a separate data packet buffer queue for each online client.
[0063] Retrieving data packets to be sent from the shared space can specifically involve the network thread reading all data packets generated by the logical thread within the current business logic unit from the shared space after detecting a change in the logical unit identifier.
[0064] One possible implementation is that the network thread reads data packets from the shared space in a loop through a lock-free circular buffer, and updates the read position after each data packet is read, until the read position catches up with the write position of the logic thread, indicating that all data packets to be sent in the current business logic unit have been read.
[0065] Each data packet to be sent is cached in the corresponding client's buffer. Specifically, the network thread can copy the content of the data packet to be sent to the aggregation buffer of the corresponding client connection, so that the data packet and other data packets to be sent by the client in this frame are accumulated in the same buffer, waiting for subsequent unified transmission.
[0066] One possible implementation is that the network thread calls the sending interface of the packetizer connected to the corresponding client to write the data packet content into the packetizer's internal buffer. If the buffer space is insufficient or it is time to send, the packetizer sends the accumulated data to the client all at once through the operating system's network interface.
[0067] By grouping and caching data packets to be sent into corresponding buffers based on user identifiers, the data packets are organized in an orderly manner according to the target client before being sent. During transmission, data packets for the same client can be delivered in batches, reducing the repetitive operations on each client connection when sending one by one, thus improving data packet delivery efficiency and network output processing capabilities.
[0068] In one optional embodiment of this specification, the network thread is configured to have independent connection channels with multiple clients; sending each data packet to be sent stored in the buffer to the corresponding client includes: Iterate through each connection channel, and for the target connection channel currently being iterated, send each data packet to be sent stored in the buffer corresponding to the target connection channel to the target client corresponding to the target connection channel; The network thread continues to iterate through each connection channel until all data packets stored in the buffer have been sent to the corresponding clients.
[0069] A connection channel is an independent network communication path established between a network thread and each client. Each connection channel corresponds to a unique client, and the network thread sends data to and receives data from the corresponding client through each connection channel. Connection channels are used to isolate data transmission and reception between different clients. The network thread can process data transmission on a connection-by-connection basis, preventing data transmission from one client from blocking communication from other clients. For example, a connection channel can be a socket connection established based on the Transmission Control Protocol (TCP), with each connected client corresponding to a connection object in the network thread. The connection object internally maintains the send and receive buffers for that channel. Alternatively, a connection channel can be a communication port based on the User Datagram Protocol (UDP), with each client corresponding to an independent port identifier.
[0070] The process iterates through each connection channel. For the target connection channel currently being iterated, each data packet to be sent stored in the buffer corresponding to the target connection channel is sent to the target client corresponding to the target connection channel. Specifically, after the network thread distributes all data packets to be sent in the current business logic unit to the buffers of each connection channel according to the client, it starts to traverse all active client connection channels in sequence. For each traversed connection channel, it checks whether there are data packets to be sent in its buffer. If there are, it triggers the send refresh operation of that channel and sends all the data packets accumulated in the buffer to the corresponding client at once through the operating system network interface.
[0071] One alternative implementation is that the network thread iterates through each connection object in the connection array in each processing loop, checks whether the packet of the currently iterated connection object needs to be refreshed and sent, and if so, sends the aggregated data in the packet through the socket of that connection all at once; for example, when the network thread iterates through the 3rd client connection, it detects that the packet buffer has accumulated a mobile synchronization packet and a health update packet, and calls a send system call to merge the two data packets and send them to the 3rd client.
[0072] The network thread continues to iterate through each connection channel until all data packets stored in the buffer have been sent to the corresponding client. Specifically, after completing the sending of the current connection channel, the network thread continues to iterate through the next connection channel in the connection array, repeatedly performing the send refresh operation until all data packets in the buffers of all active connection channels have been sent.
[0073] An alternative implementation involves using a connection-level scheduling method for network threads. The packet processing of each connection channel is strictly limited to the data range of the current connection. After processing one connection, the system immediately switches to the next connection, preventing the blocking of other connections from taking too long due to the large amount of data in one connection.
[0074] One optional implementation involves the network thread, during its processing loop iterating through each connection channel, directly executing the connection management protocol and heartbeat detection protocol for the currently iterated target connection channel, in addition to sending data packets from the buffer. This is done without reporting related events to the logic thread for processing instructions. Specifically, the network thread maintains a heartbeat timer for each connection channel. During iteration, it checks if the heartbeat timer for each channel has timed out. If it does, it marks the connection channel as disconnected and performs a disconnection operation. The connection management protocol includes at least one of connection establishment, connection termination, and reconnection. For example, when the network thread receives a connection request from a new client, it directly completes the connection establishment process and initializes the connection channel's state information. When the network thread detects a client heartbeat timeout or connection anomaly during iteration, it directly performs the disconnection and recycling operation for that connection channel. When a client initiates reconnection, the network thread directly handles the establishment of a new connection and the replacement of the old connection state; the entire process is not coordinated by the logic thread.
[0075] By iterating through each connection channel and sending data packets to their corresponding buffers, each client's data packets are sent independently by channel. Data packets within the same channel are processed in batches, while different channels do not interfere with each other, improving the organization and efficiency of data packet transmission. Furthermore, concentrating the sending operations into a single iteration reduces the number of network thread scheduling operations and system call overhead.
[0076] In one optional embodiment of this specification, the connection channel records a status identifier, which is initially in a non-receiving state. The method further includes: In response to the arrival of a data packet to be received on the first connection channel, the status flag of the first connection channel is changed to the receiving status, wherein the first connection channel is any one of the connection channels; The network thread iterates through each connection channel. For the target connection channel currently being iterated, the status flag of the target connection channel is checked. If the status flag is in the "waiting to receive" state, the data packet to be received from the client to which the target connection channel belongs is obtained. After obtaining the data packet, the status flag of the target connection channel is changed to the "non-receiving" state. The data packet to be received is then sent to the shared space for the logic thread to obtain.
[0077] Status flags are recorded on each connection channel to indicate whether a data packet has arrived for that connection. This allows the network thread to quickly determine which connections have data to receive when iterating through the connection channels, and only perform the receive operation on connections with data arrival, avoiding indiscriminate receive calls on all connections. Status flags include at least two values: a pending receive state and a non-receive state. For example, the status flag can be a Boolean variable within the connection object, where a true value indicates that the connection has data to receive, and a false value indicates that the connection currently has no data to read. Alternatively, the status flag can be a value from a connection status enumeration, which the network thread uses to determine whether to invoke the receive operation when processing a connection.
[0078] The data packet to be received is an uplink data packet sent by the client to the server, which has reached the connection channel maintained by the network thread but has not yet been read by the network thread. This data packet carries business requests or status update information sent by the client to the server. After being read by the network thread, it is passed to the shared space for the logic thread to retrieve and process. For example, the data packet to be received could be an operation command packet sent by a player after performing an action on the client, such as a movement command or a skill release command; for example, the data packet to be received could also be a heartbeat packet or a status synchronization packet sent periodically by the client.
[0079] The shared space is a thread-shared storage area used by network threads and logic threads to pass data packets to be received. Network threads write data packets to be received from the client into the shared space, while logic threads read these data packets from the shared space and perform business processing. For example, the shared space can be another lock-free circular buffer in the opposite direction to the transmission of data packets to be sent, where the network thread acts as a producer writing upstream data, and the logic thread acts as a consumer reading upstream data.
[0080] In response to the arrival of a data packet to be received on the first connection channel, the status flag of the first connection channel is changed to the receiving state. Specifically, the network thread may wait for and obtain the set of connections triggered by the data arrival event through the I / O multiplexing mechanism provided by the operating system during its own I / O event processing phase, and change the status flag of each connection channel with data arrival from the non-receiving state to the receiving state.
[0081] One possible implementation is that the network thread calls the I / O multiplexing wait function in each loop to obtain a list of sockets with I / O events, iterates through the event list, and for the socket that triggered the read event, obtains the corresponding connection index through the user data bound to the socket, and sets the status flag of the connection to true, indicating that the connection has data to be received; for example, after the network thread calls the event wait function, it obtains three socket events with data arrival, corresponding to client connections 1, 5 and 8 respectively, and sets the status flag of these three connections to the pending reception state.
[0082] The network thread iterates through each connection channel. For the target connection channel currently being iterated, the status flag of the target connection channel is checked. If the status flag is in the "waiting to receive" state, the data packets to be received from the client to which the target connection channel belongs are obtained. After obtaining the data packets, the status flag of the target connection channel is changed to the "non-receiving" state. Specifically, the network thread can iterate through all active connection channels in sequence in the connection processing loop. For each connection channel, the status flag is first checked to see if it is in the "waiting to receive" state. If it is in the "waiting to receive" state, the receive operation is called to read the data packets that have arrived from the socket of that connection in a loop. After reading the data packets, the status flag is reset to the "non-receiving" state.
[0083] One possible implementation is that the network thread traverses the connection array, checks the status flag of the currently traversed connection, and if the status flag is non-receiving, skips the connection and does not call any receive operation; if the status flag is waiting to be received, the receive system call is called repeatedly to read uplink data packets from the socket of the connection until an indication that there is no more data is returned. After reading is completed, the status flag of the connection is reset to non-receiving and waits for the next IO event to be triggered.
[0084] The data packets to be received are sent to the shared space for the logic thread to retrieve. Specifically, the network thread may read the data packets to be received from the client connection channel and write them into the shared space between the network thread and the logic thread through the inter-thread communication mechanism. The logic thread then reads the data packets from the shared space and performs business processing in its own business processing loop.
[0085] One possible implementation is that the network thread encapsulates the read uplink data packets into a result object and writes it into the lock-free circular buffer of the logic thread. At the beginning of each frame, the logic thread reads all client uplink data packets to be processed from the buffer and performs corresponding business logic processing.
[0086] By setting status flags on the connection channels, the network thread can uniformly manage the receiving operations of multiple channels through traversal and status checks. Channels waiting to receive data are processed in batches after being marked, while channels without data are skipped directly. This improves the efficiency and management convenience of the network thread when handling multiple client connections. At the same time, received data packets are passed to the logic thread through a shared space, maintaining bidirectional asynchronous decoupling of data flow.
[0087] In one optional embodiment of this specification, obtaining the data packet to be received from the client to which the target connection channel belongs includes: If the number of data packets to be received meets the preset receiving threshold and the number of currently disconnected channels is less than the preset disconnection threshold, disconnect the target connection channel and continue to perform the operation of traversing each connection channel.
[0088] The preset receive threshold is a limit on the maximum number of data packets a network thread can acquire from a single connection channel in a single processing cycle. This threshold prevents an excessive number of uplink data packets from being generated within a single frame due to abnormal client packet sending or malicious attacks, which could cause the network thread to be blocked for an extended period, affecting data transmission and reception on other connections. For example, the preset receive threshold can be set to 256 data packets per connection per frame. This value far exceeds the normal packet sending frequency of a player, who typically sends only a few data packets per frame, thus not triggering this limit. For example, the preset receive threshold can also be configured and adjusted based on the server's processing capacity and business scenarios.
[0089] The preset disconnect threshold is a global upper limit used to restrict the maximum number of connections that a network thread can disconnect in a single frame. This threshold controls the number of connections kicked out in high-load scenarios, preventing a large number of connections from being simultaneously disconnected due to CPU overload. This prevents players from reconnecting en masse, further exacerbating CPU load and creating a cascading failure. For example, the preset disconnect threshold can be set to 8 connections per frame. Even if multiple connections simultaneously meet the kickout criteria, only a maximum of 8 connections will be disconnected in that frame, with the remaining eligible connections being processed in subsequent frames.
[0090] If the number of data packets to be received meets the preset receiving threshold and the number of currently disconnected channels is less than the preset disconnection threshold, the target connection channel is disconnected and the operation of traversing each connection channel continues. Specifically, when the network thread performs a receiving operation on a certain connection channel, it counts the number of data packets received in the current frame of that connection. When the number of received data packets reaches the preset receiving threshold, it checks whether the number of disconnected connections in the current frame has not yet reached the preset disconnection threshold. If it has not reached the threshold, the current connection is marked as disconnected and kicked out, the count of disconnected connections is incremented by one, and then the network thread continues to traverse the next connection channel without interrupting the entire traversal process due to the processing of the current connection.
[0091] One optional implementation involves the network thread counting the number of data packets successfully read in each connection's receive loop. When the number of data packets read from the current connection in a frame reaches a preset receive threshold of 256, a rate limiting judgment is triggered. The network thread checks the global disconnected connection count variable for the current frame. If the value is less than the preset disconnected threshold of 8, the current connection is marked as disconnected, the reason for disconnection is set as exceeding the packet receive limit, a disconnect operation is called to close the connection, and the global disconnected count is incremented. If the disconnected count has reached 8, no disconnect operation is performed; only the current connection's receive is stopped, and processing continues in the next frame or by other mechanisms. Subsequently, the network thread directly jumps out of the current connection's receive loop and continues to traverse the next connection channel. Alternatively, the preset receive threshold is much higher than the normal player's packet sending frequency. Normal players typically only send a few data packets per frame, so normal players will never trigger the packet receive limit during normal operation. This mechanism only applies to clients with abnormal behavior and will not harm normal players.
[0092] This specification describes an implementation of a data processing scenario applied to a large-scale multiplayer online game server. The server's network thread is traversing each connection channel at a connection granularity, performing receive operations. The preset receive threshold is 256 data packets, and the preset disconnection threshold is 8 connections. When the network thread encounters a connection and detects its status as "awaiting reception," it begins a loop of calling the receive system call to read the uplink data packets for that connection. The client corresponding to this connection may be using an accelerator or engaging in malicious packet sending behavior, resulting in a large number of data packets being sent within a single frame. The network thread increments the receive count for that connection for each data packet read. When the receive count reaches 256, the network thread checks the global disconnection count variable for this frame; the current value is 2, which is less than the preset disconnection threshold of 8. The network thread marks this connection as disconnected, sets the disconnection reason to "received packets exceeding the limit," calls the disconnection operation to close the connection, and increments the global disconnection count to 3. The network thread then stops receiving data from this connection and continues traversing the next connection channel.
[0093] In subsequent iterations of this frame, five more connections were disconnected for various reasons, bringing the global disconnect count to 8. When another connection with the same received data packet count of 256 was encountered, the network thread checked that the global disconnect count was 8, which was not less than the preset disconnect threshold of 8. Therefore, no disconnection operation was performed; only reception of that connection was stopped, and the connection was allowed to continue processing in the next frame. Through this dual rate limiting mechanism, a maximum of only eight connections were disconnected in this frame, avoiding the impact on the server caused by a large number of connections being disconnected simultaneously and then reconnecting.
[0094] By actively disconnecting the connection channel when the number of received data packets reaches a threshold and the current number of disconnections has not exceeded the upper limit, the network thread can proactively manage connections that may be abnormal or need to be reclaimed. At the same time, by controlling the upper limit of the number of disconnections, it is possible to prevent too many connections from being disconnected in a single round of traversal, thus preventing the impact on service stability and achieving controllable reclamation of connection resources.
[0095] The following is in conjunction with the appendix Figure 2 Taking the application of the data processing method provided in this application in a large-scale multiplayer online server as an example, the data processing method will be further explained. Among other things, Figure 2 This is a flowchart illustrating a data processing method for a server-side application in a large-scale, multi-user application, according to an embodiment of this application. The method specifically includes the following steps: Step 202: Shared space initialization: A shared space, including a circular buffer and logical unit identifiers, is set up in shared memory accessible to both logical threads and network threads. The capacity of the circular buffer is set to a preset value (e.g., 2 to the power of 20), and indexing is performed using bitwise operations. The circular buffer maintains write positions (maintained by the logical thread) and read positions (maintained by the network thread). The logical unit identifier is used to indicate the current business processing progress, with an initial value of zero. An independent buffer is allocated for each connection channel to buffer data packets to be sent to the corresponding client of that connection channel, and the status flag is set to non-receiving state.
[0096] Step 204: Logical thread data processing and enqueueing: A logic thread executes one round of business logic processing (e.g., game logic calculation for one frame). During this process, it generates data packets to be sent to various clients, each carrying the user identifier of the corresponding client. The logic thread writes the data packets to be sent into a circular buffer in the shared space. During writing, it compares its own write position with the test read position to determine if it conforms to the queue sending rules (e.g., the write position and test read position do not conflict, i.e., the circular buffer is not full). The test read position is the read position of the network thread cached locally by the logic thread. If it conforms to the queue sending rules, it writes the data packet to be sent into the circular buffer and updates the write position; if it does not conform (e.g., the circular buffer is close to full), it loads the actual read position of the network thread from the atomic variable in the shared space, updates the local test read position, and compares again. If it conforms, it writes; otherwise, it pauses the sending operation (e.g., blocking and waiting or returning failure). This process is repeated until all data packets generated in this round of business logic processing have been written into the circular buffer. After writing is complete, the logic thread updates the logical unit identifier recorded in the shared space (e.g., increments), does not perform any network input / output operations, and returns to execute the next round of business logic processing.
[0097] Step 206: Network thread dequeueing and routing: The network thread checks whether the logical unit identifier recorded in the shared space has changed (e.g., whether it is not equal to the identifier value recorded in the previous round). If no change has occurred, it pauses for a preset time (e.g., sleeps for 10 milliseconds) and then checks again. If a change has occurred, it retrieves the data packet to be sent from the circular buffer. During retrieval, it compares its own read position with the test write position to determine whether it conforms to the queue reception rules (e.g., the read position and test write position do not conflict, i.e., the circular buffer is not empty). The test write position is the logical thread's write position cached locally by the network thread. If it conforms to the queue reception rules, it reads the data packet to be sent from the circular buffer and updates the read position; if it does not conform (e.g., the circular buffer is close to empty), it loads the logical thread's actual write position from the atomic variable in the shared space, updates the local test write position, and then compares again. If it conforms, it reads; otherwise, it ends the current round of data retrieval. The above process is repeated until there are no more data packets to be sent that can be read in the circular buffer. After retrieval, the network thread routes each data packet to be sent to the corresponding connection channel's buffer based on the user identifier carried in each data packet.
[0098] Step 208: Event-driven reception, rate limiting, and transmission: The network thread uses an I / O multiplexing mechanism to detect the arrival status of data on each connection channel, changing the status flag of the connection channel with data arrival events to the "awaiting" state. Then, it iterates through each connection channel, performing the following operations on the currently iterated target connection channel: It checks the status flag of the target connection channel; if it's in the "awaiting" state, it retrieves the data packets to be received from the client belonging to that connection channel, and changes the status flag to the "non-receiving" state after retrieval; if it's in the "non-receiving" state, it skips the receiving operation. During the retrieval of data packets to be received, if the number of data packets retrieved by the current connection channel in this round of iteration meets a preset receiving threshold (e.g., reaching 256), it checks whether the number of disconnected connection channels in the current round is less than a preset disconnection threshold (e.g., the default value is 8). If it is less, it disconnects the target connection channel and increments the disconnection count; if it is not less, it does not disconnect. During iteration, each data packet to be sent stored in the target connection channel's buffer is sent to the corresponding client, and the process continues to traverse the next connection channel until all connection channels have been traversed, returning to step 206.
[0099] Corresponding to the above method embodiments, this application also provides server-side embodiments. Figure 3 This is a schematic diagram of the structure of a server provided in one embodiment of this application. For example... Figure 3 As shown, the server includes: Logic thread 302 is configured to generate data packets to be sent to the client and send them to the shared space; in response to the completion of the generation of each data packet to be sent within a business logic unit, the logic unit identifier recorded in the shared space is updated; Network thread 304 is configured to detect whether the logical unit identifier has changed. If the logical unit identifier has changed, it retrieves the data packets to be sent from the shared space and caches them in the buffer, and sends each data packet to be sent stored in the buffer to the corresponding client.
[0100] Optionally, the logical thread 302 is further configured to have a test read position; through the logical thread, a data packet to be sent corresponding to the client is generated; based on the preset queue sending rules, its own write position is compared with the test read position, and if the comparison result meets the queue sending rules, the data packet to be sent is sent to the shared space; If the comparison result does not conform to the queue sending rules, obtain the read position of the network thread in the shared space and update the test read position based on the read position; based on the queue sending rules, compare its own write position with the updated test read position to obtain the updated comparison result; if the updated comparison result conforms to the queue sending rules, send the data packet to be sent to the shared space; if the updated comparison result does not conform to the queue sending rules, pause the sending operation.
[0101] Optionally, network thread 304 is further configured to have a test write position; based on preset queue reception rules, it compares its own read position with the test write position; if the comparison result matches the queue reception rules, it retrieves the data packet to be sent from the shared space and caches it in the buffer; if the comparison result does not match the queue reception rules, it retrieves the write position of the logical thread in the shared space and updates the test write position based on the write position; based on the queue reception rules, it compares its own read position with the updated test write position to obtain an updated comparison result; if the updated comparison result matches the queue reception rules, it retrieves the data packet to be sent from the shared space and caches it in the buffer; if the updated comparison result does not match the queue reception rules, it pauses the retrieval operation.
[0102] Optionally, network thread 304 is further configured to obtain data packets to be sent from the shared space; determine the buffer to which the client belongs for each data packet to be sent based on the user identifier; and cache each data packet to be sent in the buffer to which the corresponding client belongs.
[0103] Optionally, network thread 304 is further configured to have independent connection channels with multiple clients; it iterates through each connection channel, and for the currently traversed target connection channel, sends each data packet to be sent stored in the buffer corresponding to the target connection channel to the target client corresponding to the target connection channel; through the network thread, it continues to execute the operation of traversing each connection channel until all data packets to be sent stored in the buffer have been sent to the corresponding client.
[0104] Optionally, the connection channel records a status identifier. The network thread 304 is further configured to change the status identifier of the first connection channel to a pending reception state in response to the arrival of a pending data packet on the first connection channel. Here, the first connection channel can be any one of the connection channels. The network thread traverses each connection channel, checks the status identifier of the target connection channel for the currently traversed target connection channel, and if the status identifier is a pending reception state, obtains the pending data packet of the client to which the target connection channel belongs. After obtaining the packet, the status identifier of the target connection channel is changed to a non-receiving state. The pending data packet is then sent to the shared space for the logic thread to obtain.
[0105] Optionally, network thread 304 is further configured to disconnect the target connection channel and continue to perform the operation of traversing each connection channel if the number of data packets to be received meets the preset receiving threshold and the number of currently disconnected channels is less than the preset disconnection threshold.
[0106] The above is an illustrative solution for a server in this embodiment. It should be noted that the technical solution of this server and the technical solution of the data processing method described above belong to the same concept. For details not described in detail in the technical solution of the server, please refer to the description of the technical solution of the data processing method described above.
[0107] Figure 4 This is a structural block diagram of a computing device according to an embodiment of this application. The components of the computing device 400 include, but are not limited to, a memory 410 and a processor 420. The processor 420 is connected to the memory 410 via a bus 430, and a database 450 is used to store data.
[0108] The computing device 400 also includes an access device 440, which enables the computing device 400 to communicate via one or more networks 460. Examples of these networks include a Public Switched Telephone Network (PSTN), a Local Area Network (LAN), a Wide Area Network (WAN), a Personal Area Network (PAN), or a combination of communication networks such as the Internet. The access device 440 may include one or more of any type of wired or wireless network interface (e.g., a Network Interface Card (NIC)), such as an IEEE 802.11 Wireless Local Area Network (WLAN) interface, a Wi-MAX interface, an Ethernet interface, a Universal Serial Bus (USB) interface, a cellular network interface, a Bluetooth interface, a Near Field Communication (NFC) interface, and so on.
[0109] In one embodiment of this application, the aforementioned components of the computing device 400 and Figure 4 Other components, not shown, can also be connected to each other, for example, via a bus. It should be understood that... Figure 4 The block diagram of the computing device shown is for illustrative purposes only and is not intended to limit the scope of this application. Those skilled in the art can add or replace other components as needed.
[0110] The computing device 400 can be any type of stationary or mobile computing device, including mobile computers or mobile computing devices (e.g., tablet computers, personal digital assistants, laptop computers, notebook computers, netbooks, etc.), mobile phones (e.g., smartphones), wearable computing devices (e.g., smartwatches, smart glasses, etc.) or other types of mobile devices, or stationary computing devices such as desktop computers or PCs. The computing device 400 can also be a mobile or stationary server.
[0111] The processor 420 is used to execute computer-executable instructions for data processing methods.
[0112] The above is an illustrative scheme of a computing device according to this embodiment. It should be noted that the technical solution of this computing device and the technical solution of the data processing method described above belong to the same concept. For details not described in detail in the technical solution of the computing device, please refer to the description of the technical solution of the data processing method described above.
[0113] One embodiment of this application also provides a computer-readable storage medium storing computer instructions that, when executed by a processor, are used for a data processing method.
[0114] The above is an illustrative scheme of a computer-readable storage medium according to this embodiment. It should be noted that the technical solution of this storage medium and the technical solution of the data processing method described above belong to the same concept. For details not described in detail in the technical solution of the storage medium, please refer to the description of the technical solution of the data processing method described above.
[0115] One embodiment of this application also provides a chip that stores a computer program, which, when executed by the chip, implements the steps of a data processing method.
[0116] An embodiment of this specification also provides a computer program product, including a computer program / instructions that, when executed by a processor, implement the steps of the above-described data processing method.
[0117] The above is an illustrative scheme of a computer program product according to this embodiment. It should be noted that the technical solution of this computer program product and the technical solution of the data processing method described above belong to the same concept. For details not described in detail in the technical solution of the computer program product, please refer to the description of the technical solution of the data processing method described above.
[0118] The foregoing has described specific embodiments of this application. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recited in the claims may be performed in a different order than that shown in the embodiments and may still achieve the desired results. Furthermore, the processes depicted in the drawings do not necessarily require the specific or sequential order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0119] Computer instructions include computer program code, which can be in the form of source code, object code, executable files, or certain intermediate forms. Computer-readable media can include: any entity or device capable of carrying computer program code, recording media, USB flash drives, portable hard drives, magnetic disks, optical disks, computer memory, read-only memory (ROM), random access memory (RAM), electrical carrier signals, telecommunication signals, and software distribution media, etc. It should be noted that the content included in computer-readable media can be appropriately added or removed according to the requirements of patent practice. For example, in some regions, according to patent practice, computer-readable media do not include electrical carrier signals and telecommunication signals.
[0120] It should be noted that, for the sake of simplicity, the foregoing method embodiments are all described as a series of actions. However, those skilled in the art should understand that this application is not limited to the described order of actions, as some steps may be performed in other orders or simultaneously according to this application. Furthermore, those skilled in the art should also understand that the embodiments described in the specification are preferred embodiments, and the actions and modules involved are not necessarily essential to this application.
[0121] In the above embodiments, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions of other embodiments.
[0122] The preferred embodiments disclosed above are merely illustrative of this application. The optional embodiments do not exhaustively describe all details, nor do they limit the invention to specific implementations. Clearly, many modifications and variations can be made based on the content of this application. These embodiments are selected and specifically described in this application to better explain the principles and practical applications of this application, thereby enabling those skilled in the art to better understand and utilize this application. This application is limited only by the claims and their full scope and equivalents.
Claims
1. A data processing method, characterized in that, Applied to a server that includes logical threads and network threads, the method includes: The logical thread generates data packets to be sent to the client and sends them to the shared space; in response to the completion of the generation of each data packet to be sent within a business logic unit, the logical unit identifier recorded in the shared space is updated. The network thread detects whether the logical unit identifier has changed. If the logical unit identifier has changed, the data packets to be sent are obtained from the shared space and cached in the buffer. The data packets to be sent stored in the buffer are then sent to the corresponding clients.
2. The method according to claim 1, characterized in that, The logical thread is configured to have a test read position; the step of generating the data packet to be sent corresponding to the client and sending it to the shared space through the logical thread includes: The logical thread generates the data packets to be sent for the client. Based on the preset queue sending rules, the write position of itself is compared with the test read position. If the comparison result meets the queue sending rules, the data packet to be sent is sent to the shared space. If the comparison result does not conform to the queue sending rule, obtain the read position of the network thread in the shared space, and update the test read position based on the read position; Based on the queue sending rules, the write position is compared with the updated test read position to obtain an update comparison result; if the update comparison result conforms to the queue sending rules, the data packet to be sent is sent to the shared space. If the update comparison result does not conform to the queue sending rules, the sending operation is paused.
3. The method according to claim 1, characterized in that, The network thread is configured to have a test write position; the step of retrieving the data packet to be sent from the shared space and caching it in the buffer includes: Based on the preset queue receiving rules, the system compares its own read position with the test write position. If the comparison result meets the queue receiving rules, the system retrieves the data packet to be sent from the shared space and caches it in the buffer. If the comparison result does not conform to the queue receiving rule, obtain the write position of the logical thread in the shared space, and update the test write position based on the write position; Based on the queue receiving rules, the read position is compared with the updated test write position to obtain an update comparison result; if the update comparison result conforms to the queue receiving rules, the data packet to be sent is obtained from the shared space and cached in the buffer. If the updated comparison result does not conform to the queue receiving rules, the acquisition operation is paused.
4. The method according to claim 1, characterized in that, The data packet to be sent carries the user identifier of the corresponding client; the step of obtaining the data packet to be sent from the shared space and caching it in the buffer includes: Obtain the data packet to be sent from the shared space; Based on the user identifier, determine the buffer to which the client belongs for each data packet to be sent; Each data packet to be sent is cached in the buffer belonging to the corresponding client.
5. The method according to claim 1, characterized in that, The network thread is configured to have independent connection channels with multiple clients; sending each data packet to be sent stored in the buffer to the corresponding client includes: Iterate through each connection channel, and for the target connection channel currently being traversed, send each data packet to be sent stored in the buffer corresponding to the target connection channel to the target client corresponding to the target connection channel; The network thread continues to iterate through each connection channel until all data packets to be sent stored in the buffer are sent to the corresponding clients.
6. The method according to claim 5, characterized in that, The connection channel records a status identifier, which is initially in a non-receiving state. The method further includes: In response to the arrival of a data packet to be received in the first connection channel, the status flag of the first connection channel is changed to a pending reception status, wherein the first connection channel is any one of the connection channels; The network thread iterates through each connection channel. For the target connection channel currently being traversed, the status identifier of the target connection channel is detected. If the status identifier is in a waiting state, the data packet to be received from the client to which the target connection channel belongs is obtained. After obtaining the data packet, the status identifier of the target connection channel is changed to a non-receiving state. The data packet to be received is then sent to the shared space for the logic thread to obtain.
7. The method according to claim 6, characterized in that, The step of obtaining the data packets to be received from the client to which the target connection channel belongs includes: If the number of data packets to be received meets the preset receiving threshold and the number of currently disconnected channels is less than the preset disconnection threshold, the target connection channel is disconnected and the operation of traversing each connection channel continues.
8. A server-side component, characterized in that, include: The logical thread is configured to generate the data packets to be sent to the client and send them to the shared space. In response to the completion of the generation of each data packet to be sent within a business logic unit, the logic unit identifier recorded in the shared space is updated; A network thread is configured to detect whether the logical unit identifier has changed. If the logical unit identifier has changed, the thread retrieves the data packets to be sent from the shared space and caches them in a buffer, and sends each data packet to be sent stored in the buffer to the corresponding client.
9. A computing device, characterized in that, include: Memory and processor; The memory is used to store computer-executable instructions, and the processor is used to execute the computer-executable instructions to implement the steps of the method according to any one of claims 1 to 7.
10. A computer-readable storage medium storing computer instructions, characterized in that, When executed by the processor, this instruction implements the steps of the method according to any one of claims 1 to 7.
11. A computer program product, comprising a computer program / instructions, characterized in that, When the computer program / instructions are executed by the processor, they implement the steps of the method according to any one of claims 1 to 7.
