Method and device for responding to reading event, electronic equipment and storage medium

By using shared buffers to respond to read events in Redis, the memory waste problem caused by the large number of connections is solved, and buffer multiplexing and memory usage are reduced.

CN119025047APending Publication Date: 2024-11-26BEIJING KINGSOFT CLOUD NETWORK TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411255632.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-06
Publication Date
2024-11-26

AI Technical Summary

Technical Problem

In Redis, when there are many connections, the client's private buffer causes a large amount of memory to be consumed, causing memory waste.

Method used

A shared buffer is used to respond to read events. The shared buffer is used for new connections from any client, thereby achieving buffer reuse and reducing memory usage.

Benefits of technology

By responding to read events by the shared buffer, the memory usage of the buffer is reduced, and each client is prevented from initializing a buffer, thus solving the memory waste problem caused by the large number of connections.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119025047A_ABST
    Figure CN119025047A_ABST
Patent Text Reader

Abstract

The invention provides a method and device for responding to a reading event, electronic equipment and a storage medium, and the method comprises the steps: obtaining a target reading event initiated by a target client; under the condition that a shared buffer area is in an idle state, the shared buffer area is used for responding to a target command of the target reading event, and the shared buffer area is used for being used by new connection from any client side. Through the method and the device, the problem of memory waste caused by occupation of a large amount of memory under the condition that the number of connections is large in the prior art is solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of data processing technology, and in particular to a method and device for responding to a read event, an electronic device, and a storage medium. Background Art

[0002] As a single-threaded in-memory KV (key-value) database service, Redis is widely used in Internet cache services. The main advantages of Redis include: rich data types, low latency, high performance, and the ability to widely meet various high-concurrency scenarios. However, since Redis itself is an in-memory database, when there are many connections in the related art, the client buffer is private to each client, which will cause a large amount of memory to be occupied unnecessarily, resulting in memory waste.

[0003] Therefore, there is a problem in the related art that when the number of connections is large, a large amount of memory will be occupied, resulting in memory waste. Summary of the invention

[0004] The present application provides a method and device for responding to a read event, an electronic device and a storage medium, so as to at least solve the problem in the related art that when the number of connections is large, a large amount of memory will be occupied, thereby causing memory waste.

[0005] According to one aspect of an embodiment of the present application, a method for responding to a read event is provided, comprising:

[0006] Get the target read event initiated by the target client;

[0007] When the shared buffer is in an idle state, the shared buffer is used to respond to the target command of the target read event, wherein the shared buffer is used for a new connection from any client.

[0008] Optionally, as in the aforementioned method, obtaining a target read event initiated by a target client includes:

[0009] Pre-initialize at least one shared buffer variable;

[0010] In case of acquiring a new connection from the target client, clearing the buffer allocation behavior corresponding to the target client;

[0011] The target read event initiated by the target client is obtained through the newly created connection.

[0012] Optionally, as in the aforementioned method, when the shared buffer is in an idle state, using the shared buffer to respond to the target command of the target read event includes:

[0013] Determine whether the target client has a corresponding private buffer;

[0014] When it is determined that the target client does not have a corresponding private buffer and the shared buffer is in an idle state, the shared buffer is used to respond to the target command of the target read event.

[0015] Optionally, as in the aforementioned method, when the shared buffer is in an idle state, using the shared buffer to respond to the target command of the target read event includes:

[0016] When the shared buffer is in an idle state, the network data packet of the target read event is parsed using the shared buffer to obtain the target command;

[0017] If it is determined that there is remaining unparsed data in the network data packet, continue parsing the remaining unparsed data, and repeat this cycle until the remaining unparsed data is completely parsed and all remaining commands are obtained, or there is unparseable data in the remaining unparsed data;

[0018] The target command is responded to using the shared buffer, and when the remaining commands exist, all the remaining commands are responded to using the shared buffer.

[0019] Optionally, as in the aforementioned method, when it is determined that there is remaining unparsed data in the network data packet, continuing to parse the remaining unparsed data includes:

[0020] When it is determined that there is remaining unparsed data in the network data packet, assigning the shared buffer to the target client, making the shared buffer a private buffer of the target client, and continuing to parse the remaining unparsed data through the private buffer;

[0021] Create a new shared buffer.

[0022] Optionally, as in the aforementioned method, when the remaining commands exist, using the shared buffer to respond to all the remaining commands includes:

[0023] All remaining commands respond to the target read event using the private buffer.

