Disclosure of Invention
In view of the above, the present disclosure provides a message rewriting method for a load balancing apparatus, an electronic device, and a computer readable medium, which can flexibly implement message rewriting under the condition that a message is compressed, and improve rewriting efficiency.
Additional features and advantages of the disclosure will be set forth in the detailed description which follows, or in part will be obvious from the description, or may be learned by practice of the disclosure.
According to an aspect of the present disclosure, a method for rewriting a packet in a load balancing device is provided, where the method includes: acquiring a request message from a client; extracting a target URL address from the request message; when the rewriting configuration is not changed, matching in a cache according to the target URL address; when a valid result is matched, generating response information through the data corresponding to the target URL address in the cache; and sending the response information to the client.
In an exemplary embodiment of the present disclosure, further comprising: before obtaining the request message from the client, the method further comprises: acquiring the configuration authority of at least one server corresponding to the load balancing device; modifying the overriding configuration of the at least one server based on the configuration rights.
In an exemplary embodiment of the present disclosure, modifying the overriding configuration of the at least one server based on the configuration authority includes: and modifying the header field of the at least one server based on the configuration authority so that the response message of the at least one server is in clear text.
In an exemplary embodiment of the present disclosure, the preset condition is satisfied, including: there is a change in the overwrite configuration or no match to a valid result in the cache.
In an exemplary embodiment of the present disclosure, performing packet rewriting on the response packet to generate response information includes: the load balancing device receives and analyzes the response message; extracting a character string to be rewritten from the response message; and replacing the character string to be rewritten according to preset information to generate the response information.
In an exemplary embodiment of the present disclosure, further comprising: and storing the target URL address and the corresponding response information in a cache of a load balancing device.
In an exemplary embodiment of the present disclosure, further comprising: detecting the change condition of the rewriting configuration at fixed time, and searching in a cache according to the target URL address when the rewriting configuration is changed; and deleting cache data corresponding to the target URL address in the cache and updating the re-configured matching item.
In an exemplary embodiment of the present disclosure, when the preset condition is not satisfied, the method further includes: when the rewriting configuration is not changed, matching in a cache according to the target URL address; when a valid result is matched, generating response information through the data corresponding to the target URL address in the cache; and sending the response information to the client.
In an exemplary embodiment of the present disclosure, when the rewrite configuration is not changed, matching in a cache according to the target URL address includes: judging whether the rewriting configuration is changed; when the rewriting configuration is not changed, retrieving in a cache according to the target URL address; and when the cache data corresponding to the target address exists, determining that a valid result is matched.
In an exemplary embodiment of the present disclosure, further comprising: and when the effective result is not matched, sending the request message to a server corresponding to the target URL address to acquire response information.
According to an aspect of the present disclosure, a message module is provided for a load balancing apparatus, and is configured to obtain a request message from a client; the address module is used for extracting a target URL address from the request message; the sending module is used for sending the request message to a server corresponding to the target URL address when a preset condition is met so that the server replies a response message through a plaintext; and the response module is used for rewriting the response message to generate response information.
In an exemplary embodiment of the present disclosure, further comprising: the configuration module is used for acquiring the configuration authority of at least one server corresponding to the load balancing device; modifying the overriding configuration of the at least one server based on the configuration rights.
According to an aspect of the present disclosure, an electronic device is provided, the electronic device including: one or more processors; storage means for storing one or more programs; when executed by one or more processors, cause the one or more processors to implement a method as above.
According to an aspect of the disclosure, a computer-readable medium is proposed, on which a computer program is stored, which program, when being executed by a processor, carries out the method as above.
According to the message rewriting method for the load balancing device, the electronic equipment and the computer readable medium, the request message from the client is obtained; extracting a target URL address from the request message; when a preset condition is met, the request message is sent to a server corresponding to the target URL address, so that the server replies a response message through a plaintext; the mode of generating the response information by rewriting the message to the response message can flexibly realize message rewriting under the condition that the message is compressed and improve the rewriting efficiency.
It is to be understood that both the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the disclosure.
The specific implementation scheme is as follows:
1. configuring a corresponding HTTP rewriting method according to actual requirements, such as: modifying a specified HTTP header field value, newly adding a field or deleting a HTTP header field, searching a certain character string in the message and replacing the character string with a new character string, and the like;
2. analyzing the HTTP message, acquiring basic information and each header field of the HTTP message, and recording information such as the position of a character string to be changed;
3. and modifying the message according to the position information of the character string, the HTTP header field information and the HTTP rewriting configuration required to complete rewriting.
In the process of HTTP transmission, the data volume transmitted by the network can be reduced by using HTTP compression, and the access speed of the client browser is improved. Under the situation of HTTP compression, the position information of the character strings which need to be modified and replaced in HTTP rewriting configuration cannot be directly acquired, and the position information can be acquired only after corresponding decompression according to the compression format specified by Accept-Encoding. The HTTP compression originally improves the access experience of the client under the condition of sacrificing certain performance. When the transmission data is small, the performance is sacrificed without the difference in the customer experience.
When the load balancing device faces millions of clients, the same message needs to be rewritten once every time the client requests one time. This wastes the opportunity for the load balancing apparatus to provide more functionality.
Aiming at the defects of the prior art, the message rewriting method for the load balancing device disclosed by the invention solves the problems of repeated rewriting for many times and inconvenience in rewriting under the situation of compression. The message rewriting method for the load balancing device can flexibly realize rewriting even under the condition of message compression, and improve the rewriting efficiency. The present disclosure is described in detail below with reference to specific examples.
Fig. 2 is a schematic diagram illustrating an application scenario of a packet rewriting method for a load balancing apparatus according to an exemplary embodiment.
As shown in fig. 2, thesystem architecture 20 may includeterminal devices 201, 202, 203, anetwork 204 and load balancing means 205,servers 206, 207, 208. Thenetwork 204 is a medium to provide communication links between theterminal devices 201, 202, 203 and theload balancing apparatus 205; thenetwork 204 also serves to provide a medium for communication links between theservers 206, 207, 208 and theload balancing apparatus 205.Network 204 may include various connection types, such as wired, wireless communication links, or fiber optic cables, to name a few.
The user may use theterminal device 201, 202, 203 to interact with theserver 206, 207, 208, via thenetwork 204, the load balancing means 205, to receive or send messages, etc. Theterminal devices 201, 202, 203 may have various communication client applications installed thereon, such as shopping applications, web browser applications, search applications, instant messaging tools, mailbox clients, social platform software, and the like.
Theterminal devices 201, 202, 203 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop portable computers, desktop computers, and the like.
Theservers 206, 207, 208 may be servers providing various services, such as a background management server providing support for websites browsed by users using theterminal devices 201, 202, 203. The background management server can analyze and process the received request and feed back the processing result to the terminal equipment.
Theload balancing apparatus 205 may, for example, obtain a request message from the client 101 (or the client 102, the client 103); theload balancing device 205 may extract the target URL address, for example, from the request message; theload balancing apparatus 205 may, for example, send the request message to the server 206 (or theserver 207, the server 208) corresponding to the target URL address when a preset condition is met, so that the server replies a response message through plaintext; theload balancing apparatus 205 may, for example, rewrite the response packet to generate response information.
In one embodiment, the target URL address and the response information corresponding thereto may also be stored in a cache of a load balancing apparatus, for example.
Theload balancing apparatus 205 may also, for example, perform matching in the cache according to the target URL address when the rewrite configuration is not changed; when a valid result is matched, generating response information through the data corresponding to the target URL address in the cache; and sending the response information to the client.
Theload balancing apparatus 205 may also detect a change in the rewriting configuration at regular time, and when there is a change in the rewriting configuration, retrieve the target URL address from the cache; and deleting cache data corresponding to the target URL address in the cache and updating the re-configured matching item.
It should be noted that the message rewriting method for the load balancing apparatus provided in the embodiment of the present disclosure may be executed by theload balancing apparatus 205.
Fig. 3 is a flowchart illustrating a message rewriting method for a load balancing apparatus according to an exemplary embodiment. Themessage rewriting method 30 for a load balancing apparatus includes at least steps S302 to S308.
As shown in fig. 3, in S302, a request message from a client is obtained. The request message may be any required message, and may be, for example, a login request, an order processing request, a data access request, and the like, which is not limited in this disclosure.
Before obtaining the request message from the client, the method further comprises: acquiring the configuration authority of at least one server corresponding to the load balancing device; modifying the overriding configuration of the at least one server based on the configuration rights.
In one embodiment, modifying the overriding configuration of the at least one server based on the configuration rights comprises: and modifying the header field of the at least one server based on the configuration authority so that the response message of the at least one server is in clear text. Furthermore, an administrator can configure message rewriting items according to needs, and the method disclosed by the disclosure can be adopted in all scenes needing message rewriting. Preferably, in the context of message compression, the header-Encoding may be modified, so that the server responds to the message in a plaintext manner; after configuration, response messages of the server side are all in an HTTP plaintext state, and the position of the character string needing to be replaced is found according to rewriting configuration;
in S304, the target URL address is extracted from the request message.
In S306, when a preset condition is satisfied, the request message is sent to the server corresponding to the target URL address, so that the server replies a response message through plaintext. Wherein, satisfy preset condition, include: there is a change in the overwrite configuration or no match to a valid result in the cache. In the rewriting configuration, after the modification header field Accept-Encoding is added, the server responds to the configuration switch replied by the message in a plaintext mode, and the subsequent HTTP response message of the configured server is started to be in a plaintext state, namely the position information of the replacement character string needing to be modified can be conveniently acquired.
In S308, the response message is rewritten to generate response information. The method comprises the following steps: the load balancing device receives and analyzes the response message; extracting a character string to be rewritten from the response message; and replacing the character string to be rewritten according to preset information to generate the response information.
In one embodiment, the message rewriting method may further include: modifying a specified certain HTTP header field value, adding a certain field or deleting a certain HTTP header field, searching a certain character string in the message and replacing the character string with a new character string, and the like.
According to the message rewriting method for the load balancing device, a request message from a client is obtained; extracting a target URL address from the request message; when a preset condition is met, the request message is sent to a server corresponding to the target URL address, so that the server replies a response message through a plaintext; the mode of generating the response information by rewriting the message to the response message can flexibly realize message rewriting under the condition that the message is compressed and improve the rewriting efficiency.
It should be clearly understood that this disclosure describes how to make and use particular examples, but the principles of this disclosure are not limited to any details of these examples. Rather, these principles can be applied to many other embodiments based on the teachings of the present disclosure.
Fig. 4 is a flowchart illustrating a message rewriting method for a load balancing apparatus according to another exemplary embodiment. Theflow 40 shown in fig. 4 is a supplementary description of the flow shown in fig. 2.
As shown in fig. 4, in S402, the target URL address and the response information corresponding to the target URL address are stored in a cache of the load balancing apparatus. And when the response message is rewritten, recording the rewritten message. And marking the rewritten message according to the target URL of the request of the client. When a client initiates a request and requests the target UR of the same request, the rewritten message can be matched from the cache and directly replied to the client, namely, the same response message does not need to be rewritten every time.
In S404, when the rewrite configuration is not changed, matching is performed in the cache according to the target URL address. More specifically, the method can comprise the following steps: judging whether the rewriting configuration is changed; when the rewriting configuration is not changed, retrieving in a cache according to the target URL address; and when the cache data corresponding to the target address exists, determining that a valid result is matched.
In one embodiment, the rewriting configuration change condition can be detected at regular time, and when the rewriting configuration has change, the target URL address is searched in the cache; and deleting cache data corresponding to the target URL address in the cache and updating the re-configured matching item. When the rewriting effect of the response message changes, the cached message with the previous rewriting effect is judged and updated correspondingly. The rewriting effect required by the client is ensured to be the cached rewriting message, and the cached rewriting message is ensured to have real-time performance. When caching a rewrite packet, it is not possible to record only the requested target URL, and the rewritten configuration also needs to be recorded. When the request is received again, if only one matching condition of the target URL exists, when the rewriting configuration is changed, the replied cache response message does not contain the rewriting effect required by the client. Therefore, after the first rewrite succeeds, both the target URL and the rewrite configuration are recorded as matching conditions for the second access.
In S406, when a valid result is matched, response information is generated according to the data corresponding to the target URL address in the cache. Further comprising: and when the effective result is not matched, sending the request message to a server corresponding to the target URL address to acquire response information.
When the load balancing device receives the same target URL request of the client again, whether the configured matching item is changed or not is checked, and if the configured matching item is not changed, the cached message contains the rewriting effect required by the client, and the cached message is directly replied to the client; and the rewriting configuration is changed, the message cached by the target URL is deleted, the response message is rewritten according to the new rewriting configuration, the rewriting message is cached, and the matching item of the rewriting configuration is updated. Therefore, the target URL and the rewriting configuration are used as matching conditions of the cache message, and the latest cached rewriting message is ensured.
In S408, the response information is sent to the client.
Fig. 5 is a flowchart illustrating a message rewriting method for a load balancing apparatus according to another exemplary embodiment. Theflow 50 shown in fig. 5 is a detailed description of the overall process of the present disclosure.
As shown in fig. 5, in S502, HTTP rewriting content is configured.
In S504, the header field Accept-Encoding is modified, so that the server response packet is replied in a plaintext manner.
In S506, the received response message is retrieved. And the response messages of the server are all in an HTTP plaintext state, and the positions of the character strings needing to be replaced are found according to the rewriting configuration.
In S508, the rewrite character string position is extracted. And modifying the message by using the new character string according to the position information and the rewriting configuration obtained by retrieving the message.
In S510, after completing the rewriting, the rewritten packet is cached. After the rewriting is completed, the rewriting message is cached, and the cached content comprises a request URL and rewriting configuration.
In S512, the cached rewrite packet is matched according to the URL requested by the client.
In S514, the matched rewrite packet is replied to the request of the client. When the load balancing device receives the request of the client to the same URL again, the rewritten message is directly replied to the client after matching is successful according to the URL and the rewritten configuration as matching conditions.
According to the method disclosed by the disclosure, the HTTP response message can be flexibly rewritten in the context of message compression. And the rewritten message is cached, and when the load balancing device detects that a certain client requests the same URL, the cached rewritten message can be directly replied to the client.
Those skilled in the art will appreciate that all or part of the steps implementing the above embodiments are implemented as computer programs executed by a CPU. When executed by the CPU, performs the functions defined by the above-described methods provided by the present disclosure. The program may be stored in a computer readable storage medium, which may be a read-only memory, a magnetic or optical disk, or the like.
Furthermore, it should be noted that the above-mentioned figures are only schematic illustrations of the processes involved in the methods according to exemplary embodiments of the present disclosure, and are not intended to be limiting. It will be readily understood that the processes shown in the above figures are not intended to indicate or limit the chronological order of the processes. In addition, it is also readily understood that these processes may be performed synchronously or asynchronously, e.g., in multiple modules.
The following are embodiments of the disclosed apparatus that may be used to perform embodiments of the disclosed methods. For details not disclosed in the embodiments of the apparatus of the present disclosure, refer to the embodiments of the method of the present disclosure.
Fig. 6 is a block diagram illustrating a packet rewriting device for a load balancing device according to another exemplary embodiment. As shown in fig. 6, thepacket rewriting apparatus 60 for a load balancing apparatus includes: amessage module 602, anextraction module 604, a sendingmodule 606, aresponse module 608, and aconfiguration module 610.
Themessage module 602 is configured to obtain a request message from a client; the request message may be any desired message, and may be, for example, a login request, an order processing request, a request for accessing data, and the like.
Theaddress module 604 is configured to extract a target URL address from the request message;
the sendingmodule 606 is configured to send the request message to a server corresponding to the target URL address when a preset condition is met, so that the server replies a response message through a plaintext; wherein, satisfy preset condition, include: there is a change in the overwrite configuration or no match to a valid result in the cache.
Theresponse module 608 is configured to perform message rewriting on the response message to generate response information. The method comprises the following steps: the load balancing device receives and analyzes the response message; extracting a character string to be rewritten from the response message; and replacing the character string to be rewritten according to preset information to generate the response information.
Theconfiguration module 610 is configured to obtain a configuration right of at least one server corresponding to the load balancing apparatus; modifying the overriding configuration of the at least one server based on the configuration rights.
According to the message rewriting device for the load balancing device, the request message from the client is obtained; extracting a target URL address from the request message; when a preset condition is met, the request message is sent to a server corresponding to the target URL address, so that the server replies a response message through a plaintext; the mode of generating the response information by rewriting the message to the response message can flexibly realize message rewriting under the condition that the message is compressed and improve the rewriting efficiency.
FIG. 7 is a block diagram illustrating an electronic device in accordance with an example embodiment.
Anelectronic device 700 according to this embodiment of the disclosure is described below with reference to fig. 7. Theelectronic device 700 shown in fig. 7 is only an example and should not bring any limitation to the functions and the scope of use of the embodiments of the present disclosure.
As shown in fig. 7,electronic device 700 is embodied in the form of a general purpose computing device. The components of theelectronic device 700 may include, but are not limited to: at least oneprocessing unit 710, at least onememory unit 720, abus 730 that connects the various system components (including thememory unit 720 and the processing unit 710), adisplay unit 740, and the like.
Wherein the storage unit stores program codes executable by theprocessing unit 710 to cause theprocessing unit 710 to perform the steps according to various exemplary embodiments of the present disclosure described in the above-mentioned electronic prescription flow processing method section of the present specification. For example, theprocessing unit 710 may perform the steps as shown in fig. 3, 4, 5.
Thememory unit 720 may include readable media in the form of volatile memory units, such as a random access memory unit (RAM)7201 and/or acache memory unit 7202, and may further include a read only memory unit (ROM) 7203.
Thememory unit 720 may also include a program/utility 7204 having a set (at least one) ofprogram modules 7205,such program modules 7205 including, but not limited to: an operating system, one or more application programs, other program modules, and program data, each of which, or some combination thereof, may comprise an implementation of a network environment.
Bus 730 may be any representation of one or more of several types of bus structures, including a memory unit bus or memory unit controller, a peripheral bus, an accelerated graphics port, a processing unit, or a local bus using any of a variety of bus architectures.
Theelectronic device 700 may also communicate with one or more external devices 700' (e.g., keyboard, pointing device, bluetooth device, etc.), with one or more devices that enable a user to interact with theelectronic device 700, and/or with any devices (e.g., router, modem, etc.) that enable theelectronic device 700 to communicate with one or more other computing devices. Such communication may occur via an input/output (I/O)interface 750. Also, theelectronic device 700 may communicate with one or more networks (e.g., a Local Area Network (LAN), a Wide Area Network (WAN), and/or a public network such as the internet) via thenetwork adapter 760. Thenetwork adapter 760 may communicate with other modules of theelectronic device 700 via thebus 730. It should be appreciated that although not shown in the figures, other hardware and/or software modules may be used in conjunction with theelectronic device 700, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems, among others.
Through the above description of the embodiments, those skilled in the art will readily understand that the exemplary embodiments described herein may be implemented by software, or by software in combination with necessary hardware. Therefore, as shown in fig. 8, the technical solution according to the embodiment of the present disclosure may be embodied in the form of a software product, which may be stored in a non-volatile storage medium (which may be a CD-ROM, a usb disk, a removable hard disk, etc.) or on a network, and includes several instructions to enable a computing device (which may be a personal computer, a server, or a network device, etc.) to execute the above method according to the embodiment of the present disclosure.
The software product may employ any combination of one or more readable media. The readable medium may be a readable signal medium or a readable storage medium. A readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples (a non-exhaustive list) of the readable storage medium include: an electrical connection having one or more wires, a portable disk, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
The computer readable storage medium may include a propagated data signal with readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A readable storage medium may also be any readable medium that is not a readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a readable storage medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.
Program code for carrying out operations for the present disclosure may be written in any combination of one or more programming languages, including an object oriented programming language such as Java, C + + or the like and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code may execute entirely on the user's computing device, partly on the user's device, as a stand-alone software package, partly on the user's computing device and partly on a remote computing device, or entirely on the remote computing device or server. In the case of a remote computing device, the remote computing device may be connected to the user computing device through any kind of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or may be connected to an external computing device (e.g., through the internet using an internet service provider).
The computer readable medium carries one or more programs which, when executed by a device, cause the computer readable medium to perform the functions of: acquiring a request message from a client; extracting a target URL address from the request message; when a preset condition is met, the request message is sent to a server corresponding to the target URL address, so that the server replies a response message through a plaintext; and rewriting the response message to generate response information.
Those skilled in the art will appreciate that the modules described above may be distributed in the apparatus according to the description of the embodiments, or may be modified accordingly in one or more apparatuses unique from the embodiments. The modules of the above embodiments may be combined into one module, or further split into multiple sub-modules.
Through the above description of the embodiments, those skilled in the art will readily understand that the exemplary embodiments described herein may be implemented by software, or by software in combination with necessary hardware. Therefore, the technical solution according to the embodiments of the present disclosure may be embodied in the form of a software product, which may be stored in a non-volatile storage medium (which may be a CD-ROM, a usb disk, a removable hard disk, etc.) or on a network, and includes several instructions to enable a computing device (which may be a personal computer, a server, a mobile terminal, or a network device, etc.) to execute the method according to the embodiments of the present disclosure.
Exemplary embodiments of the present disclosure are specifically illustrated and described above. It is to be understood that the present disclosure is not limited to the precise arrangements, instrumentalities, or instrumentalities described herein; on the contrary, the disclosure is intended to cover various modifications and equivalent arrangements included within the spirit and scope of the appended claims.