A load balancing method and device for graph database request routing based on HTTP2

Through the load balancing method based on the HTTP2 protocol, the header in the HTTP2 request is parsed to obtain the graph space name, the corresponding cluster service is found, and the request is routed using the load balancing algorithm, which solves the request routing problem of different graph database clusters and improves system performance and High availability.

CN118400436BActive Publication Date: 2024-09-17杭州悦数科技有限公司
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410807439.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-06-21
Publication Date
2024-09-17
Estimated Expiration
2044-06-21

AI Technical Summary

Technical Problem

The existing technology cannot accurately route requests to the query engine services of different graph database clusters while the client request interface remains unified, resulting in request failure.

Method used

Using the load balancing method based on the HTTP2 protocol, by receiving and parsing the HTTP2 request containing the header, querying the cluster service name from the preset header information mapping table according to the graph space name, and forwarding the request to the corresponding cluster service, using load balancing Algorithms (such as round robin, weighted round robin, random, least connections, source address hashing) for routing.

Benefits of technology

The same URL is routed to target services with different target resources, ensuring system performance and high availability, and enhancing the ease of use, flexibility and stability of the system architecture.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118400436B
    Figure CN118400436B
Patent Text Reader

Abstract

The present application relates to the technical field of graph database query, and solves the problem in the prior art of how to accurately route requests to corresponding target resources when different target resources have the same URL, and discloses a load balancing method and device for routing graph database requests based on HTTP2, the method comprising: receiving an HTTP2 request containing a header sent by a user, parsing the HTTP2 request and finding the corresponding cluster service from a preset header information mapping table and forwarding the HTTP2 request to the cluster service, and then using a load balancing algorithm to select a service and query an engine service, so as to realize routing of the same URL to target services with different target resources, and realize load balancing of requests for different graph spaces under the premise of ensuring that the client request interface and URL remain unchanged.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of graph database query technology, and in particular to a load balancing method and device for graph database request routing based on HTTP2. Background Art

[0002] The query engine of the graph database NebulaGraph is distributed and stateless, and requests can be sent to various query engines. In the development of graph database business, the business has higher and higher requirements for high availability and high performance of services, which requires support for request load balancing on the client to distribute requests, so that the same request can be routed to different database query engine services, so that the query engine service pressure is dispersed. At the same time, when a query service crashes, it does not affect the processing of the upper-level business, and the request will be automatically distributed to the healthy query service. NebulaGraph client and server use the RPC protocol to communicate. The client's load balancing is stateless and can only process IP and port numbers and forward requests. This can only support routing requests to graph database services with the same resources.

[0003] However, when the business needs to access multiple graph database clusters at the same time, the graph database query engine service is no longer stateless because the graph spaces in different graph database clusters are different. This is because when a query request is sent, the load balancer cannot directly route the request to the query engine service of any cluster. In other words, when the client request interface remains unified, it is impossible to support multi-cluster request routing. For example, if a request to query graph A is routed to the cluster that created graph B, the request will fail.

[0004] The patent CN102263828A discloses a load balancing distribution method and device, which is used to solve the problem in the prior art that when the same target resource has different URLs, the target resource needs to be repeatedly stored on the cache server in the CDN system, but it still cannot solve the problem of how to accurately route the request to the corresponding target resource when different target resources have the same URL. Summary of the invention

[0005] The purpose of this application is to overcome the problem in the prior art of how to accurately route requests to corresponding target resources when different target resources have the same URL, and to provide a load balancing method and device for graph database request routing based on HTTP2.

[0006] In a first aspect, a load balancing method for graph database request routing based on HTTP2 is provided, comprising:

[0007] Receive an HTTP2 request including a header sent by a user, wherein a key and a value of the header represent a graph space and a graph space name respectively;

[0008] Parse the header in the HTTP2 request to obtain the graph space name;

[0009] According to the obtained graph space name, query the preset header information mapping table to obtain the corresponding cluster service name;

[0010] Forwarding the HTTP2 request to the cluster service corresponding to the cluster service name;

[0011] A load balancing algorithm is used to route the HTTP2 request to the query engine service in the cluster service for query.