[0024] Optionally, as in the aforementioned method, the method further comprises:

[0025] When the private buffer has responded to all the remaining commands of the target read event, the private buffer is released.

[0026] According to another aspect of an embodiment of the present application, a device for responding to a read event is also provided, including:

[0027] An acquisition module, used to acquire a target read event initiated by a target client;

[0028] The response module is used to use the shared buffer to respond to the target command of the target read event when the shared buffer is in an idle state, wherein the shared buffer is used for a new connection from any client.

[0029] According to another aspect of the embodiments of the present application, there is also provided an electronic device, including a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other via the communication bus; wherein the memory is used to store a computer program; and the processor is used to execute the method steps in any of the above embodiments by running the computer program stored in the memory.

[0030] According to another aspect of the embodiments of the present application, a computer-readable storage medium is provided, in which a computer program is stored, wherein the computer program is configured to execute the method steps in any of the above embodiments when executed.

[0031] In an embodiment of the present application, a method of responding to a read event through a shared buffer is adopted. A read event is responded to through a shared buffer, and the shared buffer is used for a new connection from any client, so that the shared buffer can be reused by a new connection from any client, thereby achieving the technical effect of reducing the memory occupied by the buffer, and there is no need to initialize a buffer for each client, thereby solving the problem in the related art that when the number of connections is large, a large amount of memory will be occupied, thereby causing memory waste. BRIEF DESCRIPTION OF THE DRAWINGS

[0032] 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.

[0033] 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.

[0034] Figure 1 is a schematic diagram of a hardware environment of an optional method for responding to a read event according to an embodiment of the present application;

[0035] Figure 2 is a flowchart of an optional method for responding to a read event according to an embodiment of the present application;

[0036] Figure 3 is a flowchart of another optional method for responding to a read event according to an embodiment of the present application;

[0037] Figure 4 is a flowchart of another optional method for responding to a read event according to an embodiment of the present application;

[0038] Figure 5 is a schematic diagram of the overall process of another optional method for responding to a read event according to an embodiment of the present application;

[0039] Figure 6 is a structural block diagram of an optional device for responding to a read event according to an embodiment of the present application;

[0040] Figure 7 It is a structural block diagram of an optional electronic device according to an embodiment of the present application. DETAILED DESCRIPTION

[0041] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present application.

[0042] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0043] In the related art, in the Redis client connection scenario, each new connection between the Redis server and a client will create a memory buffer of at least 16KB; then the client reads the request data, and the Redis server reads the request data into the client's own 16kb memory buffer, and then parses the request data to obtain the corresponding command. After the Redis server processes the client's command, it will write the response result into the above memory buffer, and the client then reads the response result from the memory buffer. Among them, the buffer refers to the memory area between the client and the Redis server for temporarily storing data. These buffers are private to the client, and each client connection has an independent buffer. In the case of a large number of connections, the client's memory buffer is private to each client, which will cause a large amount of memory to be occupied unnecessarily. For example: if there are 10,000 links, each memory buffer is at least 16kb, which will occupy at least 160MB of memory. It can be seen that when there are a large number of connections in the related art, a large amount of memory will be occupied, resulting in a problem of memory waste.

[0044] According to one aspect of an embodiment of the present application, a method for responding to a read event is provided. Optionally, in this embodiment, the method for responding to a read event can be applied to Figure 1 In the hardware environment composed of terminal 1402 and server 1404 shown in FIG. Figure 1 As shown, server 1404 is connected to terminal 1402 via a network, and can be used to provide services (such as game services, application services, etc.) for the terminal or a client installed on the terminal. A database can be set up on the server or independently of the server to provide data storage services for server 1404.

[0045] The above network may include but is not limited to at least one of the following: wired network, wireless network. The above wired network may include but is not limited to at least one of the following: wide area network, metropolitan area network, local area network, and the above wireless network may include but is not limited to at least one of the following: WIFI (Wireless Fidelity), Bluetooth. The terminal may not be limited to a PC, a mobile phone, a tablet computer, etc.

[0046] The method for responding to a read event in the embodiment of the present application can be executed by a server, a terminal, or both. The terminal can also execute the method for responding to a read event in the embodiment of the present application by a client installed thereon.

[0047] Taking the method of responding to a read event in this embodiment executed by the server as an example, Figure 2A method for responding to a read event provided in an embodiment of the present application includes the following steps:

[0048] Step S202: obtaining a target read event initiated by the target client.

