Business request processing method, device and computer equipment
Patent Information
- Application Number
- CN202211593334.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-13
- Publication Date
- 2026-09-22
- Estimated Expiration
- 2042-12-13
AI Technical Summary
由于负载均衡的方式较为单一,影响在复杂业务场景下的负载均衡能力
[0050]上述业务请求处理方法、装置、计算机设备、存储介质和计算机程序产品,通过调用解析脚本对业务请求信息的请求体进行解析,得到代码层面的请求的业务码和业务层面的业务类型,根据业务类型的业务流量状态、业务类型以及业务类型和服务器之间的映射关系表,可以直接得到业务码的目标服务器。该方法不同于传统的均匀负载均衡的方式,而是为不同的业务类型设置对应的服务器,同时考虑了业务类型的业务流量状态,一方面,无需为每个用户的业务请求额外增加转发配置,通过业务类型和服务器的映射关系表完成业务码的转发,转发过程简便高效,另一方面,在进行分发时还考虑了不同业务类型的业务流量状态,能够应用多种突发情况,提高负载均衡能力。
Smart Images

Figure CN116016677B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to a business request processing method, apparatus, computer equipment, storage medium, and computer program product. Background Technology
[0002] With the popularization of the internet, the number of internet users in my country is constantly increasing, and various applications related to daily life have been developed to provide services to people, such as shopping applications and video applications. When a user uses an application and clicks a button or menu, at least one request is sent to the server, which then processes the user's request information. To improve the server's processing speed for user requests, load balancing methods have emerged, prioritizing server resources.
[0003] Existing load balancing technologies can only simply distribute requests evenly across different servers for processing. This limited approach hinders their ability to handle complex business scenarios. Summary of the Invention
[0004] Therefore, it is necessary to provide a business request processing method, apparatus, computer equipment, computer-readable storage medium, and computer program product that can improve the load balancing effect in response to the above-mentioned technical problems.
[0005] Firstly, this application provides a business request processing method, the method comprising:
[0006] Receive business request information from the client;
[0007] The parsing script is invoked to parse the request body in the business request information to obtain the request's business code and the business type corresponding to the business code;
[0008] Based on the service traffic status of the service type and the mapping relationship table between the service type and the server, determine the target server for processing the service code;
[0009] The service code is forwarded to the target server.
[0010] In one embodiment, determining the target server for processing the service code based on the service traffic status of the service type and a mapping table between service types and servers includes:
[0011] If the service type is in a normal service traffic state, then obtain the mapping relationship table between the service type and the server;
[0012] Based on the business type, the target server for processing the business code is determined by searching the mapping table between the business type and the server.
[0013] In one embodiment, determining the target server for processing the service code based on the service traffic status of the service type and a mapping table between service types and servers includes:
[0014] If the service type is experiencing a surge in traffic, the designated forwarding server corresponding to the service type is obtained according to the mapping table between the service type and the server.
[0015] The target server for processing the service code is determined based on the load status of the specified forwarding server.
[0016] In one embodiment, determining the target server for processing the service code based on the load status of the designated forwarding server includes: if the load of the designated forwarding server is not saturated, then the designated forwarding server with the unsaturated load is used as the target server for processing the service code.
[0017] If the designated forwarding server is overloaded, the backup designated server will be expanded to be the backup designated server for the service type, and the backup designated server will be used as the target server for processing the service code.
[0018] In one embodiment, the method further includes: if the absolute value of the difference between the number of service requests of the service type in the current period and the preset number of service requests is greater than a first threshold, and the absolute value of the difference between the number of service requests of the service type in two adjacent periods is greater than a second threshold, then the service type is determined to be in a state of surge in service traffic.
[0019] In one embodiment, the method further includes:
[0020] If the business type is experiencing a surge in business traffic, then obtain the associated business type.
[0021] Specify a forwarding server for the associated service type.
[0022] In one embodiment, the method further includes:
[0023] Update the mapping table between the service type and the server according to the designated forwarding server for the expanded service type.
[0024] Secondly, this application provides a service request processing apparatus, the apparatus comprising:
[0025] The receiving module is used to receive business request information from the client;
[0026] The parsing module is used to call the parsing script to parse the request body in the business request information to obtain the request business code and the business type corresponding to the business code;
[0027] The processing module is used to determine the target server for processing the service code based on the service traffic status of the service type and the mapping relationship table between the service type and the server.
[0028] The forwarding module is used to forward the service code to the target server.
[0029] In one embodiment, the processing module is further configured to, if the service type is in a normal service traffic state, obtain a mapping table between the service type and the server; and, based on the service type, search the mapping table between the service type and the server to determine the target server for processing the service code.
[0030] In one embodiment, the processing module is further configured to, if the service type is in a state of surge in service traffic, obtain the designated forwarding server corresponding to the service type according to the mapping relationship table between the service type and the server; and determine the target server for processing the service code according to the load status of the designated forwarding server.
[0031] In one embodiment, the processing module is further configured to: if the load of the designated forwarding server is not saturated, use the designated forwarding server with the unsaturated load as the target server for processing the service code; if the load of the designated forwarding server is saturated, expand the backup designated server to be the designated forwarding server for the service type; and use the backup designated server as the target server for the service type.
[0032] In one embodiment, the processing module is further configured to determine that the service type is in a state of surge in business traffic if the absolute value of the difference between the number of business requests of the service type in the current period and the preset number of business requests is greater than a first threshold, and the absolute value of the difference between the number of business requests of the service type in two adjacent periods is greater than a second threshold.
[0033] In one embodiment, the processing module is further configured to, if the service type is in a state of surge in service traffic, obtain the associated service type of the service type; and expand the designated forwarding server for the associated service type.
[0034] In one embodiment, the processing module is further configured to update the mapping table between the service type and the server according to the designated forwarding server of the expanded service type.
[0035] Thirdly, this application provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the following method steps:
[0036] Receive business request information from the client;
[0037] The parsing script is invoked to parse the request body in the business request information of the transaction, and the business code of the request and the business type corresponding to the business code are obtained.
[0038] Based on the service traffic status of the service type and the mapping relationship table between the service type and the server, determine the target server for processing the service code;
[0039] The service code is forwarded to the target server.
[0040] Fourthly, this application provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the following method steps:
[0041] Receive business request information from the client;
[0042] The parsing script is invoked to parse the request body in the business request information of the transaction, and the business code of the request and the business type corresponding to the business code are obtained.
[0043] Based on the service traffic status of the service type and the mapping relationship table between the service type and the server, determine the target server for processing the service code;
[0044] The service code is forwarded to the target server.
[0045] Fifthly, this application provides a computer program product, including a computer program that, when executed by a processor, implements the following method steps:
[0046] Receive business request information from the client;
[0047] The parsing script is invoked to parse the request body in the business request information of the transaction, and the business code of the request and the business type corresponding to the business code are obtained.
[0048] Based on the service traffic status of the service type and the mapping relationship table between the service type and the server, determine the target server for processing the service code;
[0049] The service code is forwarded to the target server.
[0050] The aforementioned business request processing method, apparatus, computer equipment, storage medium, and computer program product parse the request body of the business request information by calling a parsing script to obtain the business code at the code level and the business type at the business level. Based on the business traffic status of the business type, the business type itself, and the mapping table between the business type and the server, the target server for the business code can be directly obtained. This method differs from traditional uniform load balancing; instead, it sets up corresponding servers for different business types and considers the business traffic status of each business type. On the one hand, it eliminates the need for additional forwarding configurations for each user's business request, as the forwarding of the business code is completed through the mapping table between the business type and the server, making the forwarding process simple and efficient. On the other hand, it considers the business traffic status of different business types during distribution, enabling it to handle various contingency situations and improve load balancing capabilities. Attached Figure Description
[0051] Figure 1 This is an application environment diagram of a business request processing method in one embodiment;
[0052] Figure 2 This is a flowchart illustrating a business request processing method in one embodiment;
[0053] Figure 3 This is a flowchart illustrating a method for determining the server corresponding to a service code in one embodiment.
[0054] Figure 4 This is one embodiment of a method for determining the processing of service codes;
[0055] Figure 5 This is a flowchart illustrating a method for specifying a target server in one embodiment;
[0056] Figure 6 This is a schematic diagram of the service request information cycle in one embodiment;
[0057] Figure 7 This is a schematic diagram of the mapping relationship table between service types and servers in one embodiment;
[0058] Figure 8 This is a flowchart illustrating a transaction-based dynamic load balancing method using Nginx in one embodiment.
[0059] Figure 9 This is a structural block diagram of a service request processing device in one embodiment;
[0060] Figure 10 This is an internal structural diagram of a computer device in one embodiment. Detailed Implementation
[0061] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.
[0062] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, data stored, data displayed, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties.
[0063] According to the 49th Statistical Report on Internet Development in China, as of December 2021, my country's internet user population reached 1.032 billion, an increase of 42.96 million from December 2020, with an internet penetration rate of 73.0%. Behind this massive user base lies immense pressure on various websites and apps. Typically, when a user clicks a button or menu item, at least one request is sent to the server, with each request taking approximately 50-200ms. For a server with 8 cores and 32GB of memory deploying Java applications, approximately 100 threads can be running simultaneously to process transactions. Theoretically, a single server can handle a peak of 2000 transactions per second. Given the sheer number of internet users, a single server cannot handle the load. Therefore, a virtual private server address (VIP) is typically used to virtualize multiple cloud server resources into a high-performance, highly available application service pool, increasing throughput and transaction processing capacity. Typical web servers include Nginx, Apache, and Lighttpd. Among them, Nginx's weighted round-robin load balancing is currently the mainstream solution. It can distribute all requests sent by clients in a round-robin manner according to the weights set for each server, reducing the pressure on each server and improving the availability of the system.
[0064] Nginx (engine x) is a high-performance HTTP and reverse proxy web server. The Nginx layer includes: handlers, filters, and proxies, which are used to interact with backend services such as FastCGI to implement service proxy and load balancing functions.
[0065] Nginx is a widely used mainstream web server. Its load balancing schemes can improve server bandwidth, increase throughput, enhance transaction processing capabilities, and improve network flexibility and availability. By default, it supports the following five load balancing schemes: Round Robin, Weighted Round Robin, IP Hash, Least Connections, and URL Hash.
[0066] Traditional load balancing methods simply distribute request information evenly across different servers without distinguishing the requests themselves. After parsing the request messages, forwarding configurations are added to the request messages to complete the forwarding. As the number of business types increases and the business volume surges, the forwarding configurations become cumbersome and inconvenient to maintain.
[0067] In view of this, the business request processing method provided in the embodiments of this application can be applied to, for example, Figure 1 In the application environment shown, client 102 communicates with proxy server 104 via a network. Proxy server 104 communicates with target server 106. A data storage system can store the data that proxy server 104 needs to process. The data storage system can be integrated on proxy server 104 or placed on the cloud or other network servers. Proxy server 104 receives business request information from client 102; proxy server 104 calls a parsing script to parse the request body in the business request information to obtain the requested business code and the corresponding business type; proxy server 104 determines the target server for processing the business code based on the business traffic status of the business type, the business type, and the mapping relationship table between the business type and the server; proxy server 104 forwards the business code to target server 106.
[0068] The client 102 can be, but is not limited to, various personal computers, laptops, smartphones, tablets, IoT devices, and portable wearable devices. IoT devices can include smart speakers, smart TVs, smart air conditioners, and smart in-vehicle systems. Portable wearable devices can include smartwatches, smart bracelets, and head-mounted devices. The proxy server 104 can be implemented using a standalone server or a server cluster consisting of multiple servers. The target server 106 can be implemented using a standalone server or a server cluster consisting of multiple servers capable of handling different types of business.
[0069] In one embodiment, such as Figure 2 As shown, a business request processing method is provided, which is applied to... Figure 1 Taking a proxy server as an example, the following steps are included:
[0070] S202, Receives business request information from the client.
[0071] The business request information can be a request message generated on the client when the user performs a certain operation on the client. The business request information can include the business code and the business type.
[0072] Among them, the business code is the identifier of the user's business request information at the code level, and the business type is the type of the user's business request information at the business level. As can be understood, the business code at the code level is code that the proxy server can directly process, such as parsing, identifying, or forwarding. The business type at the business level is the specific type of client operation obtained by the proxy server from the business request information, such as placing an order, requesting user benefits, or requesting user membership information.
[0073] Specifically, business request information can be the specific request message generated when a user performs a transaction operation on the client side. Taking a transaction request as an example, the transaction request message includes the transaction code and the transaction type.
[0074] The transaction code contained in the transaction request message can be a code-level transaction code such as a registration code, login code, search code, order code, or payment code. The transaction type contained in the transaction request message can be a business-level transaction type such as registration, login, search, order placement, or payment.
[0075] The business request information can be an HTTP request based on the HTTP protocol, which stands for Hypertext Transfer Protocol. HTTP is a request-response protocol that specifies what messages the client might send to the server and what kind of response it might receive.
[0076] Based on the HTTP protocol, a client can initiate an HTTP request to a server, and the server processes the HTTP request and returns a response to the client. Specifically, the browser, acting as an HTTP client, sends an HTTP request to the HTTP server (web server) via a URL, and the web server returns a response to the client based on the received HTTP request.
[0077] The communication process between the client and server involves two types of message passing: HTTP request messages initiated by the client and HTTP response information initiated by the server. The HTTP request message initiated by the client specifically includes: a request line, request headers, a blank line, and request data (request body); the HTTP response information initiated by the server specifically includes: a status line, message headers (response headers), a blank line, and the response body.
[0078] Specifically, a proxy server can be used to receive business request information from clients.
[0079] A proxy server is a type of server that acts as a relay. It receives and parses client requests, then forwards the requests to the target server based on the parsing results. The target server processes the requests, generates a response, and returns it to the client through the proxy server.
[0080] Specifically, this will be illustrated using an example where the proxy server is an Nginx module built as the core of a web server, and the business request information is an HTTP request:
[0081] like Figure 3 As shown, the Nginx module receives HTTP request information from the client. This HTTP request message includes a request line, request headers, and request data. Business codes, business types, and other data can be stored in the request headers or request data. The proxy server forwards the client's business request information to the target server according to certain rules. The target server processes the client's business request information and generates business response information, which includes a status line, message headers, and a response body. The status line corresponds one-to-one with the request line, the message headers correspond one-to-one with the request headers, and the message body corresponds one-to-one with the request data.
[0082] S204, call the parsing script to parse the request body in the business request information to obtain the request business code and the business type corresponding to the business code.
[0083] The parsing script can be an embedded script type compatible with the processing module (such as the Nginx module) in the proxy server. The parsing script is used to parse the request body of the client's business request information. Specifically, the parsing script can be a Lua script or other scripts with parsing functions that are compatible with the Nginx module in the proxy server.
[0084] Business request information is generally an HTTP request, which typically includes a request line, request headers, and request body (request data).
[0085] Specifically, the HTTP request line includes the protocol type required for parsing, and the HTTP request header or request body contains the object that the proxy server needs to parse. The parsing method can be that the proxy server's Nginx module calls a Lua script to parse the code in the request header or request body based on the protocol type in the request line, obtaining the request's business code and the corresponding business type.
[0086] It should be noted that the location of the parsed object in the business request information varies depending on the type of business request information. Generally, the parsed object is stored in the request body of the business request information. In specific cases, the parsed object can be stored in the request header of the business request information. In this case, it is necessary to store the parsed object in the request header of the business request information in the form of "attributes and attribute values" according to certain storage rules. This method is more cumbersome than the other method.
[0087] The requested business code is a code that the proxy server can directly process; specifically, it can be the transaction code of a transaction request. The business type refers to the type of user's business request information at the business level; specifically, it can be the transaction type of a transaction request message, such as registration, login, search, order placement, payment, etc.
[0088] Specifically, the Nginx module parses the request body of the business request information based on the protocol type of the request line. During the parsing process, the Nginx module controls the Lua script to extract the business code and business type contained in the request body, thus obtaining the request's business code and the corresponding business type.
[0089] S206. Based on the business traffic status of the business type and the mapping relationship table between the business type and the server, determine the target server for processing the business code.
[0090] Among them, the business traffic status of the business type represents the amount of business volume of the target business type within a certain period of time. The business traffic status includes: normal traffic status, business traffic surge status, etc.
[0091] Normal traffic status is defined as a situation where the difference between the increase in business request information from the client and the processing volume of business request information from the target server is less than a preset threshold over a period of time. Under this traffic status, it can be guaranteed that the target server will process the client's business request information and return business response information without exceeding the designed load.
[0092] A surge in business traffic occurs when the difference between the increase in business request information from clients and the processing volume of business request information from the target server exceeds a preset threshold over a period of time. Under this traffic condition, the processing of client business request information and the return of business response information can be guaranteed for a short period of time. However, as time goes on, the computing resources of the target server gradually become saturated until the target server's load capacity reaches the designed load value. At this point, the processing of client business request information and the return of business response information cannot be guaranteed.
[0093] The mapping table between business types and servers can be pre-configured in the proxy server. There can be multiple target servers, and the business types handled by each target server are generally different.
[0094] Specifically, different mapping tables are selected based on the business traffic status of the business type. For example, when the business traffic status of a certain business type is normal, the mapping table for normal traffic status is selected; when the business traffic status of a certain business type is surge, the mapping table for surge is selected. That is, the number of servers corresponding to this business type is greater than that in the normal traffic status, or the performance of the servers corresponding to this business type is better than that in the normal traffic status.
[0095] The mapping table for different business traffic states can be selected based on the business traffic state of the business type. Based on the mapping table for different business traffic states, the business type, and the business type, the target server for processing the business code can be determined.
[0096] The target server can be a server with strong load capacity or large remaining load capacity. Specifically, when there are multiple servers corresponding to a certain business type, the server with the strongest load capacity or the largest remaining load capacity can be used as the target server. S208, forward the business code to the target server.
[0097] After obtaining the target server for the determined business code of the business type, the business code is forwarded to the target server.
[0098] Specifically, for multiple business request messages, the system parses and forwards them based on their different business types, forwarding the business code to a target server that processes only that single business type. It should be noted that the target server can be configured to handle multiple business types, but within a certain time period, it only processes business codes for a single business type to improve processing efficiency. Alternatively, the business type processed by the target server can be changed; for example, in the first time period, the target server processes login business processing, and in the second time period, it processes payment business processing.
[0099] In the aforementioned business request processing method, the request body of the business request information is parsed by calling a parsing script to obtain the business code at the code level and the business type at the business level. Based on the business traffic status of the business type, the business type itself, and the mapping table between the business type and the server, the target server for the business code can be directly obtained. This method differs from traditional uniform load balancing; instead, it sets up corresponding servers for different business types and considers the business traffic status of each business type. On the one hand, it eliminates the need to add extra forwarding configuration for each user's business request, as the forwarding of the business code is completed through the mapping table between the business type and the server, making the forwarding process simple and efficient. On the other hand, it considers the business traffic status of different business types during distribution, enabling it to handle various contingency situations and improve load balancing capabilities.
[0100] In one embodiment, the target server for processing the service code is determined based on the service traffic status of the service type and a mapping table between service types and servers. Figure 4 As shown, the method for determining the processing of business codes includes:
[0101] S402, If the service type is in a normal service traffic state, then obtain the mapping relationship table between the service type and the server;
[0102] Among them, the normal business traffic state can be defined as the difference between the growth of the client's business request information and the processing volume of the target server's business request information within a certain period of time being less than a preset threshold. Under this traffic state, it can be guaranteed that the target server will process the client's business request information and return business response information without exceeding the designed load.
[0103] Specifically, a mapping table between multiple service types and servers can be pre-defined. This mapping table can be for normal service traffic conditions or for service traffic surge conditions.
[0104] Taking the registration business type as an example, if the difference between the growth of registration business request information and the processing volume of business request information on the target server is less than a preset threshold within a certain period of time, then the registration business type is in a normal business traffic state. In this case, the mapping relationship table between the business type and the server is obtained, that is, the mapping relationship table of the normal business traffic state.
[0105] If the difference between the growth rate of registered business request information and the processing volume of business request information on the target server exceeds a preset threshold within a certain period, then the mapping relationship table between business type and server is obtained, that is, the mapping relationship table of business traffic surge state.
[0106] S404: Based on the business type, search the mapping table between business types and servers to determine the target server for processing the business code.
[0107] Specifically, based on a pre-defined mapping table between multiple business types and servers, the target server for processing the business code is determined according to the business type.
[0108] In this embodiment, based on the business type, the mapping table between business type and server is searched. The server that processes the transaction code under this transaction type can be quickly obtained based on the mapping table between business type and server, providing a basis for forwarding the transaction code to the target server in the future.
[0109] In one embodiment, determining the target server for processing the service code based on the service traffic status of the service type and the mapping table between the service type and the server includes: if the service type is in a state of surge in service traffic, obtaining the designated forwarding server corresponding to the service type based on the mapping table between the service type and the server; and determining the target server for processing the service code based on the load status of the designated forwarding server.
[0110] Among them, the surge in business traffic can be defined as a situation where the difference between the increase in business request information from clients and the processing volume of business request information from the target server exceeds a preset threshold within a certain period of time. Under this traffic condition, the processing of client business request information and the return of business response information can be guaranteed for a short period of time. However, as time goes by, the computing resources of the target server gradually become saturated until the target server's load capacity reaches the designed load value. At this point, the processing of client business request information and the return of business response information cannot be guaranteed.
[0111] If the business type of the business request information is experiencing a surge in business traffic, it is necessary to obtain the specified forwarding server corresponding to the business type.
[0112] The specified server includes all servers under a certain business type. The specified server contains one or more servers. Therefore, when there is only one specified server, the specified server is the target server. When there are multiple specified servers, one server can be selected from the specified servers as the target server.
[0113] The designated forwarding servers can include the target server and other servers. These other servers handle the same types of business as the target server, but their computing resources can differ from those of the target server. For example, the performance of the other servers may be superior to that of the target server, or vice versa. It should be noted that performance and computing resources represent the server's specific data throughput capacity, and are both metrics for measuring the service's data processing capabilities.
[0114] The load status of the specified forwarding server includes: the specified forwarding server is saturated, and the specified forwarding server is not saturated.
[0115] If the designated forwarding server is at full load, a backup designated server should be selected as the target server for the service type experiencing a surge in traffic. If the designated forwarding server is not at full load, it can be used as the target server for the service type experiencing a surge in traffic.
[0116] In this embodiment, by judging the load status of the designated forwarding server, the problem of load imbalance that may occur when the service type is in a state of surge in business traffic can be solved. This provides a server with sufficient computing resources in advance for the business code of the subsequent target server to process business request information, thereby improving the server's data throughput and thus improving the server's processing efficiency.
[0117] In one embodiment, determining the target server for processing the service code based on the load status of the designated forwarding server includes: if the load of the designated forwarding server is not saturated, then using the designated forwarding server with the unsaturated load as the target server for processing the service code; if the load of the designated forwarding server is saturated, then expanding the standby designated server into a standby designated server for the service type; and using the standby designated server as the target server for the service type.
[0118] Specifically, such as Figure 5 The flowchart illustrating the specified method for the target server shown includes:
[0119] S502: Determine if the load status of the specified forwarding server is saturated. If yes, execute S504; otherwise, execute S508.
[0120] The load status of a specified forwarding service can be determined by the data traffic between the proxy server and the specified forwarding server interface. Based on the cumulative data throughput over a period of time and the designed load of the specified forwarding server, the load status of the specified forwarding server can be determined.
[0121] S504 expands the standby designated server to a standby designated server for a specific business type.
[0122] This can be achieved by pre-configuring one or more designated forwarding servers for the target servers corresponding to each business type. When the server load is saturated, the one or more pre-configured designated forwarding servers will be used as backup designated servers.
[0123] Alternatively, the backup designated service can be temporarily configured to expand the backup designated server into a designated server for a specific business type.
[0124] S506 specifies the backup designated server as the target server for the business type.
[0125] S508 designates a specified forwarding server that is not under load as the target server for processing the service code.
[0126] In this embodiment, by judging whether the load status of the specified forwarding server is saturated, the most suitable target server for processing the service code is found under different load statuses of the specified forwarding servers. The performance and load status of each server are taken into account, so that the computing resources of the target server are matched with the traffic of service request information. Thus, the computing resources of the target server are saved while improving the processing efficiency of the target server.
[0127] In one embodiment, the business request processing method further includes: if the absolute value of the difference between the number of business requests of a business type in the current period and the preset number of business requests is greater than a first threshold, and the absolute value of the difference between the number of business requests of a business type in two adjacent periods is greater than a second threshold, then it is determined that the business type is in a state of business traffic surge.
[0128] The first threshold is determined by considering the average number of business requests for a particular business type over a period of time.
[0129] The second threshold is used to measure the growth rate of the number of business requests for the current business type within the current period. The size of the second threshold is determined based on the performance of the target server and the server's load status. Understandably, the better the performance of the target server and the less saturated the server's load status, the larger the second threshold will be.
[0130] The duration of a cycle can be determined by the frequency of business request information. The higher the frequency of business request information, the shorter the duration of a cycle. Specifically, the duration of a cycle can be 5 minutes.
[0131] Specifically, such as Figure 6 The diagram showing the business request information cycle determines the business type's current business traffic status: if the absolute value of the difference between the number of business requests for the business type in the second cycle and the preset number of business requests is greater than the first threshold, and the absolute value of the difference between the number of business requests for the business type in the first cycle and the second cycle is greater than the second threshold, then the business type is determined to be in a business surge state.
[0132] In this embodiment, by setting two thresholds, the absolute increase in the number of business requests and the growth rate of the number of business requests are used to determine whether a business type is in a state of surge in business traffic, providing a basis for how to forward business request information in a state of surge in business traffic.
[0133] In one embodiment, if a service type experiences a surge in traffic, the associated service types are retrieved; and a designated forwarding server is assigned to the associated service types.
[0134] Among them, the related business types refer to business types that are related to the original business types at the business level. The original business types are registration, login, search, order placement, and payment.
[0135] Specifically, the original business type is the registration business type, and the associated business type can be the login business type.
[0136] If the original business type is one of the search, order placement, or payment business types, the associated business types can be the other two.
[0137] When a business type experiences a surge in traffic, expanding the designated forwarding servers for the associated business type includes: expanding the designated forwarding servers according to the order of the associated business types.
[0138] The order of related business types indicates the logical sequence between the original business types and related business types at the business level. For example, there is no sequence between the registration and login business types and related business types. That is, a user can send a registration request first or a login request first.
[0139] For example, there is a sequence to the three business types of search, order placement, and payment, as well as related business types. The general order is search first, then order placement, and then payment, or order placement followed by payment, or payment can be made directly.
[0140] Specifically, for existing business types and related business types without order, when the existing business type is experiencing a surge in business traffic, the designated forwarding server is expanded simultaneously based on the existing business type and the related business type, that is, the designated forwarding server is expanded for the related business type.
[0141] For existing business types and related business types in a certain order, when the existing business type experiences a surge in business traffic, the designated forwarding server is expanded according to the related business types that follow the existing business type in order.
[0142] In this embodiment, by considering the degree of association and order of the original business types and related business types, it is possible to predict the surge in business-related businesses in advance, expand the servers in advance, prepare for the surge in related businesses, and improve processing efficiency. In one embodiment, the mapping relationship table between business types and servers is updated according to the designated forwarding server of the expanded business type.
[0143] Among them, such as Figure 7 As shown, based on the original mapping table between the service type and the target server before the update, and the mapping table that needs to be added for the specified forwarding server of the expanded service type, the updated mapping table between the service type and the server is obtained.
[0144] Specifically, the mapping table before the update includes business types (registration, search, and order placement) and the target servers corresponding to each business type (Server 1, Server 2, and Server 3). If there is a surge in business traffic or the designated forwarding server is overloaded, the mapping relationships between the original business types (registration, search, and order placement) and their associated business types (login and payment) and the corresponding designated forwarding servers are recorded, resulting in an updated mapping table that needs to be added. Based on the original mapping table between business types and target servers before the update, and the mapping table between the expanded business types and designated forwarding services, the updated mapping table between business types and servers is obtained.
[0145] In this embodiment, by updating the mapping table between service types and servers, the service types and extended service types can be forwarded directly based on the updated mapping table, which can improve the convenience of forwarding service request information.
[0146] In one embodiment, such as Figure 8 As shown, an Nginx-based dynamic load balancing method based on transactions is provided, including:
[0147] S802, the client initiates a business request.
[0148] S804, the proxy server receives business request information from the client.
[0149] The proxy server accepts HTTP requests through the Nginx application.
[0150] S806 calls the parsing script to parse the request body in the business request information to obtain the request's business code and the corresponding business type.
[0151] Specifically, the Nginx application parses HTTP requests, and during the parsing process, Lua scripts are called to dynamically obtain the business type of the client request.
[0152] S808: Determine if the service type is in a normal traffic state. If yes, execute S810; otherwise, execute S814.
[0153] S810: If the service type is in a normal service traffic state, then obtain the mapping table between the service type and the server.
[0154] Specifically, if the absolute value of the difference between the number of business requests for a business type in the current period and the preset number of business requests is greater than the first threshold, and the absolute value of the difference between the number of business requests for a business type in two adjacent periods is greater than the second threshold, then the business type is determined to be in a state of business traffic surge.
[0155] If a business type is experiencing a surge in business traffic, the system retrieves the associated business types; expands the specified forwarding servers for the associated business types; and expands the specified forwarding servers based on the expansion of the associated business types.
[0156] Specifically, based on the designated forwarding server for the expanded service type, the mapping table between the service type and the server is updated.
[0157] S812: Based on the business type, search the mapping table between business types and servers to determine the target server for processing the business code, and then execute S818.
[0158] S814 If the service type is experiencing a surge in traffic, obtain the specified forwarding server corresponding to the service type based on the mapping table between service types and servers.
[0159] If the load of the designated forwarding server is not saturated, the designated forwarding server with the unsaturated load will be used as the target server for processing the service code; if the load of the designated forwarding server is saturated, the backup designated server will be expanded to be a backup designated server for the service type; and the backup designated server will be used as the target server for processing the service code.
[0160] Specifically, based on the designated forwarding server for the expanded service type, the mapping table between the service type and the server is updated.
[0161] S816 determines the target server for processing the service code based on the load status of the specified forwarding server.
[0162] S818 forwards the service code to the target server.
[0163] S820, the target server returns a business response message.
[0164] In one embodiment, directly rewriting the Nginx load balancing module and adding a transaction-based forwarding configuration is a highly coupled application approach that is highly stable and less prone to errors.
[0165] Specifically, at the nginx level, this involves adding a location to match transactions when Lua scripts are not being used for processing. A simple example of the added configuration is as follows:
[0166] #Targeting search transactions
[0167] # indicates the destination server address for the specific forwarding of the transaction;
[0168] Set some header information (add configuration 1 to the request header);
[0169] Additionally, set some header information (add configuration 2 to the request header);
[0170] Set some more header information (add configuration 3 to the request header).
[0171] In this embodiment, the request body of the business request information is parsed by calling a parsing script to obtain the business code and business type at the code level. Based on the business traffic status of the business type, the business type itself, and the mapping table between the business type and the server, the target server for the business code can be directly obtained. This method differs from traditional uniform load balancing; instead, it sets up corresponding servers for different business types and considers the business traffic status of each business type. On the one hand, it eliminates the need for additional forwarding configurations for each user's business request, as the forwarding of the business code is completed through the mapping table between the business type and the server, making the forwarding process simple and efficient. On the other hand, it considers the business traffic status of different business types during distribution, enabling it to handle various contingency situations and improve load balancing capabilities. This method is a non-intrusive way to extend Nginx's load balancing approach, adding an Nginx load balancing strategy that can allocate different servers for processing based on the transaction type initiated by the client, achieving the goal of specific servers handling specific transactions. It enhances Nginx's load balancing approach, supports dynamic transaction allocation by transaction type, well meets the business needs of this scenario, greatly reduces Nginx configuration settings, and is convenient to use and highly scalable.
[0172] It should be understood that although the steps in the flowcharts of the above embodiments are shown sequentially according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the flowcharts of the above embodiments may include multiple steps or multiple stages. These steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the steps or stages of other steps.
[0173] Based on the same inventive concept, this application also provides a business request processing apparatus for implementing the business request processing method described above. The solution provided by this apparatus is similar to the implementation scheme described in the above method; therefore, the specific limitations in one or more business request processing apparatus embodiments provided below can be found in the limitations of the business request processing method described above, and will not be repeated here.
[0174] In one embodiment, such as Figure 9 As shown, a service request processing apparatus is provided, including: a receiving module 902, a parsing module 904, a processing module 906, and a forwarding module 908, wherein:
[0175] Receiver module 902 is used to receive business request information from the client;
[0176] Parsing module 904 is used to call the parsing script to parse the request body in the business request information to obtain the request business code and the business type corresponding to the business code;
[0177] Processing module 906 is used to determine the target server for processing the service code based on the service traffic status of the service type and the mapping relationship table between the service type and the server.
[0178] Forwarding module 908 is used to forward the business code to the target server.
[0179] In one embodiment, the processing module 906 is further configured to, if the service type is in a normal service traffic state, obtain a mapping table between the service type and the server; and, based on the service type, search the mapping table between the service type and the server to determine the target server for processing the service code.
[0180] In one embodiment, the processing module 906 is further configured to, if the service type is in a state of surge in service traffic, obtain the specified forwarding server corresponding to the service type according to the mapping relationship table between the service type and the server; and determine the target server for processing the service code according to the load status of the specified forwarding server.
[0181] In one embodiment, the processing module 906 is further configured to: if the load of the specified forwarding server is not saturated, use the unsaturated specified forwarding server as the target server for processing the service code; if the load of the specified forwarding server is saturated, expand the backup specified server into a backup specified server for the service type, and use the backup specified server as the target server for processing the transaction code.
[0182] In one embodiment, the processing module 906 is further configured to determine that the business type is in a state of business traffic surge if the absolute value of the difference between the number of business requests of the business type in the current period and the preset number of business requests is greater than a first threshold, and the absolute value of the difference between the number of business requests of the business type in two adjacent periods is greater than a second threshold.
[0183] In one embodiment, the processing module 906 is further configured to, if the service type is in a state of surge in service traffic, obtain the associated service type of the service type; and specify a forwarding server for the associated service type.
[0184] In one embodiment, the processing module 906 is further configured to update the mapping table between service types and servers according to the specified forwarding server of the extended service type.
[0185] Each module in the aforementioned service request processing device can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in or independent of the processor in a computer device, or stored in the memory of a computer device as software, so that the processor can invoke and execute the operations corresponding to each module.
[0186] In one embodiment, a computer device is provided, which may be a server, and its internal structure diagram may be as follows: Figure 10As shown, this computer device includes a processor, memory, input / output interfaces (I / O), and a communication interface. The processor, memory, and I / O interfaces are connected via a system bus, and the communication interface is also connected to the system bus via the I / O interfaces. The processor provides computational and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system, computer programs, and a database. The internal memory provides the environment for the operation of the operating system and computer programs stored in the non-volatile storage media. The database stores business request information data. The I / O interfaces are used for exchanging information between the processor and external devices. The communication interface is used for communicating with external terminals via a network connection. When the computer program is executed by the processor, it implements a business request processing method.
[0187] Those skilled in the art will understand that Figure 10 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.
[0188] In one embodiment, a computer device is also provided, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the steps in the above method embodiments.
[0189] In one embodiment, a computer-readable storage medium is provided having a computer program stored thereon that, when executed by a processor, implements the steps in the above method embodiments.
[0190] In one embodiment, a computer program product is provided, including a computer program that, when executed by a processor, implements the steps in the above method embodiments.
[0191] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. Any references to memory, databases, or other media used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM can take many forms, such as Static Random Access Memory (SRAM) or Dynamic Random Access Memory (DRAM). The databases involved in the embodiments provided in this application may include at least one type of relational database and non-relational database. Non-relational databases may include, but are not limited to, blockchain-based distributed databases. The processors involved in the embodiments provided in this application may be general-purpose processors, central processing units, graphics processing units, digital signal processors, programmable logic devices, quantum computing-based data processing logic devices, etc., and are not limited to these.
[0192] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0193] The embodiments described above are merely illustrative of several implementation methods of this application, and while the descriptions are specific and detailed, they should not be construed as limiting the scope of this patent application. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the protection scope of this application. Therefore, the protection scope of this application should be determined by the appended claims.
Claims
1. A business request processing method, characterized in that, The method includes: Receive business request information from the client; The parsing script is invoked to parse the request body in the business request information to obtain the request's business code and the business type corresponding to the business code; Based on the business traffic status of the business type and the mapping relationship table between the business type and the server, the target server for processing the business code is determined. The determination of the target server for processing the business code based on the business traffic status of the business type and the mapping relationship table between the business type and the server includes: selecting different mapping tables based on the business traffic status of the business type, and determining the target server for processing the business code based on the mapping tables under different business traffic statuses and the business type. The business traffic status of the business type represents the amount of business volume of the target business type within a certain period of time. Forward the service code to the target server; Specifically, determining the target server for processing the service code based on the service traffic status of the service type and the mapping table between service types and servers includes: If the absolute value of the difference between the number of service requests of the service type in the current period and the preset number of service requests is greater than a first threshold, and the absolute value of the difference between the number of service requests of the service type in two adjacent periods is greater than a second threshold, then the service type is determined to be in a state of surge in service traffic. Based on the mapping table of surge in service traffic states, the designated forwarding server corresponding to the service type is obtained. The first threshold is determined by considering the average number of service requests of the service type over a period of time, and the second threshold is used to measure the growth rate of the number of service requests of the service type in the current period. The absolute value of the difference between the number of service requests of the service type in the current period and the preset number of service requests is used to characterize the absolute growth of the number of service requests of the service type; the absolute value of the difference between the number of service requests of the service type in two adjacent periods is used to characterize the growth rate of the number of service requests of the service type. Based on the load status of the designated forwarding server, determine the target server for processing the service code; The method further includes: If the business type is experiencing a surge in business traffic, then obtain the associated business type of the business type; According to the order of the associated service types, a forwarding server is designated for the associated service types that are in the order of the service types. The order of the associated service types indicates the logical order between the service types and the associated service types at the service level.
2. The method according to claim 1, characterized in that, Based on the service traffic status of the service type and the mapping table between service types and servers, the target server for processing the service code is determined, including: If the service type is in a normal service traffic state, then obtain the mapping relationship table between the service type and the server; Based on the business type, the target server for processing the business code is determined by searching the mapping table between the business type and the server.
3. The method according to claim 1, characterized in that, Based on the load status of the designated forwarding server, determine the target server for processing the service code, including: If the load of the designated forwarding server is not saturated, then the designated forwarding server with unsaturated load will be used as the target server for processing the service code. If the designated forwarding server is overloaded, the designated forwarding server that was previously configured for the target server will be expanded into a backup designated server for the service type, and the backup designated server will be used as the target server for processing the service code.
4. The method according to claim 1 or 3, characterized in that, The method further includes: Update the mapping table between the service type and the server according to the designated forwarding server for the expanded service type.
5. A business request processing device, characterized in that, The device includes: The receiving module is used to receive business request information from the client; The parsing module is used to call the parsing script to parse the request body in the business request information to obtain the request business code and the business type corresponding to the business code; The processing module is configured to determine the target server for processing the service code based on the service traffic status of the service type and the mapping relationship table between the service type and the server. The determination of the target server for processing the service code based on the service traffic status of the service type and the mapping relationship table between the service type and the server includes: selecting different mapping tables based on the service traffic status of the service type, and determining the target server for processing the service code based on the mapping tables under different service traffic statuses and the service type. The service traffic status of the service type represents the amount of service volume of the target service type within a certain period of time. The forwarding module is used to forward the service code to the target server; The processing module is further configured to: determine that the service type is in a surge in traffic if the absolute value of the difference between the number of service requests of the service type in the current period and the preset number of service requests is greater than a first threshold, and the absolute value of the difference between the number of service requests of the service type in two adjacent periods is greater than a second threshold; obtain the designated forwarding server corresponding to the service type according to the mapping table of surge in traffic; the first threshold is determined by considering the average number of service requests of the service type over a period of time; the second threshold is used to measure the growth rate of the number of service requests of the service type in the current period; the absolute value of the difference between the number of service requests of the service type in the current period and the preset number of service requests is used to characterize the absolute growth of the number of service requests of the service type; the absolute value of the difference between the number of service requests of the service type in two adjacent periods is used to characterize the growth rate of the number of service requests of the service type; and determine the target server for processing the service code according to the load status of the designated forwarding server. The processing module is further configured to, if the service type is in a state of surge in service traffic, obtain the associated service types of the service type; and, according to the order of the associated service types, expand the designated forwarding servers for the associated service types that are in the order of the service type, where the order of the associated service types indicates the logical order of the service type and the associated service types at the service level.
6. The apparatus according to claim 5, characterized in that, The processing module is further configured to, if the service type is in a normal service traffic state, obtain a mapping table between the service type and the server; and, based on the service type, search the mapping table between the service type and the server to determine the target server for processing the service code.
7. The apparatus according to claim 5, characterized in that, The processing module is further configured to, if the load of the designated forwarding server is not saturated, use the designated forwarding server with the unsaturated load as the target server for processing the service code; if the load of the designated forwarding server is saturated, expand the designated forwarding server that has been pre-configured for the target server into a backup designated server for the service type, and use the backup designated server as the target server for processing the service code.
8. The apparatus according to claim 5 or 7, characterized in that, The processing module is further configured to update the mapping table between the service type and the server according to the designated forwarding server of the expanded service type.
9. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the processor executes the computer program, it implements the steps of the method according to any one of claims 1 to 4.
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 steps of the method according to any one of claims 1 to 4.
11. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 4.
Citation Information
Patent Citations
Business instruction processing method and device, computer equipment and storage medium
CN110351342A
Business data distributed processing method and device based on cable business data type
CN114327863A