[0012] In some possible implementations, the key and value of the header are configured by the client. If the key and value of the header are not configured, the key and value of the header are empty.

[0013] In some possible implementations, the content of the preset header information mapping table is: graph space name-cluster service name.

[0014] In some possible implementations, if the key and value of the header in the HTTP2 request are empty, the HTTP2 request is randomly forwarded to multiple cluster services and routed using a load balancing algorithm.

[0015] In some possible implementations, the load balancing algorithm includes, but is not limited to, round-robin, weighted round-robin, random, least connections, and source address hashing.

[0016] In a second aspect, a load balancing device for routing graph database requests based on HTTP2 is provided, comprising:

[0017] A receiving module, used for receiving an HTTP2 request including a header sent by a user, wherein the key and value of the header represent a graph space and a graph space name respectively;

[0018] A parsing module, used for parsing the header in the HTTP2 request to obtain a graph space name;

[0019] A query module is used to query and obtain the corresponding cluster service name from the preset header information mapping table according to the acquired graph space name;

[0020] A forwarding module, used for forwarding the HTTP2 request to the cluster service corresponding to the cluster service name;

[0021] The routing module is used to adopt a load balancing algorithm to route the HTTP2 request to the query engine service in the cluster service for query.

[0022] In some possible implementations, the content of the preset header information mapping table is: graph space name-cluster service name.

[0023] In a third aspect, a computer program product comprising instructions is provided, which, when executed on a computer, enables the computer to execute the method described in the first aspect.

[0024] In a fourth aspect, a computer-readable storage medium is provided, wherein the computer-readable medium stores a program code for execution by a device, wherein the program code includes steps for executing the method in any one of the implementations of the first aspect described above.

[0025] In a fifth aspect, an electronic device is provided, comprising a processor, a memory, and a program or instruction stored in the memory and executable on the processor, wherein the program or instruction, when executed by the processor, implements a method as in any one of the implementations in the first aspect above.

[0026] The present application has the following beneficial effects: by supporting the HTTP2 protocol and supporting header-based load balancing to distribute requests, the present application can realize routing of the same URL to target services with different target resources, and realize load balancing of requests for different graph spaces while ensuring that the client request interface and URL remain unchanged, thereby improving system performance and high availability, and enhancing the usability, flexibility and stability of the entire system architecture. BRIEF DESCRIPTION OF THE DRAWINGS

[0027] The drawings constituting a part of the present application are used to provide a further understanding of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application.

[0028] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.

[0029] Figure 1 It is a flow chart of a load balancing method for graph database request routing based on HTTP2 in Example 1 of the present application;

[0030] Figure 2It is a request forwarding flow chart when the header carries cluster information in the load balancing method for graph database request routing based on HTTP2 in Example 1 of the present application;

[0031] Figure 3 It is a request forwarding flow chart when the header does not carry cluster information in the load balancing method for graph database request routing based on HTTP2 in Example 1 of the present application;

[0032] Figure 4 It is a structural block diagram of a load balancing device for performing graph database request routing based on HTTP2 in Example 2 of the present application;

[0033] Figure 5 It is a schematic diagram of the internal structure of the electronic device of Example 5 of the present application.

[0034] Reference numerals:

[0035] 100, receiving module; 200, parsing module; 300, query module; 400, forwarding module; 500, routing module. DETAILED DESCRIPTION

[0036] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0037] Example 1

[0038] Embodiment 1 of the present application involves a load balancing method for routing graph database requests based on HTTP2, including: receiving an HTTP2 request containing a header sent by a user, wherein the key and value of the header respectively represent a graph space and a graph space name; parsing the header in the HTTP2 request to obtain the graph space name; querying the corresponding cluster service name from a preset header information mapping table according to the acquired graph space name; forwarding the HTTP2 request to the cluster service corresponding to the cluster service name; and using a load balancing algorithm to route the HTTP2 request to a query engine service in the cluster service for query. By supporting the HTTP2 protocol and supporting header-based load balancing to distribute requests, the same URL can be routed to a target service with different target resources. On the premise of ensuring that the client request interface and URL remain unchanged, load balancing of requests for different graph spaces can be achieved, thereby improving system performance and high availability, and enhancing the usability, flexibility and stability of the entire system architecture.