[0049] The method for responding to a read event in this embodiment can be applied to a scenario where a Redis server needs to respond to a read event from a client.

[0050] When the target client needs to make a request to the Redis server (for example, data storage, retrieval, operation, transaction processing, etc.), the purpose of the request can be achieved by initiating a target read event.

[0051] like Figure 3 and Figure 5 As shown, as an optional implementation, step S202 of obtaining the target read event initiated by the target client can be implemented by the following steps:

[0052] Step S302, pre-initialize at least one shared buffer variable. Specifically, a shared buffer variable (i.e., Buffer variable) can be pre-initialized. The shared buffer variable is a part of the buffer, usually a memory block of a specific size, used to store data of a specific type. When Redis initializes a Buffer variable of a preset size (for example, 16KB) for a new client connection, it actually allocates a continuous memory area of ​​a preset size in the memory. This memory area will be used as part of the shared buffer for temporarily storing data sent by the client. The example assumes that during the initialization phase, the Redis server will initialize a 16KB shared buffer variable for this connection. This shared buffer variable will be used to temporarily store data sent by the client subsequently received. This shared buffer variable is part of the input buffer of the client connection, and is used to store commands and parameters sent by the client.

[0053] Step S304, when a new connection is obtained from the target client, the buffer allocation behavior corresponding to the target client is cleared. That is, when the Redis server receives a new connection, it can create a client object, and by default, it will not apply for a shared buffer of a preset size for the target client by executing the buffer allocation behavior, but will clear the buffer allocation behavior.

[0054] Step S306, obtaining a target read event initiated by the target client through the newly created connection. Optionally, the newly created connection can be monitored for read events, and when a target read event is detected to be sent from the target client to the Redis server through the newly created connection, the target read event can be obtained.

[0055] Step S204: when the shared buffer is in an idle state, use the shared buffer to respond to the target command of the target read event, wherein the shared buffer is used for a new connection from any client.

[0056] In this embodiment, a shared buffer is preferentially used to respond to the client's read event, and the shared buffer can be used for new connections from any client. That is to say, no matter which client currently initiates the read event, as long as the shared buffer is idle, it can be used to respond to the read event. Furthermore, assuming that there are 10,000 connections, the size of each shared buffer is 16KB. If only a preset number of N shared buffers are used to respond to the read event, (16×N)KB of memory will be used. This is equivalent to using only the original N / 10000 client request cache memory overhead. In particular, if only one shared buffer is set, only 16KB of memory is used. This is equivalent to using only 1 / 10000 of the original client request cache memory overhead.

[0057] Furthermore, the shared buffer can be adjusted dynamically: if the amount of data in the shared buffer exceeds the initial size, the Redis server can automatically expand the size of the shared buffer. Secondly, threshold monitoring is also possible: the Redis server monitors the size of the dynamic buffer. If the amount of data in the shared buffer exceeds the set threshold, the Redis server can take measures, such as closing the connection or warning the client to reduce the frequency of sending data.

[0058] In general, a shared buffer can include an input buffer and an output buffer. The target command that uses the shared buffer to respond to the target read event can be implemented in the following ways: 1. Receive data: The command and parameters sent by the target client are received and temporarily stored in the input buffer. 2. Parse the command: The Redis server reads data from the input buffer and parses it to obtain the target command sent by the target client, which is the operation that the target client needs to perform. 3. Process the command: The Redis server performs the corresponding operation according to the parsed target command. 4. Generate a response: The Redis server generates response data according to the result of the target command. 5. Write to the output buffer: The response data is written to the output buffer. 6. Send a response: The target client reads the response result from the output buffer.

[0059] As an optional implementation, as in the aforementioned method, the following steps are used to implement the use of a shared buffer to respond to a target command of a target read event when the shared buffer is in an idle state: determine whether the target client has a corresponding private buffer; when it is determined that the target client does not have a corresponding private buffer and the shared buffer is in an idle state, use the shared buffer to respond to the target command of the target read event. That is, before determining whether to use the shared buffer to respond to the target command of the target read event, first determine whether the target client has a corresponding private buffer, and when it is determined that the target client does not have a corresponding private buffer and the shared buffer is in an idle state, use the shared buffer to respond to the target command of the target read event. And, when it is determined that the target client has a private buffer, use the private buffer to respond to the target command of the target read event.

[0060] like Figure 4 and 5 As shown, as an optional implementation, as in the aforementioned method, the following steps can be used to implement the use of the shared buffer to respond to the target command of the target read event when the shared buffer is in an idle state:

[0061] Step S402, when the shared buffer is in an idle state, the network data packet of the target read event is parsed using the shared buffer to obtain the target command. Specifically, the network data packet is the original data packet sent by the target client to the Redis service through a newly created connection in the target read event. After parsing the network data packet, the target command can be obtained.

[0062] Step S404, when it is determined that there is remaining unparsed data in the network data packet, the remaining unparsed data is further parsed, and this cycle is repeated until the remaining unparsed data is completely parsed and all remaining commands are obtained, or there is unparseable data in the remaining unparsed data. That is to say, the above-mentioned target command can be a command obtained after parsing part of the data in the network data packet. Furthermore, when there is still remaining unparsed data in the network data packet after the first parsing, it is necessary to continue parsing the remaining unparsed data and parse to obtain the remaining commands. Further, after parsing the remaining commands, if there is still the latest remaining unparsed data in the network data packet, the latest remaining unparsed data is continued to be parsed, and this cycle is repeated until the remaining unparsed data is completely parsed and all remaining commands are obtained, or there is unparseable data in the remaining unparsed data.

[0063] As an optional implementation, as in the aforementioned method, the aforementioned step S404 can be implemented by the following steps: when it is determined that there is remaining unparsed data in the network data packet, the remaining unparsed data is continued to be parsed by assigning a shared buffer to the target client, making the shared buffer a private buffer of the target client, and continuing to parse the remaining unparsed data through the private buffer; creating a new shared buffer. That is, when there is remaining unparsed data in the network data packet, the shared buffer is still used to respond to the command of the target client next time, therefore, the shared buffer is assigned to the target client, making the shared buffer a private buffer dedicated to responding to the command of the target client, and continuing to parse the remaining unparsed data through the private buffer; in order to allow other newly connected clients to have a usable buffer, a new shared buffer needs to be created.

[0064] Step S406, using the shared buffer to respond to the target command, and when there are remaining commands, using the shared buffer to respond to all remaining commands. That is to say, there is at least one target command, so at least the shared buffer needs to be used to respond to the target command, and when there are remaining commands, it is necessary to continue to use the shared buffer to respond to all remaining commands. And when there are remaining commands, the shared buffer becomes a private buffer assigned to the target client, so it is also equivalent to using the shared buffer as the private buffer of the target client to respond to all remaining commands when there are remaining commands. Further, when there are remaining commands, using the shared buffer to respond to all remaining commands can be achieved by the following steps: using the private buffer to respond to all remaining commands of the target read event.

[0065] As an optional implementation, as in the aforementioned method, the method further includes: releasing the private buffer when the private buffer has responded to all remaining commands of the target read event. Since the private buffer only responds to the target client, the private buffer is released when all remaining commands have been responded to, so as to save memory usage.

[0066] The method of this embodiment adopts a method of responding to read events through a shared buffer. The shared buffer is used for new connections from any client, so that the shared buffer can be reused by new connections from any client, thereby achieving the technical effect of reducing the memory occupation of the buffer. There is no need to initialize a buffer for each client, thereby solving the problem in the related art that when there are many connections, a large amount of memory will be occupied, thereby causing memory waste.

[0067] It should be noted that, for the aforementioned method embodiments, for the sake of simplicity, they are all expressed as a series of action combinations, but those skilled in the art should be aware that the present application is not limited by the described order of actions, because according to the present application, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required by the present application.

[0068] Through the description of the above implementation methods, those skilled in the art can clearly understand that the method according to the above embodiment can be implemented by means of software plus a necessary general hardware platform, and of course it can also be implemented by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM (Read-Only Memory) / RAM (Random Access Memory), a disk, or an optical disk), and includes a number of instructions for a terminal device (which can be a mobile phone, a computer, a server, or a network device, etc.) to execute the methods described in each embodiment of the present application.

[0069] According to another aspect of an embodiment of the present application, a device for responding to a read event for implementing the above method for responding to a read event is also provided. Figure 6 is a structural block diagram of an optional device for responding to a read event according to an embodiment of the present application, such as Figure 6 As shown, the device may include:

[0070] An acquisition module 61 is used to acquire a target read event initiated by a target client;

[0071] The response module 62 is used to use the shared buffer to respond to the target command of the target read event when the shared buffer is in an idle state, wherein the shared buffer is used for a new connection from any client.

