Data compression method, electronic equipment and storage medium
By dynamically adjusting the compression level to adapt to the data transmission between the client and the server, the problem that data compression methods in the prior art are difficult to take into account communication quality and efficiency, and the optimized communication effect under different data volumes is achieved.
Patent Information
- Application Number
- CN202411129258.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-16
- Publication Date
- 2024-11-01
- Estimated Expiration
- 2044-08-16
AI Technical Summary
The existing data compression methods are difficult to take into account both communication quality and communication efficiency, especially when the data transmission is small, it leads to waste of system resources, and when the data transmission is large, it may cause packet errors.
By receiving the client's interface access request, obtaining the total amount of transmitted data and the average access time, dynamically adjusting the compression level of the preset compression algorithm to determine the optimal compression level, and performing data compression when specific conditions are met to ensure communication quality and efficiency.
It effectively avoids resource waste and packet errors caused by fixed compression algorithms and compression levels, and realizes optimized communication quality and efficiency under different data volumes.
Smart Images

Figure CN118890400A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of data transmission, and in particular to a data compression method, an electronic device and a storage medium. Background Art
[0002] With the development of the fifth generation mobile communication technology (5th Generation Mobile Communication Technology, referred to as 5G), network speed has been greatly improved, allowing people to browse the web, watch videos, play online games, etc. faster. When the client and the server interact with each other based on the Hypertext Transfer Protocol (HTTP), the data transmitted from the client to the server and the data transmitted from the server to the client are usually compressed using a fixed compression algorithm and a fixed compression level. Therefore, when the amount of data transmitted is small, it is easy to cause a waste of system resources, affecting the communication efficiency between the client and the server; when the amount of data transmitted is large, it is easy to cause data packet errors, affecting the communication quality between the client and the server. Therefore, it is difficult for existing data compression methods to take into account both communication quality and communication efficiency at the same time. Summary of the invention
[0003] The present application provides a data compression method, an electronic device and a storage medium to solve the problem that it is difficult to take into account both communication quality and communication efficiency in existing data compression methods.
[0004] In a first aspect, an embodiment of the present application provides a data compression method, which is applied to a server, and the method includes:
[0005] Receive a first interface access request sent by a client, wherein the first interface access request carries first field information and first transmission data, the first field information is used to represent a first average access time required for the client to access the interface when no compression algorithm is used for data compression, and the first transmission data refers to data transmitted by the client to the server;
[0006] In response to the first interface access request, obtaining second transmission data to be returned to the client, and determining a total amount of transmission data according to the first transmission data and the second transmission data;
[0007] Based on the first average access time and the total amount of transmitted data, determining whether a trigger condition for data compression is currently met;
[0008] In the case of determining that the trigger condition for data compression is currently met, dynamically adjusting multiple compression levels in the preset compression algorithm to obtain an optimal compression level, and encapsulating the optimal compression level as second field information into a response message and sending it to the client;
[0009] The optimal compression level is used to compress the transmission data between the client and the client.
[0010] Optionally, the number of the preset compression algorithms is one; and dynamically adjusting multiple compression levels in the preset compression algorithms to obtain an optimal compression level includes:
[0011] Sequentially traverse multiple compression levels in the preset compression algorithm, and sequentially encapsulate the traversed compression levels as second field information into a response message and send it to the client;
[0012] receiving in sequence the second interface access requests sent by the client based on the compression level carried in each response message, and determining the minimum second average access duration corresponding to the preset compression algorithm based on each received second interface access request, wherein different second interface access requests carry second average access durations corresponding to different compression levels;
[0013] Determine whether the minimum second average access time corresponding to the preset compression algorithm is less than a first preset threshold;
[0014] When it is determined that the minimum second average access time corresponding to the preset compression algorithm is less than the first preset threshold, the compression level of the minimum second average access time corresponding to the preset compression algorithm is determined as the optimal compression level.
[0015] Optionally, the determining the minimum second average access time corresponding to the preset compression algorithm based on each received second interface access request includes: comparing the second average access time in the currently received second interface access request with the second average access time in the last received second interface access request;
[0016] When the second average access duration in the currently received second interface access request is greater than the second average access duration in the last received second interface access request, the second average access duration in the last received second interface access request is determined as the minimum second average access duration corresponding to the preset compression algorithm;
[0017] When the second average access time in the currently received second interface access request is less than or equal to the second average access time in the last received second interface access request, continue to traverse the next compression level in the preset compression algorithm, and compare the second average access time in the next received second interface access request with the second average access time in the currently received second interface access request, and repeat the process until the traversal is stopped when a first preset condition is met, wherein the first preset condition is that all compression levels in the preset compression algorithm have been traversed, or the minimum second average access time corresponding to the preset compression algorithm is detected.
[0018] Optionally, there are multiple preset compression algorithms, and dynamically adjusting multiple compression levels in the preset compression algorithms to obtain an optimal compression level includes:
[0019] When the minimum second average access time corresponding to the first compression algorithm is greater than or equal to the first preset threshold, traverse the multiple compression levels in the second compression algorithm in sequence, and encapsulate the traversed compression levels in the second compression algorithm in sequence as second field information into a response message and send it to the client;
[0020] receiving in sequence the second interface access requests sent by the client based on the compression level carried in each response message, and determining the minimum second average access time corresponding to the second compression algorithm based on each received second interface access request, wherein different second interface access requests carry second average access times corresponding to different compression levels;
[0021] Determine whether the minimum second average access time corresponding to the second compression algorithm is less than the first preset threshold;
[0022] In the case where it is determined that the minimum second average access time corresponding to the second compression algorithm is less than the first preset threshold, determining the compression level of the minimum second average access time corresponding to the second compression algorithm as the optimal compression level;
[0023] When it is determined that the minimum second average access time corresponding to the second compression algorithm is greater than or equal to the first preset threshold, continue to traverse the multiple compression levels in the third compression algorithm in sequence, and loop in sequence until the traversal is stopped when the second preset condition is met, wherein the second preset condition is that all compression levels of the multiple compression algorithms in the preset compression algorithm have been traversed, or it is detected that the minimum second average access time corresponding to any compression algorithm is less than the first preset threshold, and the first compression algorithm, the second compression algorithm and the third compression algorithm belong to the preset compression algorithm.
[0024] Optionally, the determining whether a triggering condition for data compression is currently met based on the first average access time and the total amount of transmitted data includes:
[0025] Determine whether the total amount of transmitted data is greater than a second preset threshold, and whether the first average access time is greater than a third preset threshold;
[0026] When it is determined that the total amount of transmitted data is greater than the second preset threshold and the first average access time is greater than the third preset threshold, determining that a trigger condition for data compression is currently met;
[0027] When it is determined that the total amount of transmitted data is less than or equal to the second preset threshold, and / or the first average access time is less than or equal to the third preset threshold, it is determined that the trigger condition for data compression is not currently met.
[0028] Optionally, after compressing the transmission data between the client and the client using the optimal compression level, the method further includes:
[0029] Acquire the duration of data compression in real time, wherein the duration of data compression refers to the duration between the current time point and the time point at which the trigger condition for data compression is determined to be satisfied;
[0030] When the duration of the data compression reaches a fourth preset threshold, setting the second field information in the response message to empty, and sending the set response message to the client;
[0031] The transmission data between the client and the client is transmitted in an original data transmission mode, wherein the original data transmission mode refers to a data transmission mode that does not use any compression algorithm to compress the transmission data.
[0032] In a second aspect, an embodiment of the present application further provides a data compression method, which is applied to a client, and the method includes:
[0033] Sending a first interface access request to the server, wherein the first interface access request carries first field information and first transmission data, the first field information is used to represent a first average access time required for the client to access the interface when no compression algorithm is used for data compression, and the first transmission data refers to data that the client needs to transmit to the server;
[0034] Receive a response message returned by the server in response to the first interface access request, wherein the second field information of the response message is an optimal compression level, and the optimal compression level is obtained by the server dynamically adjusting multiple compression levels in a preset compression algorithm when determining that a trigger condition for data compression is currently met, and the trigger condition for data compression is determined by the server based on the first average access time and the total amount of transmitted data, and the total amount of transmitted data is the sum of first transmitted data transmitted by the client to the server and second transmitted data to be returned by the server to the client;
[0035] The optimal compression level is used to compress the data transmitted between the server.
[0036] Optionally, after compressing the transmission data between the server and the server using the optimal compression level, the method further includes:
[0037] When the duration of data compression reaches a fourth preset threshold, receiving a set response message returned by the server, wherein the second field information in the set response message is empty;
[0038] The transmission data between the server and the server is transmitted in an original data transmission mode, wherein the original data transmission mode refers to a data transmission mode that does not use any compression algorithm to compress the transmission data.
[0039] In a third aspect, an embodiment of the present application further provides 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;
[0040] Memory, used to store computer programs;
[0041] The processor is used to implement the data compression method described in any one of the first aspects, or implement the data compression method described in any one of the second aspects when executing the program stored in the memory.
[0042] In a fourth aspect, an embodiment of the present application further provides a computer-readable storage medium having a computer program stored thereon, wherein when the computer program is executed by a processor, the data compression method described in any one of the first aspect is implemented, or the data compression method described in any one of the second aspect is implemented.
[0043] The above-mentioned technical solution provided by the embodiment of the present application has the following advantages over the prior art: the method provided by the embodiment of the present application, by receiving a first interface access request sent by a client, wherein the first interface access request carries first field information and first transmission data, the first field information is used to characterize the first average access time required for the client to access the interface when no compression algorithm is used for data compression, and the first transmission data refers to the data transmitted by the client to the server; in response to the first interface access request, obtaining second transmission data to be returned to the client, and determining the total amount of transmission data based on the first transmission data and the second transmission data; determining whether a trigger condition for data compression is currently met based on the first average access time and the total amount of transmission data; in the case of determining that the trigger condition for data compression is currently met, dynamically adjusting multiple compression levels in a preset compression algorithm to obtain an optimal compression level, and encapsulating the optimal compression level as the second field information into a response message and sending it to the client; using the optimal compression level to compress the transmission data between the client and the client. Through the above method, the server can dynamically adjust multiple compression levels in the preset compression algorithm when it is determined that the trigger conditions for data compression are currently met, thereby effectively avoiding the use of fixed compression algorithms and fixed compression levels for data compression in the prior art, resulting in the problem of waste of system resources when the amount of data transmitted is small, and the problem of data packet errors when the amount of data transmitted is large, thereby achieving the purpose of taking into account both communication quality and communication efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0044] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the invention and, together with the description, serve to explain the principles of the invention.
[0045] In order to more clearly illustrate the embodiments of the present invention 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.
[0046] One or more embodiments are exemplarily described by pictures in the corresponding drawings, and these exemplified descriptions do not constitute limitations on the embodiments. Elements with the same reference numerals in the drawings represent similar elements, and unless otherwise stated, the figures in the drawings do not constitute proportional limitations.
[0047] Figure 1 A flowchart of a data compression method provided in an embodiment of the present application;
[0048] Figure 2A flowchart of another data compression method provided in an embodiment of the present application;
[0049] Figure 3 A flowchart of another data compression method provided in an embodiment of the present application;
[0050] Figure 4 A schematic diagram of the structure of a data compression device provided in an embodiment of the present application;
[0051] Figure 5 A schematic diagram of the structure of a data compression device provided in an embodiment of the present application;
[0052] Figure 6 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0053] In order to make the purpose, technical solution and advantages of the embodiments of the present application clearer, 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 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 making creative work are within the scope of protection of this application.
[0054] The disclosure below provides many different embodiments or examples to implement different structures of the present invention. In order to simplify the disclosure of the present invention, the parts and settings of specific examples are described below. Of course, they are only examples, and the purpose is not to limit the present invention. In addition, the present invention can repeat reference numbers and / or letters in different examples. This repetition is for the purpose of simplification and clarity, and does not itself indicate the relationship between the various embodiments and / or settings discussed.
[0055] In order to solve the problem that it is difficult to take into account both communication quality and communication efficiency in existing data compression methods, the present application provides a data compression method, an electronic device and a storage medium, which can take into account both communication quality and communication efficiency.
[0056] See also Figure 1 , Figure 1 A flow chart of a data compression method provided in an embodiment of the present application. Figure 1 As shown, the data compression method may include the following steps:
[0057] Step 101: Receive a first interface access request sent by a client, wherein the first interface access request carries first field information and first transmission data, the first field information is used to characterize a first average access time required for accessing the interface when the client does not use any compression algorithm for data compression, and the first transmission data refers to data transmitted by the client to the server.
[0058] It should be noted that the data compression method provided in the embodiment of the present application is applied to a server, and the server can provide a data access interface for a client to access data, so as to realize data transmission between the server and the client.
[0059] Specifically, the above-mentioned first interface access request can be an HTTP request message, which can carry the first field information and the first transmission data, wherein the first field information is used to characterize the first average access time required for the client to access the interface when no compression algorithm is used for data compression, and the first field here can be a field in the request header of the HTTP request message. The first average access time can be understood as the ratio between the total interface access time and the number of interface accesses of the client within the preset calculation period. It should be noted that the preset calculation period here can be set according to actual needs, and the embodiment of the present application is not specifically limited. Specifically, before the client initiates the first interface access request each time, the client will use the current time point as the end time point of the preset calculation period, and count the total interface access time and the number of interface accesses within the preset calculation period before the first interface access request is initiated, and encapsulate the ratio of the total interface access time to the number of interface accesses as the first average access time into the first interface access request. For example, assuming that the preset calculation period is 10 minutes, the preset calculation period is 10 minutes before the client initiates the first interface access request.
[0060] After receiving the first interface access request sent by the client, the server may parse the first interface access request to obtain the first field information and the first transmission data in the first interface access request.
[0061] Step 102: In response to the first interface access request, obtain second transmission data to be returned to the client, and determine the total amount of transmission data according to the first transmission data and the second transmission data.
[0062] After receiving the first interface access request sent by the client, the server can parse the first interface access request to obtain the first field information and the first transmission data in the first interface access request, and perform business interaction in response to the first interface access request to obtain the second transmission data to be returned to the client, so that the total amount of transmission data can be determined based on the first transmission data and the second transmission data. The total amount of transmission data here can be the sum of the first transmission data and the second transmission data.
[0063] Step 103: Based on the first average access time and the total amount of transmitted data, determine whether a trigger condition for data compression is currently met.
[0064] It should be noted that the trigger condition for data compression here can be that the first average access time is greater than the specified threshold, or the total amount of transmitted data is greater than the specified threshold, or both the first average access time and the total amount of transmitted data are greater than the specified threshold, and the embodiments of the present application do not make specific limitations.
[0065] In this step, the server can determine whether the triggering condition for data compression is currently met based on the first average access time and the total amount of transmitted data. If it is determined that the triggering condition for data compression is currently met, step 104 is executed; if it is determined that the triggering condition for data compression is currently not met, the above steps 101 to 103 are repeated.
[0066] Step 104: When it is determined that the triggering condition for data compression is currently met, multiple compression levels in the preset compression algorithm are dynamically adjusted to obtain the best compression level, and the best compression level is encapsulated as the second field information in the response message and sent to the client.
[0067] Specifically, the preset compression algorithm refers to one or more compression algorithms pre-set in the server, each compression algorithm can be configured with multiple compression levels, and different compression levels have different compression degrees for data.
[0068] In this step, when the server determines that the trigger conditions for data compression are currently met, it can dynamically adjust multiple compression levels in the preset compression algorithm, and finally obtain the optimal compression level, and then encapsulate the optimal compression level as the second field information in the response message and send it to the client. Specifically, the second field can be a field in the response header in the HTTP response message. It should be noted that when the server dynamically adjusts the multiple compression levels in the preset compression algorithm, the server will also encapsulate the compression level after each dynamic adjustment as the second field information in the response message and send it to the client. In this way, the client can calculate the second average access time based on the compression level carried in each response message, and carry the calculation result in the second interface access request and send it to the server, so that the server can make further adjustments to the multiple compression levels in the preset compression algorithm based on the second average access time in the second interface access request.
[0069] Step 105: Use the best compression level to compress the data transmitted to and from the client.
[0070] After determining the optimal compression level, the client and the server may use the optimal compression level to compress the transmission data before transmission, so as to ensure that the communication quality and communication efficiency of the client and the server are both in a good state.
[0071] In this embodiment, the server can dynamically adjust multiple compression levels in the preset compression algorithm when it is determined that the trigger conditions for data compression are currently met, thereby effectively avoiding the problem of using a fixed compression algorithm and a fixed compression level for data compression in the prior art, which leads to waste of system resources when the amount of data transmitted is small, and packet errors when the amount of data transmitted is large, thereby achieving the purpose of taking into account both communication quality and communication efficiency.
[0072] Furthermore, the number of preset compression algorithms is one; the above step 104, dynamically adjusting multiple compression levels in the preset compression algorithm to obtain the optimal compression level, includes:
[0073] Sequentially traverse multiple compression levels in the preset compression algorithm, and sequentially encapsulate the traversed compression levels as second field information into a response message and send it to the client;
[0074] Sequentially receive second interface access requests sent by the client based on the compression level carried in each response message, and determine a minimum second average access duration corresponding to a preset compression algorithm based on each received second interface access request, wherein different second interface access requests carry second average access durations corresponding to different compression levels;
[0075] Determine whether the minimum second average access time corresponding to the preset compression algorithm is less than the first preset threshold;
[0076] When it is determined that the minimum second average access time corresponding to the preset compression algorithm is less than the first preset threshold, the compression level of the minimum second average access time corresponding to the preset compression algorithm is determined as the optimal compression level.
[0077] Specifically, the first preset threshold can be set according to actual needs and is not limited in the embodiment of the present application, for example, 5 seconds.
[0078] In one embodiment, when there is only one preset compression algorithm in the server, and the preset compression algorithm includes multiple compression levels, when the server dynamically adjusts the multiple compression levels in the preset compression algorithm, it can sequentially traverse the multiple compression levels in the preset compression algorithm, and sequentially encapsulate the traversed compression levels as the second field information into the response message and send it to the client. In this way, after receiving each response message, the client can calculate the second average access time corresponding to each compression level based on the compression level carried in each response message, and carry the second average access time in the second interface access request and send it to the server. In this way, the server will sequentially receive the second interface access request sent by the client, and determine the minimum second average access time corresponding to the preset compression algorithm based on each received second interface access request, and then determine whether the minimum second average access time corresponding to the preset compression algorithm is less than the first preset threshold value. If the minimum second average access time corresponding to the preset compression algorithm is less than the first preset threshold value, it means that the average access time required for the access interface reaches the optimal state and meets the user's expected requirements. At this time, the compression level of the minimum second average access time corresponding to the preset compression algorithm can be determined as the best compression level.
[0079] Through the above method, the server can traverse multiple compression levels in a preset compression algorithm in turn, and dynamically adjust the multiple compression levels in the preset compression algorithm according to the second average access time calculated by the client based on each compression level, so as to accurately determine the optimal compression level, ensuring better communication quality and higher communication efficiency between the server and the client.
[0080] Furthermore, in the above step, based on each received second interface access request, determining the minimum second average access duration corresponding to the preset compression algorithm includes:
[0081] Compare the second average access duration in the currently received second interface access request with the second average access duration in the last received second interface access request;
[0082] When the second average access duration in the currently received second interface access request is greater than the second average access duration in the last received second interface access request, the second average access duration in the last received second interface access request is determined as the minimum second average access duration corresponding to the preset compression algorithm;
[0083] When the second average access time in the currently received second interface access request is less than or equal to the second average access time in the last received second interface access request, continue to traverse the next compression level in the preset compression algorithm, and compare the second average access time in the next received second interface access request with the second average access time in the currently received second interface access request, and repeat the process until the traversal is stopped when a first preset condition is met, wherein the first preset condition is that all compression levels in the preset compression algorithm have been traversed, or the minimum second average access time corresponding to the preset compression algorithm is detected.
[0084] In one embodiment, in the process of determining the minimum second average access time corresponding to the preset compression algorithm, the server may compare the second average access time in the currently received second interface access request with the second average access time in the last received second interface access request. If the second average access time in the currently received second interface access request is greater than the second average access time in the last received second interface access request, the second average access time in the last received second interface access request is determined as the minimum second average access time corresponding to the preset compression algorithm; if the second average access time in the currently received second interface access request is less than or equal to the second average access time in the last received second interface access request, the next compression level in the preset compression algorithm is continued to be traversed, and the second average access time in the next received second interface access request is continued to be compared with the second average access time in the currently received second interface access request, and the traversal is stopped in sequence until the first preset condition is met. The first preset condition here is that all compression levels in the preset compression algorithm have been traversed, or the minimum second average access time corresponding to the preset compression algorithm is detected.
[0085] For example, assuming that the preset compression algorithm is the Deflate algorithm, and the Deflate algorithm includes three compression levels, namely level 0, level 1 and level 2, the server can, when determining that the trigger condition for data compression is currently met, encapsulate level 0 as the second field information in the response message and send it to the client. At this time, both the client and the server use level 0 for data compression and transmission. At the same time, the client counts the corresponding second average access time in the current preset calculation cycle, and encapsulates the second average access time as the first field information in the second interface access request and sends it to the server. Then the server can record the second average access time corresponding to level 0, and encapsulate level 1 as the second field information in the response message and send it to the client. At this time, both the client and the server use level 1 for data compression and transmission. At the same time, the client counts the corresponding second average access time in the current preset calculation cycle, and encapsulates the second average access time as the first field information in the second interface access request and sends it to the server. Then, the server can receive the second average access time corresponding to level 1, and determine whether the second average access time corresponding to level 1 is greater than the second average access time corresponding to level 0. If the second average access time corresponding to level 1 is greater than the second average access time corresponding to level 0, then stop traversing level 2, and determine the second average access time corresponding to level 0 as the minimum second average access time corresponding to the preset compression algorithm. If the second average access time corresponding to level 1 is less than or equal to the second average access time corresponding to level 0, then continue to traverse level 2, and encapsulate level 2 as the second field information in the response message and send it to the client. At this time, both the client and the server use level 2 for data compression and transmission. At the same time, the client counts the corresponding second average access time within the current preset calculation cycle, and encapsulates the second average access time as the first field information in the second interface access request and sends it to the server. Then, the server may receive the second average access time corresponding to level 2, and determine whether the second average access time corresponding to level 2 is greater than the second average access time corresponding to level 1. If the second average access time corresponding to level 2 is greater than the second average access time corresponding to level 1, the traversal is stopped, and the second average access time corresponding to level 1 is determined as the minimum second average access time corresponding to the preset compression algorithm. If the second average access time corresponding to level 2 is less than or equal to the second average access time corresponding to level 1, the traversal is stopped, and the second average access time corresponding to level 2 is determined as the minimum second average access time corresponding to the preset compression algorithm.
[0086] Through the above method, the server can dynamically adjust multiple compression levels in the preset compression algorithm according to the second average access time in each second interface access request received during data interaction with the client, thereby accurately determining the optimal compression level to ensure good communication quality and high communication efficiency between the server and the client.
[0087] Furthermore, there are multiple preset compression algorithms, and the above step 104, dynamically adjusting multiple compression levels in the preset compression algorithms to obtain the optimal compression level, includes:
[0088] When the minimum second average access time corresponding to the first compression algorithm is greater than or equal to the first preset threshold, traverse the multiple compression levels in the second compression algorithm in sequence, and encapsulate the traversed compression levels in the second compression algorithm as the second field information in sequence into a response message and send it to the client;
[0089] receiving in sequence the second interface access requests sent by the client based on the compression level carried in each response message, and determining the minimum second average access time corresponding to the second compression algorithm based on each received second interface access request, wherein different second interface access requests carry second average access times corresponding to different compression levels;
[0090] Determine whether the minimum second average access time corresponding to the second compression algorithm is less than a first preset threshold;
[0091] In the case where it is determined that the minimum second average access time corresponding to the second compression algorithm is less than the first preset threshold, the compression level of the minimum second average access time corresponding to the second compression algorithm is determined as the optimal compression level;
[0092] When it is determined that the minimum second average access time corresponding to the second compression algorithm is greater than or equal to the first preset threshold, continue to traverse the multiple compression levels in the third compression algorithm in sequence, and loop in sequence until the traversal is stopped when the second preset condition is met, wherein the second preset condition is that all compression levels of the multiple compression algorithms in the preset compression algorithm have been traversed, or it is detected that the minimum second average access time corresponding to any compression algorithm is less than the first preset threshold, and the first compression algorithm, the second compression algorithm and the third compression algorithm belong to the preset compression algorithms.
[0093] In one embodiment, the preset compression algorithm in the server may include multiple compression algorithms, and each compression algorithm may be configured with multiple compression levels, so that when the server dynamically adjusts the compression level, it may traverse the compression levels in each compression algorithm in turn. Specifically, when the minimum second average access time corresponding to the first compression algorithm is greater than or equal to the first preset threshold, the server may traverse the multiple compression levels in the second compression algorithm in turn, and encapsulate the traversed compression levels in the second compression algorithm as the second field information in turn into a response message and send it to the client, and then receive the second interface access request sent by the client based on the compression level carried in each response message in turn, and determine the minimum second average access time corresponding to the second compression algorithm based on each received second interface access request. Then, it is determined whether the minimum second average access time corresponding to the second compression algorithm is less than the first preset threshold. If the minimum second average access time corresponding to the second compression algorithm is less than the first preset threshold, the compression level of the minimum second average access time corresponding to the second compression algorithm is determined as the optimal compression level. If the minimum second average access time corresponding to the second compression algorithm is greater than or equal to the first preset threshold, the multiple compression levels in the third compression algorithm are traversed in sequence, and the traversal is stopped in sequence until the second preset condition is met. The second preset condition here is that all compression levels of the multiple compression algorithms in the preset compression algorithm have been traversed, or it is detected that the minimum second average access time corresponding to any compression algorithm is less than the first preset threshold.
[0094] It should be noted that the method for determining the minimum second average access time in the first compression algorithm, the second compression algorithm and the third compression algorithm is the same as the method for determining the minimum second average access time in the preset compression algorithm in the aforementioned embodiment, and will not be repeated here.
[0095] In the above manner, if the second average access times corresponding to all compression levels in a certain compression algorithm are greater than the first preset threshold, the compression levels in other preset compression algorithms can be traversed to expand the adjustment range of the compression level and improve the matching probability of the optimal compression level.
[0096] Furthermore, the above step 103, based on the first average access time and the total amount of transmitted data, determines whether the triggering condition for data compression is currently met, including:
[0097] Determine whether the total amount of transmitted data is greater than a second preset threshold, and whether the first average access time is greater than a third preset threshold;
[0098] When it is determined that the total amount of transmitted data is greater than the second preset threshold value, and the first average access time is greater than the third preset threshold value, determining that the trigger condition for data compression is currently met;
[0099] When it is determined that the total amount of transmitted data is less than or equal to the second preset threshold, and / or the first average access time is less than or equal to the third preset threshold, it is determined that the trigger condition for data compression is not currently met.
[0100] Specifically, the second preset threshold and the third preset threshold can be set according to actual needs and are not specifically limited in the embodiment of the present application. For example, the second preset threshold is 1 megabyte, the third preset threshold is 5 seconds, etc.
[0101] In one embodiment, when determining whether the trigger condition for data compression is currently met, the server may first determine whether the total amount of transmitted data is greater than a second preset threshold, and whether the first average access time is greater than a third preset threshold; if the total amount of transmitted data is greater than the second preset threshold, and the first average access time is greater than the third preset threshold, then it can be determined that the trigger condition for data compression is currently met; if the total amount of transmitted data is less than or equal to the second preset threshold, and / or the first average access time is less than or equal to the third preset threshold, then it can be determined that the trigger condition for data compression is not currently met.
[0102] Through the above method, when the client and the server adopt the original transmission method for data transmission, it can be accurately judged whether the trigger condition for data compression is currently met based on the first average access time and the total amount of transmitted data, thereby ensuring that when the first average access time is long and the total amount of transmitted data is large, the transmission data is compressed to improve the communication quality and communication efficiency between the client and the server.
[0103] Furthermore, after the above step 105, in which the data transmitted to and from the client is compressed using the optimal compression level, the method further includes:
[0104] Acquire the duration of data compression in real time, wherein the duration of data compression refers to the duration between the current time point and the time point at which the trigger condition for data compression is determined to be satisfied;
[0105] When the duration of data compression reaches a fourth preset threshold, setting the second field information in the response message to empty, and sending the set response message to the client;
[0106] The original data transmission mode is used to transmit the transmission data between the client and the client, wherein the original data transmission mode refers to a data transmission mode that does not use any compression algorithm to compress the transmission data.
[0107] Specifically, the fourth preset threshold can be set according to actual needs and is not specifically limited in the embodiment of the present application. For example, the fourth preset threshold is 24 hours.
[0108] In one embodiment, after the server compresses the transmission data between the server and the client using the optimal compression level, it can also obtain the duration of the data compression in real time, and compare the duration of the data compression with a fourth preset threshold. When the duration of the data compression reaches the fourth preset threshold, the second field information in the response message can be set to empty, and the set response message can be sent to the client. In this way, the server can use the original data transmission method to transmit the transmission data between the server and the client.
[0109] Through the above method, the duration of data compression can be controlled according to the set fourth preset threshold, and the data transmission mode can be restored to the original data transmission mode. This is conducive to starting data compression in time according to business conditions when business needs change, and adjusting the compression level to the optimal compression level.
[0110] See also Figure 2 , Figure 2 A flowchart of another data compression method provided in an embodiment of the present application is shown below. Figure 2 As shown, the data compression method may include the following steps:
[0111] Step 201: Send a first interface access request to the server, wherein the first interface access request carries first field information and first transmission data, the first field information is used to characterize a first average access time required for accessing the interface when the client does not use any compression algorithm for data compression, and the first transmission data refers to data that the client needs to transmit to the server.
[0112] It should be noted that the data compression method provided in the embodiment of the present application is applied to the client, and the client can send an interface access request to the server. After receiving the interface access request sent by the client, the server can feedback a response message to the client to realize data transmission between the server and the client.
[0113] Specifically, the above-mentioned first interface access request can be an HTTP request message, which can carry the first field information and the first transmission data, wherein the first field information is used to characterize the first average access time required for the client to access the interface when no compression algorithm is used for data compression, and the first field here can be a field in the request header of the HTTP request message. The first average access time can be understood as the ratio between the total interface access time and the number of interface accesses of the client within the preset calculation period. It should be noted that the preset calculation period here can be set according to actual needs, and the embodiment of the present application is not specifically limited. Specifically, before the client initiates the first interface access request each time, the client will use the current time point as the end time point of the preset calculation period, and count the total interface access time and the number of interface accesses within the preset calculation period before the first interface access request is initiated, and encapsulate the ratio of the total interface access time to the number of interface accesses as the first average access time into the first interface access request. For example, assuming that the preset calculation period is 10 minutes, the preset calculation period is 10 minutes before the client initiates the first interface access request.
[0114] Step 202, receiving a response message returned by the server in response to the first interface access request, wherein the second field information of the response message is an optimal compression level, and the optimal compression level is obtained by the server dynamically adjusting multiple compression levels in a preset compression algorithm when it is determined that the trigger condition for data compression is currently met, and the trigger condition for data compression is determined by the server based on the first average access time and the total amount of transmitted data, and the total amount of transmitted data is the sum of the first transmission data transmitted by the client to the server and the second transmission data to be returned by the server to the client.
[0115] In this step, after receiving the first interface access request sent by the client, the server can parse the first interface access request to obtain the first field information and the first transmission data in the first interface access request, and perform business interaction in response to the first interface access request to obtain the second transmission data to be returned to the client, so that the total amount of transmission data can be determined based on the first transmission data and the second transmission data. The total amount of transmission data here can be the sum of the first transmission data and the second transmission data. Then, the server can determine whether the trigger condition for data compression is currently met based on the first average access time and the total amount of transmission data. If it is determined that the trigger condition for data compression is currently met, the multiple compression levels in the preset compression algorithm are dynamically adjusted to obtain the best compression level, and the best compression level is encapsulated as the second field information in the response message and sent to the client. Specifically, when the server determines that the trigger condition for data compression is currently met, the multiple compression levels in the preset compression algorithm can be dynamically adjusted to finally obtain the best compression level, and then the best compression level is encapsulated as the second field information in the response message and sent to the client. Specifically, the second field can be a field in the response header in the HTTP response message. It should be noted that, when the server is dynamically adjusting multiple compression levels in the preset compression algorithm, the server will also encapsulate the compression level after each dynamic adjustment as the second field information in the response message and send it to the client. In this way, the client can calculate the average access time based on the compression level carried in each response message, and carry the calculation result in the second interface access request and send it to the server, so that the server can make further adjustments to the multiple compression levels in the preset compression algorithm based on the average access time in the second interface access request.
[0116] Step 203: Use the best compression level to compress the data transmitted to and from the server.
[0117] After determining the optimal compression level, the client and the server may use the optimal compression level to compress the transmission data before transmission, so as to ensure that the communication quality and communication efficiency of the client and the server are both in a good state.
[0118] In this embodiment, the server can dynamically adjust multiple compression levels in the preset compression algorithm when it is determined that the trigger conditions for data compression are currently met, thereby effectively avoiding the problem of using a fixed compression algorithm and a fixed compression level for data compression in the prior art, which leads to waste of system resources when the amount of data transmitted is small, and packet errors when the amount of data transmitted is large, thereby achieving the purpose of taking into account both communication quality and communication efficiency.
[0119] Furthermore, after compressing the data transmitted to and from the server at step 203 using the best compression level, the method further includes:
[0120] When the duration of data compression reaches a fourth preset threshold, receiving a set response message returned by the server, wherein the second field information in the set response message is empty;
[0121] The original data transmission mode is used to transmit the data between the server and the server, wherein the original data transmission mode refers to a data transmission mode that does not use any compression algorithm to compress the transmission data.
[0122] In one embodiment, after the server compresses the transmission data between the server and the client using the optimal compression level, it can also obtain the duration of the data compression in real time, and compare the duration of the data compression with a fourth preset threshold. When the duration of the data compression reaches the fourth preset threshold, the second field information in the response message can be set to empty, and the set response message can be sent to the client. In this way, the client can receive the set response message returned by the server, and use the original data transmission method to transmit the transmission data between the server.
[0123] Through the above method, the duration of data compression can be controlled according to the set fourth preset threshold, and the data transmission mode can be restored to the original data transmission mode. This is conducive to starting data compression in time according to business conditions when business needs change, and adjusting the compression level to the optimal compression level.
[0124] In one embodiment, the data compression process provided by the embodiment of the present application is as follows: Figure 3 As shown, the following steps may be specifically included:
[0125] Step 301: The client counts the average access duration of the interface within a calculation cycle.
[0126] The calculation period here is the preset calculation period mentioned above. For ease of understanding, the average access time is explained here using 10 minutes as the calculation period, that is, the average access time is the total access time of the interface within 10 minutes divided by the number of accesses to the interface within 10 minutes.
[0127] Step 302: The client sends the average access duration information to the server.
[0128] As an optional implementation, average access duration field information may be added to the HTTP request header information and sent to the server.
[0129] Step 303: The server performs business processing.
[0130] Step 304: Before returning the response message, the server calculates the size of the data received and returned by the interface to obtain the total amount of transmitted data.
[0131] Step 305: The server determines whether the total amount of transmitted data is greater than a threshold.
[0132] Step 306: The server determines whether the average access time is greater than a threshold.
[0133] Specifically, before initiating an interface access request each time, the client obtains the total access time, the number of accesses and other information within the 10-minute calculation cycle of the current record, and then calculates the average access time within 10 minutes by dividing the total access time by the number of accesses. Then, by adding the average access time field to the HTTP request header information, the average access time information is transmitted to the server. After receiving the interface access request from the client, the server performs normal business logic processing. After completing the business logic processing, the size of the information to be responded to the client and the client-incoming data are added to obtain the total amount of transmitted data, and the average access time field information transmitted in the client request is obtained at the same time. The server combines the total amount of transmitted data and the average access time to make a judgment. When the total amount of transmitted data is less than or equal to the threshold, it means that the interface transmits a small amount of data, and there is no need to compress the data at this time, and the process ends. When the total amount of transmitted data is greater than the threshold, it means that the interface transmits a large amount of data, and at this time it is necessary to make further judgments in combination with the average access time of the interface. Then it is judged whether the average access time of the interface is greater than the threshold. When the average access time is greater than the threshold, it means that the interface access speed is abnormal, and data compression needs to be triggered at this time. When the average access time is less than or equal to the threshold, it indicates that the interface access speed is fast. In this case, there is no need to trigger data compression and the process ends.
[0134] Step 307: The server selects a compression algorithm and adjusts the compression level.
[0135] Step 308: The server determines whether there is an adjustable compression level.
[0136] Step 309: The client and the server compress and decompress the transmission data.
[0137] It should be noted that the purpose of adaptive adjustment of the compression level is to find the compression level that can achieve the best transmission efficiency. When the triggering conditions for data compression are met, the server uses the Deflate algorithm in the example and sets the compression level to 0 to compress the information to be returned to the client. When the compression is completed, the Deflate algorithm and compression level 0 are set as the field values in the HTTP response header information. The compressed data is returned to the client together with the response header information.
[0138] After receiving the response information, the client checks whether there is a value in the preset field in the response header. If there is a value, it means that the data needs to be decompressed. The client and the server use the compression algorithm and compression level to compress / decompress the data when sending / receiving data, and then interact to calculate the average access time in a calculation cycle. When the client request of a calculation cycle ends and the client request of the next calculation cycle begins, the Deflate compression algorithm continues to be used and the compression level is increased by one level (i.e., compression level 1), and the previous steps are repeated. When the average access time calculated in the next calculation cycle is less than the average access time calculated in the previous calculation cycle, the compression level continues to be increased in the next calculation cycle until the average access time calculated in the next calculation cycle is greater than the average access time calculated in the previous calculation cycle. At this time, the compression level is reduced to the compression level of the previous calculation cycle. At the same time, during the adjustment process, if the compression level adjustment has reached the maximum or minimum, stop adjusting the compression level.
[0139] In this way, the best compression level of the interface under this compression algorithm can be obtained. Next, the average access time under the best compression level is compared with the threshold to determine whether the current average access time is less than the threshold. If the current average access time is less than the threshold, no further adjustment is required. Subsequent interface accesses continue to use the compression algorithm and compression level for data compression processing until the duration of data compression reaches the fourth preset threshold (such as 24 hours), then all compression processing is reset and the original data transmission method is restored. However, if the average access time under the best compression level is still greater than the average access time threshold, the compression algorithm is adjusted.
[0140] Step 310: The server determines whether there is an adjustable compression algorithm.
[0141] The purpose of adaptively adjusting the compression algorithm is to adjust the compression algorithm to try to reduce the average access time when the condition that the average access time is less than a threshold cannot be met after all compression levels of a compression algorithm are adjusted.
[0142] If the Deflate compression algorithm in the current example cannot make the average access time less than the threshold at all compression levels, the Brotli compression algorithm can be used instead of the Deflate compression algorithm, and the steps of adaptively adjusting the compression level are repeated. If the Brotli compression algorithm cannot make the average access time less than the threshold at all compression levels, continue to try other configured compression algorithms until the average access time threshold is reached and no adaptive adjustment is made. If all algorithms and all compression levels cannot make the average access time less than the threshold, reset all compression processing and restore the original data transmission method.
[0143] Step 311: The server adjusts the compression algorithm.
[0144] In an embodiment of the present application, the average access time and the total amount of transmitted data are combined to compress the HTTP interface interaction data where the interaction time between the client and the server is too slow. By adjusting the compression level and compression algorithm in a step-by-step manner, the compression time and transmission time are balanced, and the optimal compression algorithm and compression level of the interface in the current state are gradually detected to achieve the best transmission efficiency, thereby improving the efficiency of the overall system.
[0145] See also Figure 4 , Figure 4 A schematic diagram of the structure of a data compression device provided in an embodiment of the present application is shown in FIG. Figure 4 As shown, the data compression device is applied to a server, and the device 400 includes:
[0146] The first receiving module 401 is used to receive a first interface access request sent by a client, wherein the first interface access request carries first field information and first transmission data, the first field information is used to represent a first average access time required for the client to access the interface when no compression algorithm is used for data compression, and the first transmission data refers to data transmitted by the client to the server;
[0147] A first acquisition module 402 is used to acquire second transmission data to be returned to the client in response to the first interface access request, and determine the total amount of transmission data according to the first transmission data and the second transmission data;
[0148] A determination module 403, configured to determine whether a trigger condition for data compression is currently satisfied based on the first average access time and the total amount of transmitted data;
[0149] The adjustment module 404 is used to dynamically adjust multiple compression levels in the preset compression algorithm to obtain the best compression level when it is determined that the trigger condition of data compression is currently met, and encapsulate the best compression level as the second field information into the response message and send it to the client;
[0150] The first compression module 405 is used to compress the data transmitted between the client and the client using an optimal compression level.
[0151] Furthermore, the number of preset compression algorithms is one; the adjustment module 404 includes:
[0152] The first traversal submodule is used to traverse multiple compression levels in the preset compression algorithm in sequence, and encapsulate the traversed compression levels as the second field information in the response message and send it to the client;
[0153] A first determination submodule is used to sequentially receive second interface access requests sent by the client based on the compression level carried in each response message, and determine a minimum second average access duration corresponding to a preset compression algorithm based on each received second interface access request, wherein different second interface access requests carry second average access durations corresponding to different compression levels;
[0154] A first judgment submodule, used to judge whether the minimum second average access time corresponding to the preset compression algorithm is less than a first preset threshold;
[0155] The second determination submodule is used to determine the compression level of the minimum second average access time corresponding to the preset compression algorithm as the optimal compression level when it is determined that the minimum second average access time corresponding to the preset compression algorithm is less than the first preset threshold.
[0156] Furthermore, the first determining submodule includes:
[0157] a comparing unit, configured to compare the second average access duration in the currently received second interface access request with the second average access duration in the last received second interface access request;
[0158] a determining unit, configured to determine the second average access duration in the second interface access request received last as the minimum second average access duration corresponding to the preset compression algorithm, when the second average access duration in the second interface access request currently received is greater than the second average access duration in the second interface access request received last;
[0159] A loop unit is used to continue to traverse the next compression level in the preset compression algorithm when the second average access time in the second interface access request currently received is less than or equal to the second average access time in the second interface access request last received, and compare the second average access time in the second interface access request received next time with the second average access time in the second interface access request currently received, and loop in sequence until the traversal is stopped when a first preset condition is met, wherein the first preset condition is that all compression levels in the preset compression algorithm have been traversed, or the minimum second average access time corresponding to the preset compression algorithm is detected.
[0160] Furthermore, there are multiple preset compression algorithms; the adjustment module 404 includes:
[0161] A second traversal submodule is used to traverse the multiple compression levels in the second compression algorithm in sequence when the minimum second average access time corresponding to the first compression algorithm is greater than or equal to the first preset threshold, and encapsulate the traversed compression levels in the second compression algorithm in sequence as second field information into a response message and send it to the client;
[0162] A third determination submodule is used to sequentially receive second interface access requests sent by the client based on the compression level carried in each response message, and determine the minimum second average access time corresponding to the second compression algorithm based on each received second interface access request, wherein different second interface access requests carry second average access times corresponding to different compression levels;
[0163] A second judgment submodule, used to judge whether the minimum second average access time corresponding to the second compression algorithm is less than a first preset threshold;
[0164] A fourth determination submodule, configured to determine the compression level of the minimum second average access time corresponding to the second compression algorithm as the optimal compression level when it is determined that the minimum second average access time corresponding to the second compression algorithm is less than the first preset threshold;
[0165] A loop submodule is used to continue to traverse multiple compression levels in the third compression algorithm in sequence when it is determined that the minimum second average access time corresponding to the second compression algorithm is greater than or equal to the first preset threshold, and to loop in sequence until the traversal is stopped when the second preset condition is met, wherein the second preset condition is that all compression levels of the multiple compression algorithms in the preset compression algorithm have been traversed, or it is detected that the minimum second average access time corresponding to any compression algorithm is less than the first preset threshold, and the first compression algorithm, the second compression algorithm and the third compression algorithm belong to the preset compression algorithms.
[0166] Furthermore, the preset compression algorithm includes multiple compression algorithms, and the device 400 also includes:
[0167] A traversal module, configured to sequentially traverse multiple compression levels in a second compression algorithm among the multiple compression algorithms when multiple compression levels in a first compression algorithm among the multiple compression algorithms have been traversed and no second interface access request with a second average access time less than a first preset threshold has been received;
[0168] A judging module, used to judge in turn whether the second average access time corresponding to each compression level in the second compression algorithm is less than a first preset threshold;
[0169] A stop traversal module is used to continue to traverse multiple compression levels in a third compression algorithm among multiple compression algorithms in sequence when it is determined that the second average access time corresponding to each compression level in the second compression algorithm is greater than or equal to a first preset threshold, and to loop in sequence until the traversal is stopped when a second preset condition is met, wherein the second preset condition is that the compression levels corresponding to all compression algorithms in the multiple compression algorithms have been traversed, or a second interface access request with a second average access time less than the first preset threshold is received.
[0170] Further, the determination module 403 includes:
[0171] A third judgment submodule, used to judge whether the total amount of transmitted data is greater than a second preset threshold, and whether the first average access time is greater than a third preset threshold;
[0172] A fifth determination submodule, configured to determine that a trigger condition for data compression is currently satisfied when it is determined that the total amount of transmitted data is greater than a second preset threshold and the first average access time is greater than a third preset threshold;
[0173] The sixth determination submodule is used to determine that the trigger condition for data compression is not currently met when it is determined that the total amount of transmitted data is less than or equal to the second preset threshold and / or the first average access time is less than or equal to the third preset threshold.
[0174] Furthermore, the device 400 further includes:
[0175] A second acquisition module is used to acquire the duration of data compression in real time, wherein the duration of data compression refers to the duration between the current time point and the time point at which the trigger condition of data compression is determined to be satisfied;
[0176] A setting module, configured to set the second field information in the response message to be empty when the duration of data compression reaches a fourth preset threshold, and send the set response message to the client;
[0177] The first transmission module is used to transmit the transmission data between the client and the client by adopting the original data transmission mode, wherein the original data transmission mode refers to a data transmission mode that does not use any compression algorithm to compress the transmission data.
[0178] It should be noted that the device 400 can implement the above Figure 1 The data compression method provided by the method embodiment shown can achieve the same technical effect, and will not be described in detail here.
[0179] See also Figure 5 , Figure 5 A schematic diagram of the structure of a data compression device provided in an embodiment of the present application is shown in FIG. Figure 5As shown, the data compression device is applied to a client, and the device 500 includes:
[0180] A sending module 501 is used to send a first interface access request to a server, wherein the first interface access request carries first field information and first transmission data, the first field information is used to represent a first average access time required for the client to access the interface when the client does not use any compression algorithm for data compression, and the first transmission data refers to data that the client needs to transmit to the server;
[0181] The second receiving module 502 is used to receive a response message returned by the server in response to the first interface access request, wherein the second field information of the response message is an optimal compression level, and the optimal compression level is obtained by the server dynamically adjusting multiple compression levels in a preset compression algorithm when determining that a trigger condition for data compression is currently met, and the trigger condition for data compression is determined by the server based on a first average access time and a total amount of transmitted data, and the total amount of transmitted data is the sum of first transmitted data transmitted by the client to the server and second transmitted data to be returned by the server to the client;
[0182] The second compression module 503 is used to compress the data transmitted to and from the server using an optimal compression level.
[0183] Furthermore, the device 500 also includes:
[0184] A third receiving module is used to receive a set response message returned by the server when the duration of data compression reaches a fourth preset threshold, wherein the second field information in the set response message is empty;
[0185] The second transmission module is used to transmit the transmission data between the server and the server in an original data transmission mode, wherein the original data transmission mode refers to a data transmission mode that does not use any compression algorithm to compress the transmission data.
[0186] It should be noted that the device 500 can implement the above Figure 2 The data compression method provided by the method embodiment shown can achieve the same technical effect, and will not be described in detail here.
[0187] like Figure 6 As shown, the embodiment of the present application further provides an electronic device, including a processor 611, a communication interface 612, a memory 613 and a communication bus 614, wherein the processor 611, the communication interface 612, and the memory 613 communicate with each other through the communication bus 614.
[0188] Memory 613, used for storing computer programs;
[0189] In one embodiment of the present application, the processor 611 is used to implement the data compression method provided by any one of the aforementioned method embodiments when executing the program stored in the memory 613.
[0190] An embodiment of the present application also provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the data compression method provided by any of the aforementioned method embodiments is implemented.
[0191] The device embodiments described above are merely illustrative, wherein 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, i.e., they may be located in one place, or may be distributed over multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0192] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a general hardware platform, and of course, by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the relevant technology can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.
[0193] It should be understood that the terms used herein are only for the purpose of describing specific example embodiments and are not intended to be limiting. Unless the context clearly indicates otherwise, the singular forms "one", "an" and "said" as used herein may also be meant to include plural forms. The terms "include", "comprise", "contain", and "have" are inclusive, and therefore specify the existence of stated features, steps, operations, elements and / or parts, but do not exclude the existence or addition of one or more other features, steps, operations, elements, parts, and / or combinations thereof. The method steps, processes, and operations described herein are not interpreted as necessarily requiring them to be performed in the specific order described or illustrated, unless the execution order is clearly indicated. It should also be understood that additional or alternative steps may be used.
[0194] The foregoing is merely a specific embodiment of the present invention, which enables those skilled in the art to understand or implement the present invention. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention will not be limited to the embodiments shown herein, but rather to the widest scope consistent with the principles and novel features claimed herein.
Claims
1. A data compression method, characterized in that: Applied to a server, the method comprises: Receive a first interface access request sent by a client, wherein the first interface access request carries first field information and first transmission data, the first field information is used to represent a first average access time required for the client to access the interface when no compression algorithm is used for data compression, and the first transmission data refers to data transmitted by the client to the server; In response to the first interface access request, obtaining second transmission data to be returned to the client, and determining a total amount of transmission data according to the first transmission data and the second transmission data; Based on the first average access time and the total amount of transmitted data, determining whether a trigger condition for data compression is currently met; In the case of determining that the trigger condition for data compression is currently met, dynamically adjusting multiple compression levels in the preset compression algorithm to obtain an optimal compression level, and encapsulating the optimal compression level as second field information into a response message and sending it to the client; The optimal compression level is used to compress the transmission data between the client and the client.
2. The method according to claim 1, characterized in that The number of the preset compression algorithms is one; the multiple compression levels in the preset compression algorithms are dynamically adjusted to obtain the optimal compression level, including: Sequentially traverse multiple compression levels in the preset compression algorithm, and sequentially encapsulate the traversed compression levels as second field information into a response message and send it to the client; receiving in sequence the second interface access requests sent by the client based on the compression level carried in each response message, and determining the minimum second average access duration corresponding to the preset compression algorithm based on each received second interface access request, wherein different second interface access requests carry second average access durations corresponding to different compression levels; Determine whether the minimum second average access time corresponding to the preset compression algorithm is less than a first preset threshold; When it is determined that the minimum second average access time corresponding to the preset compression algorithm is less than the first preset threshold, the compression level of the minimum second average access time corresponding to the preset compression algorithm is determined as the optimal compression level.
3. The method according to claim 2, characterized in that The determining, based on each received second interface access request, a minimum second average access duration corresponding to the preset compression algorithm includes: Compare the second average access duration in the currently received second interface access request with the second average access duration in the last received second interface access request; When the second average access duration in the currently received second interface access request is greater than the second average access duration in the last received second interface access request, the second average access duration in the last received second interface access request is determined as the minimum second average access duration corresponding to the preset compression algorithm; When the second average access time in the currently received second interface access request is less than or equal to the second average access time in the last received second interface access request, continue to traverse the next compression level in the preset compression algorithm, and compare the second average access time in the next received second interface access request with the second average access time in the currently received second interface access request, and repeat the process until the traversal is stopped when a first preset condition is met, wherein the first preset condition is that all compression levels in the preset compression algorithm have been traversed, or the minimum second average access time corresponding to the preset compression algorithm is detected.
4. The method according to claim 1, characterized in that: The number of the preset compression algorithms is multiple, and the multiple compression levels in the preset compression algorithms are dynamically adjusted to obtain the optimal compression level, including: When the minimum second average access time corresponding to the first compression algorithm is greater than or equal to the first preset threshold, traverse the multiple compression levels in the second compression algorithm in sequence, and encapsulate the traversed compression levels in the second compression algorithm in sequence as second field information into a response message and send it to the client; receiving in sequence the second interface access requests sent by the client based on the compression level carried in each response message, and determining the minimum second average access time corresponding to the second compression algorithm based on each received second interface access request, wherein different second interface access requests carry second average access times corresponding to different compression levels; Determine whether the minimum second average access time corresponding to the second compression algorithm is less than the first preset threshold; In the case where it is determined that the minimum second average access time corresponding to the second compression algorithm is less than the first preset threshold, determining the compression level of the minimum second average access time corresponding to the second compression algorithm as the optimal compression level; When it is determined that the minimum second average access time corresponding to the second compression algorithm is greater than or equal to the first preset threshold, continue to traverse the multiple compression levels in the third compression algorithm in sequence, and loop in sequence until the traversal is stopped when the second preset condition is met, wherein the second preset condition is that all compression levels of the multiple compression algorithms in the preset compression algorithm have been traversed, or it is detected that the minimum second average access time corresponding to any compression algorithm is less than the first preset threshold, and the first compression algorithm, the second compression algorithm and the third compression algorithm belong to the preset compression algorithm.
5. The method according to claim 1, characterized in that The determining whether a triggering condition for data compression is currently met based on the first average access time and the total amount of transmitted data includes: Determine whether the total amount of transmitted data is greater than a second preset threshold, and whether the first average access time is greater than a third preset threshold; When it is determined that the total amount of transmitted data is greater than the second preset threshold and the first average access time is greater than the third preset threshold, determining that a trigger condition for data compression is currently met; When it is determined that the total amount of transmitted data is less than or equal to the second preset threshold, and / or the first average access time is less than or equal to the third preset threshold, it is determined that the trigger condition for data compression is not currently met.
6. The method according to claim 1, characterized in that After compressing the transmission data between the client and the client using the optimal compression level, the method further includes: Acquire the duration of data compression in real time, wherein the duration of data compression refers to the duration between the current time point and the time point at which the trigger condition for data compression is determined to be satisfied; When the duration of the data compression reaches a fourth preset threshold, setting the second field information in the response message to empty, and sending the set response message to the client; The transmission data between the client and the client is transmitted in an original data transmission mode, wherein the original data transmission mode refers to a data transmission mode that does not use any compression algorithm to compress the transmission data.
7. A data compression method, characterized in that: Applied to a client, the method comprises: Sending a first interface access request to the server, wherein the first interface access request carries first field information and first transmission data, the first field information is used to represent a first average access time required for the client to access the interface when no compression algorithm is used for data compression, and the first transmission data refers to data that the client needs to transmit to the server; Receive a response message returned by the server in response to the first interface access request, wherein the second field information of the response message is an optimal compression level, and the optimal compression level is obtained by the server dynamically adjusting multiple compression levels in a preset compression algorithm when determining that a trigger condition for data compression is currently met, and the trigger condition for data compression is determined by the server based on the first average access time and the total amount of transmitted data, and the total amount of transmitted data is the sum of first transmitted data transmitted by the client to the server and second transmitted data to be returned by the server to the client; The optimal compression level is used to compress the data transmitted between the server.
8. The method according to claim 7, characterized in that After compressing the transmission data between the server and the server using the optimal compression level, the method further includes: When the duration of data compression reaches a fourth preset threshold, receiving a set response message returned by the server, wherein the second field information in the set response message is empty; The transmission data between the server and the server is transmitted in an original data transmission mode, wherein the original data transmission mode refers to a data transmission mode that does not use any compression algorithm to compress the transmission data.
9. An electronic device, characterized in that: It includes a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other through the communication bus; Memory, used to store computer programs; A processor, for implementing the data compression method described in any one of claims 1 to 6, or implementing the data compression method described in any one of claims 7 to 8, when executing a program stored in a memory.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, it implements the data compression method described in any one of claims 1 to 6, or implements the data compression method described in any one of claims 7 to 8.
Citation Information
Patent Citations
System and method for dynamically selecting a level of compression for data to be transmitted
US20050188112A1
Dynamic data delivery
US20060195464A1
Method and system for web-based medical image processing
US20220392615A1
Data transmission device, data transmission method, and program
WO2014155490A1
Cited By
Data transmission method, system, device, equipment, medium and product
CN121151313A