[0039] Specifically, Figure 1 A flow chart of a load balancing method for graph database request routing based on HTTP2 in application embodiment 1 is shown, including:

[0040] S100, receiving an HTTP2 request including a header sent by a user, wherein the key and value of the header represent a graph space and a graph space name respectively, and the key and value of the header are configured by the client. If the key and value of the header are not configured, the key and value of the header are empty;

[0041] It should be noted that http2 is a secure and efficient next-generation http transmission protocol. It is secure because it is built on the basis of the https protocol, and it is efficient because it transmits data through binary framing. Compared with http1, http2's multiplexing solves the blocking problem of http1's multiple request queuing serial processing and the problem of having to use multiple TCP connections to achieve concurrency. Header compression solves the problem of low transmission efficiency of http1. http2 requests can save a lot of bandwidth resources, and multiple requests can be executed in parallel on the same connection. The request processing efficiency is high. HTTP allows the client and server to pass additional information through the header in the request or response. A header consists of a name and a value in the form of: name:value.

[0042] In order to improve the efficiency of request processing, the http2 protocol needs to be supported on both the server and the client. NebulaGraph uses the fbthrift protocol for communication between the client and the server. fbthrift does not support the http2 protocol, so OKHttp3 is needed to support the http2 protocol. In order to improve the efficiency of network connections, OKHTTP3 implements network connection reuse, and each OKhttp client maintains its own connection pool and thread pool. In order to save memory, we use the singleton mode to build the OKHttp3 client.

[0043] The user configures the key and value of the custom header through the client. Multiple items can be configured. The client configures the key-value pair of the custom header into the Request.Builder of the http2 client. If the user does not configure a custom header, the default custom header is empty. The user configuration method is as follows:

[0044] Map<String, String> customHeaders = new HashMap<String, String> ();

[0045] customHeaders.put("space ", "Picture A");

[0046] SessionPoolConfig sessionPoolConfig = new SessionPoolConfig(

[0047] Arrays.asList(new HostAddress(host, port)), spaceName, user,password)

[0048] .setUseHttp2(useHttp2)

[0049] .setCustomHeaders(customHeaders);

[0050] SessionPool sessionPool = new SessionPool(sessionPoolConfig).

[0051] S200, parsing the header in the HTTP2 request to obtain a graph space name, querying a preset header information mapping table to obtain a corresponding cluster service name according to the obtained graph space name, wherein the content of the preset header information mapping table is: graph space name-cluster service name, and forwarding the HTTP2 request to the cluster service corresponding to the cluster service name;

[0052] Specifically, load balancing needs to maintain a custom header mapping table. The content of the mapping table is graph space name -> cluster service name. According to the header key, the current HTTP2 request should be routed to which cluster service. After the cluster service is determined, random routing or polling routing methods are used.

[0053] Taking the HaProxy proxy service as an example, you need to configure in the configuration file to select different cluster services based on the header:

[0054] frontend graph

[0055] bind: 8080 alpn h2,http / 1.1

[0056] log global

[0057] option httplog

[0058] mode http

[0059] acl graphA hdr(space) -i graphA

[0060] acl graphB hdr(space) -i graphB

[0061] acl graphC hdr(space) -i graphC

[0062] use_backend server1 if graphA

[0063] use_backend server2 if graphB

[0064] use_backend server3 if graphC

[0065] backend server1

[0066] mode http

[0067] balance roundrobin

[0068] cookie SERVERID insert indirect nocache

[0069] server graphA 127.0.0.1:8020 alpn h2 cookie graphA

[0070] http-reuse never

[0071] backend server2

[0072] mode http

[0073] balance roundrobin

[0074] cookie SERVERID insert indirect nocache

[0075] server graphB 127.0.0.1:8021 alpn h2 cookie graphB

[0076] http-reuse never

[0077] backend server3

[0078] mode http

[0079] Balance Round Robin

[0080] cookie SERVERID insert indirect nocache

[0081] server graphC 127.0.0.1:8022 alpn h2 cookie graphC