[0072] It should be noted that the acquisition module 61 in this embodiment can be used to execute the above step S202, and the response module 62 in this embodiment can be used to execute the above step S204.

[0073] Through the above module, a read event is responded to through a shared buffer, and the shared buffer is used for a new connection from any client, so that the shared buffer can be reused by a new connection from any client, thereby achieving the technical effect of reducing the memory occupation of the buffer, and there is no need to initialize a buffer for each client, thereby solving the problem in the related technology that when the number of connections is large, a large amount of memory will be occupied, thereby causing memory waste.

[0074] As an optional implementation, in the aforementioned device, the acquisition module 61 includes:

[0075] an initialization unit, used for pre-initializing at least one shared buffer variable;

[0076] a clearing unit, configured to clear a buffer allocation behavior corresponding to the target client when a new connection is acquired from the target client;

[0077] An acquiring unit is used to acquire the target read event initiated by the target client through the newly created connection.

[0078] As an optional implementation, in the aforementioned device, the response module 62 includes:

[0079] A determination unit, used to determine whether a corresponding private buffer exists in the target client;

[0080] The first responding unit is configured to respond to a target command of the target read event by using the shared buffer when it is determined that the target client does not have a corresponding private buffer and the shared buffer is in an idle state.

[0081] As an optional implementation, in the aforementioned device, the response module 62 includes:

[0082] A first parsing unit, configured to parse the network data packet of the target read event using the shared buffer to obtain the target command when the shared buffer is in an idle state;

[0083] a second parsing unit, configured to, if it is determined that there is remaining unparsed data in the network data packet, continue parsing the remaining unparsed data, and repeat this cycle until the remaining unparsed data is completely parsed and all remaining commands are obtained, or there is data that cannot be parsed in the remaining unparsed data;

[0084] The second responding unit is configured to respond to the target command using the shared buffer, and when the remaining commands exist, respond to all the remaining commands using the shared buffer.

[0085] As an optional implementation manner, in the aforementioned device, the second parsing unit is configured to:

[0086] When it is determined that there is remaining unparsed data in the network data packet, assigning the shared buffer to the target client, making the shared buffer a private buffer of the target client, and continuing to parse the remaining unparsed data through the private buffer;

[0087] Create a new shared buffer.

[0088] As an optional implementation manner, as in the aforementioned device, the second response unit is configured as follows:

[0089] All remaining commands respond to the target read event using the private buffer.

[0090] As an optional implementation, the aforementioned device further includes a release module, wherein the release module is configured to:

[0091] When the private buffer has responded to all the remaining commands of the target read event, the private buffer is released.

[0092] The device in this embodiment, in addition to the above modules, may also include a module for executing any method in any of the above embodiments of the method for responding to a read event.

[0093] It should be noted that the examples and application scenarios implemented by the above modules and corresponding steps are the same, but are not limited to the contents disclosed in the above embodiments. It should be noted that the above modules as part of the device can be run in Figure 1 In the hardware environment shown, it can be implemented by software or by hardware, wherein the hardware environment includes a network environment.

[0094] According to another aspect of the embodiments of the present application, an electronic device for implementing the above-mentioned method of responding to a read event is also provided. The electronic device may be a server, a terminal, or a combination thereof.

[0095] According to another embodiment of the present application, there is also provided an electronic device, including: Figure 7 As shown, the electronic device may include: a processor 1501 , a communication interface 1502 , a memory 1503 and a communication bus 1504 , wherein the processor 1501 , the communication interface 1502 , and the memory 1503 communicate with each other via the communication bus 1504 .

[0096] Memory 1503, used for storing computer programs;

[0097] The processor 1501 is used to implement the following steps when executing the program stored in the memory 1503:

[0098] Step S202: obtaining a target read event initiated by the target client.

[0099] Step S204: when the shared buffer is in an idle state, use the shared buffer to respond to the target command of the target read event, wherein the shared buffer is used for a new connection from any client.

[0100] Optionally, in this embodiment, the above-mentioned communication bus can be a PCI (Peripheral Component Interconnect) bus, or an EISA (Extended Industry Standard Architecture) bus, etc. The communication bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus. The communication interface is used for communication between the above-mentioned electronic device and other devices.

[0101] The memory may include a random access memory (RAM) or a non-volatile memory (NVM), such as at least one disk memory. Optionally, the memory may also be at least one storage device located away from the aforementioned processor.

[0102] As an example, the memory 1503 may include but is not limited to the acquisition module 51 and the response module 52 in the device for responding to a read event. In addition, it may also include but is not limited to other module units in the device for responding to a read event, which will not be repeated in this example.

[0103] The above-mentioned processor can be a general-purpose processor, which can include but not be limited to: CPU (Central Processing Unit), NP (Network Processor), etc.; it can also be DSP (Digital Signal Processor), ASIC (Application Specific Integrated Circuit), FPGA (Field-Programmable Gate Array) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.

[0104] An embodiment of the present application further provides a computer-readable storage medium, the storage medium including a stored program, wherein the method steps of the above method embodiment are executed when the program is run.

[0105] Optionally, in this embodiment, the storage medium may include but is not limited to: a U disk, a ROM, a RAM, a mobile hard disk, a magnetic disk or an optical disk, and other media that can store program codes.

[0106] The serial numbers of the above-mentioned embodiments of the present application are for description only and do not represent the advantages or disadvantages of the embodiments.

[0107] If the integrated units in the above embodiments are implemented in the form of software functional units and sold or used as independent products, they can be stored in the above computer-readable storage medium. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for enabling one or more computer devices (which may be personal computers, servers, or network devices, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present application.

[0108] In the above embodiments of the present application, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, please refer to the relevant description of other embodiments.

[0109] In the several embodiments provided in the present application, it should be understood that the disclosed client can be implemented in other ways. Among them, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of units or modules, which can be electrical or other forms.

[0110] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution provided in this embodiment.

[0111] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.

[0112] The above is only a preferred implementation of the present application. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present application. These improvements and modifications should also be regarded as the scope of protection of the present application.

Claims

1. A method for responding to a read event, characterized in that: include: Get the target read event initiated by the target client; When the shared buffer is in an idle state, the shared buffer is used to respond to the target command of the target read event, wherein the shared buffer is used for a new connection from any client.

2. The method according to claim 1, characterized in that The obtaining of a target read event initiated by a target client includes: Pre-initialize at least one shared buffer variable; In case of acquiring a new connection from the target client, clearing the buffer allocation behavior corresponding to the target client; The target read event initiated by the target client is obtained through the newly created connection.

3. The method according to claim 1, characterized in that When the shared buffer is in an idle state, using the shared buffer to respond to the target command of the target read event includes: Determine whether the target client has a corresponding private buffer; When it is determined that the target client does not have a corresponding private buffer and the shared buffer is in an idle state, the shared buffer is used to respond to the target command of the target read event.

4. The method according to claim 1, characterized in that: When the shared buffer is in an idle state, using the shared buffer to respond to the target command of the target read event includes: When the shared buffer is in an idle state, the network data packet of the target read event is parsed using the shared buffer to obtain the target command; If it is determined that there is remaining unparsed data in the network data packet, continue parsing the remaining unparsed data, and repeat this cycle until the remaining unparsed data is completely parsed and all remaining commands are obtained, or there is unparseable data in the remaining unparsed data; The target command is responded to using the shared buffer, and when the remaining commands exist, all the remaining commands are responded to using the shared buffer.

5. The method according to claim 4, characterized in that When it is determined that there is remaining unparsed data in the network data packet, continuing to parse the remaining unparsed data includes: When it is determined that there is remaining unparsed data in the network data packet, assigning the shared buffer to the target client, making the shared buffer a private buffer of the target client, and continuing to parse the remaining unparsed data through the private buffer; Create a new shared buffer.

6. The method according to claim 5, characterized in that When the remaining commands exist, using the shared buffer to respond to all the remaining commands includes: All remaining commands respond to the target read event using the private buffer.

7. The method according to claim 6, characterized in that The method further comprises: When the private buffer has responded to all the remaining commands of the target read event, the private buffer is released.

8. A device for responding to a read event, characterized in that: include: An acquisition module, used to acquire a target read event initiated by a target client; The response module is used to use the shared buffer to respond to the target command of the target read event when the shared buffer is in an idle state, wherein the shared buffer is used for a new connection from any client.

9. An electronic device comprising a processor, a communication interface, a memory and a communication bus, wherein: The processor, the communication interface and the memory communicate with each other via the communication bus, wherein: The memory is used to store computer programs; The processor is configured to execute the method according to any one of claims 1 to 7 by running the computer program stored in the memory.

10. A computer-readable storage medium, characterized in that: The storage medium stores a computer program, wherein the computer program is configured to execute the method according to any one of claims 1 to 7 when executed.