[0082] http-reuse never.

[0083] S300, using a load balancing algorithm to route the HTTP2 request to the query engine service in the cluster service for query;

[0084] Specifically, the http2 request needs to be accompanied by a header that specifies the cluster information. If no cluster-related header information is included, the request will be randomly routed among multiple cluster services.

[0085] When the request header contains cluster information, that is, the key and value of the header in the HTTP2 request are not empty, the request is forwarded as follows: Figure 2 As shown in the figure. The space value of the request header is graph database A. The load balancer parses the request header and obtains the value of graph database A with the key space. It will find the corresponding graph database cluster server1 from the header information mapping table based on graph database A and determine that the request needs to be forwarded to graph database cluster server1. Then, roundrobin (i.e. polling scheduling algorithm) or other load balancing algorithms are used to select the service and route the request to a query engine service graphd on graph database cluster server1.

[0086] When the request header does not contain cluster information, that is, the key and value of the header in the HTTP2 request are empty, the HTTP2 request is randomly forwarded to multiple cluster services and routed using a load balancing algorithm. The request forwarding is as follows: Figure 3 As shown in the figure, the request is routed to the third graphd service of the graph database cluster server1 by the load balancing strategy. The load balancing strategy here takes roundrobin as an example, and any load balancing algorithm can be used for implementation.

[0087] It should be noted that the load balancing algorithms include but are not limited to: round-robin, weighted round-robin, random, least connections and source address hashing.

[0088] In this embodiment, the same HTTP2 request can be routed to a graph database cluster service with different resources. During routing, the graph space information set in the request header is used to determine which cluster the current request is routed to, and then the services within the cluster are routed based on traditional load balancing strategies (including but not limited to polling, random and other algorithms). This enables the same URL to be routed to target services with different target resources, and load balancing of requests for different graph spaces is achieved while ensuring that the client request interface and URL remain unchanged, thereby improving system performance and high availability, and enhancing the ease of use, flexibility and stability of the entire system architecture.

[0089] Example 2

[0090] like Figure 4 As shown, a load balancing device for routing graph database requests based on HTTP2 according to Embodiment 2 of the present application includes:

[0091] The receiving module 100 is used to receive an HTTP2 request including a header sent by a user, wherein the key and value of the header represent a graph space and a graph space name respectively;

[0092] A parsing module 200, used for parsing the header in the HTTP2 request to obtain a graph space name;

[0093] A query module 300 is used to query and obtain a corresponding cluster service name from a preset header information mapping table according to the acquired graph space name;

[0094] The forwarding module 400 is used to forward the HTTP2 request to the cluster service corresponding to the cluster service name;

[0095] The routing module 500 is used to adopt a load balancing algorithm to route the HTTP2 request to the query engine service in the cluster service for query.

[0096] It should be noted that other specific implementations of the load balancing device for routing graph database requests based on HTTP2 in the embodiment of the present invention can be found in the specific implementations of the load balancing method for routing graph database requests based on HTTP2 mentioned above. To avoid redundancy, they will not be repeated here.

[0097] Example 3

[0098] A computer program product involved in Example 3 of the present application is used to store a computer program. When the computer program runs on a computer, the method in any one of the implementation modes in Example 1 of the present application is implemented.

[0099] Example 4

[0100] A computer-readable storage medium according to Embodiment 4 of the present application, wherein the computer-readable storage medium stores a program code for execution by a device, wherein the program code includes steps for executing a method in any one of the implementations in Embodiment 1 of the present application;

[0101] Among them, the computer-readable storage medium can be a read-only memory (ROM), a static storage device, a dynamic storage device or a random access memory (RAM); the computer-readable storage medium can store program code, and when the program stored in the computer-readable storage medium is executed by the processor, the processor is used to execute the steps of the method in any one of the implementation methods in Example 1 of the present application.

[0102] Example 5

[0103] like Figure 5 As shown, an electronic device involved in Embodiment 5 of the present application includes a processor, a memory, and a program or instruction stored in the memory and executable on the processor, and when the program or instruction is executed by the processor, a method in any one of the implementations in Embodiment 1 of the present application is implemented;

[0104] Among them, the processor can adopt a general-purpose central processing unit (CPU), a microprocessor, an application specific integrated circuit (ASIC), a graphics processing unit (GPU) or one or more integrated circuits to execute relevant programs to implement the method in any one of the implementation methods in Example 1 of the present application.

[0105] The processor may also be an integrated circuit electronic device with signal processing capability. In the implementation process, each step of the method in any implementation of Embodiment 1 of the present application may be completed by an integrated logic circuit of hardware in the processor or by instructions in software form.

[0106] The above-mentioned processor may also be a general-purpose processor, a digital signal processor, an application-specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. The methods, steps and logic block diagrams disclosed in the embodiments of the present application may be implemented or executed. The general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc. The steps of the method disclosed in the embodiments of the present application may be directly embodied as being executed by a hardware decoding processor, or may be executed by a combination of hardware and software modules in a decoding processor. The software module may be located in a mature storage medium in the art such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory or an electrically erasable programmable memory, a register, etc. The storage medium is located in a memory, and the processor reads the information in the memory, and completes the functions required to be performed by the unit included in the data processing device of the embodiment of the present application in combination with its hardware, or executes the method in any one of the implementation modes in the embodiment 1 of the present application.

[0107] The above are only preferred specific implementations of the present application; however, the protection scope of the present application is not limited thereto. Any technician familiar with the technical field can make equivalent replacements or changes according to the technical solution and its improved ideas of the present application within the technical scope disclosed in the present application, which should be included in the protection scope of the present application.

Claims

1. A load balancing method for graph database request routing based on HTTP2, characterized in that: include: Receive an HTTP2 request including a header sent by a user, wherein a key and a value of the header represent a graph space and a graph space name respectively; Parse the header in the HTTP2 request to obtain the graph space name; According to the obtained graph space name, query the preset header information mapping table to obtain the corresponding cluster service name; Forwarding the HTTP2 request to the cluster service corresponding to the cluster service name; A load balancing algorithm is used to route the HTTP2 request to the query engine service in the cluster service for query.

2. According to the load balancing method for graph database request routing based on HTTP2 in claim 1, it is characterized in that: The key and value of the header are configured by the client. If the key and value of the header are not configured, the key and value of the header are empty.

3. The load balancing method for graph database request routing based on HTTP2 according to claim 1 is characterized in that: The content of the preset header information mapping table is: graph space name-cluster service name.

4. The load balancing method for graph database request routing based on HTTP2 according to claim 2 is characterized in that: If the key and value of the header in the HTTP2 request are empty, the HTTP2 request is randomly forwarded to multiple cluster services and routed using a load balancing algorithm.

5. The load balancing method for graph database request routing based on HTTP2 according to any one of claims 1 to 4, characterized in that: The load balancing algorithm includes, but is not limited to, round-robin, weighted round-robin, random, least connections, or source address hashing.

6. A load balancing device for graph database request routing based on HTTP2, characterized in that: include: A receiving module, used for receiving an HTTP2 request including a header sent by a user, wherein the key and value of the header represent a graph space and a graph space name respectively; A parsing module, used for parsing the header in the HTTP2 request to obtain a graph space name; A query module is used to query and obtain the corresponding cluster service name from the preset header information mapping table according to the acquired graph space name; A forwarding module, used for forwarding the HTTP2 request to the cluster service corresponding to the cluster service name; The routing module is used to adopt a load balancing algorithm to route the HTTP2 request to the query engine service in the cluster service for query.

7. The load balancing device for performing graph database request routing based on HTTP2 according to claim 6, characterized in that: The content of the preset header information mapping table is: graph space name-cluster service name.

8. A computer program product, characterized in that The computer program product stores computer instructions, and when the computer instructions are executed by a processor, the method according to any one of claims 1 to 5 is implemented.

9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a program code for execution by a device, wherein the program code includes steps for executing the method according to any one of claims 1 to 5.

10. An electronic device, characterized in that: The electronic device includes a processor, a memory, and a program or instruction stored in the memory and executable on the processor, wherein the program or instruction implements the method according to any one of claims 1 to 5 when executed by the processor.