A method and device for forwarding operation requests

By setting weight rules based on the operation performance of the slave database, load-balanced forwarding of operation requests is achieved, which solves the problem of low processing efficiency of the slave database with weak load capacity, and improves the efficiency and stability of the operation request processing of the database system.

CN112100208BActive Publication Date: 2024-09-13BEIJING KINGSOFT CLOUD NETWORK TECH CO LTD
View PDF 9 Cites 0 Cited by

Patent Information

Application Number
CN202010937228.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-09-08
Publication Date
2024-09-13
Estimated Expiration
2040-09-08

AI Technical Summary

Technical Problem

In a database system, a secondary database with a weak load capacity cannot process concurrent read operation requests in a timely manner, resulting in low efficiency in processing operation requests. Existing technologies cannot effectively solve this problem.

Method used

By determining the type of operation request and the target database, and setting weight rules according to the operation performance of the slave database, load-balanced forwarding of multiple slave databases is achieved to ensure that each request processed by the slave database matches its operation performance.

Benefits of technology

The processing efficiency of operation requests is improved, and concurrent read operations can be effectively shared from the database through load balancing, which improves the stability and responsiveness of the system.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN112100208B
    Figure CN112100208B
Patent Text Reader

Abstract

The present application relates to a method and device for forwarding an operation request, wherein the method comprises: determining the operation type of the operation request to be forwarded; determining the target database for processing the operation request to be forwarded according to the operation type; when the target database is a slave database, forwarding the operation request to be forwarded to a target slave database among multiple slave databases according to a preset weight rule, wherein the preset weight rule is set according to the operation performance of each slave database in the multiple slave databases. The present application solves the technical problem of low processing efficiency of operation requests.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computers, and in particular to a method and device for forwarding an operation request. Background Art

[0002] Faced with the increasing number of system accesses, the database throughput faces a huge bottleneck. For application systems with a large number of concurrent read operations and fewer write operations at the same time, in order to ensure the stability of the database product, the database is divided into a master database and a slave database. The slave database handles a large number of concurrent read operations. The current system forwards read operations to the slave database, which makes each slave database share the concurrent read operations evenly, resulting in the slave database with stronger load capacity being relatively idle, while the slave database with weaker load capacity cannot process the operation request in time, which seriously affects the processing efficiency of the operation request.

[0003] To address the above-mentioned problems, no effective solution has been proposed yet. Summary of the invention

[0004] The present application provides a method and device for forwarding an operation request, so as to at least solve the technical problem of low processing efficiency of operation requests in related technologies.

[0005] According to one aspect of an embodiment of the present application, a method for forwarding an operation request is provided, including:

[0006] Determine the operation type of the operation request to be forwarded;

[0007] Determine, according to the operation type, a target database for processing the operation request to be forwarded;

[0008] When the target database is a slave database, the operation request to be forwarded is forwarded to a target slave database among multiple slave databases according to a preset weight rule, wherein the preset weight rule is set according to the operation performance of each slave database among the multiple slave databases.

[0009] Optionally, forwarding the operation request to be forwarded to a target slave database among multiple slave databases according to the preset weight rule includes:

[0010] Determine an initial slave database that receives a previous operation request, and an initial consecutive number corresponding to the initial slave database, wherein the initial consecutive number is the number of operation requests that the initial slave database has continuously received;

[0011] Determine whether the initial consecutive number reaches the consecutive number corresponding to the initial slave database, wherein the preset weight rule is used to indicate the forwarding order of forwarding operation requests to the multiple slave databases and the consecutive number corresponding to each slave database, and the consecutive number corresponding to each slave database is proportional to the operation performance of each slave database;

[0012] When the initial consecutive number has reached the consecutive number corresponding to the initial slave database, determining the next slave database of the initial slave database in the forwarding sequence as the target slave database;

[0013] When the initial consecutive number does not reach the consecutive number corresponding to the initial slave database, determining the initial slave database as the target slave database;

[0014] The operation request to be forwarded is forwarded to the target slave database.

[0015] Optionally, before forwarding the operation request to be forwarded to a target slave database among multiple slave databases according to a preset weight rule, the method further includes:

[0016] Configuring a preset polling mechanism, wherein the preset polling mechanism is used to indicate a forwarding order of forwarding operation requests to the multiple slave databases;

[0017] Obtaining the operation performance of each slave database;

[0018] Determine the number of consecutive times corresponding to each slave database according to the operation performance, wherein the number of consecutive times is used to indicate the number of operation requests that can be processed simultaneously or continuously to each slave database;

[0019] The continuous number is recorded in the preset polling mechanism to obtain the preset weight rule.

[0020] Optionally, before determining the operation type of the operation request to be forwarded, the method further includes:

[0021] Acquire indication information from the operation request to be forwarded, wherein the indication information is used to indicate a database specified by the operation request to be forwarded;

[0022] When the indication information is obtained, forwarding the operation request to be forwarded to a database specified by the operation request to be forwarded;

[0023] When the indication information is not obtained, a step of determining the operation type of the operation request to be forwarded is performed.

[0024] Optionally, before obtaining the indication information from the operation request to be forwarded, the method further includes:

[0025] Determine the transaction type of the transaction corresponding to the operation request to be forwarded;

[0026] When the transaction type is an explicit transaction, forwarding the operation request to be forwarded to the primary database;

[0027] When the transaction type is a non-explicit transaction, a step of acquiring indication information from the operation request to be forwarded is performed.

[0028] Optionally, determining, according to the operation type, a target database for processing the operation request to be forwarded includes:

[0029] When the operation type is a write request, determining that the target database is a primary database;

[0030] When the operation type is a read request, the target database is determined to be a slave database.

[0031] Optionally, after determining that the target database is the primary database, the method further includes:

[0032] The operation request to be forwarded is forwarded to the primary database, wherein the operation request to be forwarded is used to request the primary database to perform a write operation.

[0033] According to another aspect of an embodiment of the present application, a device for forwarding an operation request is further provided, including:

[0034] A first determination module, used to determine the operation type of the operation request to be forwarded;

[0035] A second determination module, configured to determine, according to the operation type, a target database for processing the operation request to be forwarded;

[0036] The first forwarding module is used to forward the operation request to be forwarded to a target slave database among multiple slave databases according to a preset weight rule when the target database is a slave database, wherein the preset weight rule is set according to the operation performance of each slave database among the multiple slave databases.

[0037] According to another aspect of an embodiment of the present application, a storage medium is further provided, which includes a stored program, and the above method is executed when the program is run.

[0038] According to another aspect of an embodiment of the present application, an electronic device is further provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the above method through the computer program.

[0039] In an embodiment of the present application, the operation type of the operation request to be forwarded is determined; the target database for processing the operation request to be forwarded is determined according to the operation type; when the target database is a slave database, the operation request to be forwarded is forwarded to a target slave database in a plurality of slave databases according to a preset weight rule, wherein the preset weight rule is set according to the operation performance of each slave database in the plurality of slave databases, and the preset weight rule is determined according to the operation performance of the slave database, so that when the operation request is forwarded from the slave database, it is forwarded according to the preset weight rule. Since the preset weight rule is determined according to the operation performance of each slave database, the operation performance of the slave database can be used as a basis when polling and forwarding the operation request in the plurality of slave databases, so that the resources provided by each slave database can match its load, and the purpose of forwarding the operation request to the slave database according to the operation performance of the slave database is achieved, so that the operation request processed by the slave database matches its operation performance, thereby achieving the technical effect of improving the processing efficiency of the operation request, and further solving the technical problem of low processing efficiency of the operation request. BRIEF DESCRIPTION OF THE DRAWINGS

[0040] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the invention and, together with the description, serve to explain the principles of the invention.

[0041] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.

[0042] Figure 1 is a schematic diagram of a hardware environment of a method for forwarding an operation request according to an embodiment of the present application;

[0043] Figure 2 is a flowchart of an optional method for forwarding an operation request according to an embodiment of the present application;

[0044] Figure 3 is a schematic diagram of a process of forwarding an operation request according to an optional implementation mode of the present application;

[0045] Figure 4 is a schematic diagram of an optional operation request forwarding device according to an embodiment of the present application;

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

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

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

[0049] According to one aspect of an embodiment of the present application, a method embodiment of forwarding an operation request is provided.

[0050] Optionally, in this embodiment, the method for forwarding the operation request can be applied to: Figure 1 The hardware environment shown in FIG. 1 is composed of a terminal 101, a middleware server 103, a plurality of slave database servers (105-1 to 105-n) and a master database server 107. Figure 1 As shown, the middleware server 103 is connected to the terminal 101, multiple slave database servers (105-1 to 105-n) and the main database server 107 through the network, and the middleware server 103 can be used to provide services (such as operation request forwarding, etc.) for the terminal 101 or the client installed on the terminal, and multiple slave database servers (105-1 to 105-n) and the main database server 107 are used to provide data storage, query and other services for the terminal 101. The above network includes but is not limited to: a wide area network, a metropolitan area network or a local area network, and the terminal 101 is not limited to a PC, a mobile phone, a tablet computer, etc. The forwarding method of the operation request in the embodiment of the present application can be executed by the middleware server 103.

[0051] Figure 2 is a flowchart of an optional method for forwarding an operation request according to an embodiment of the present application, such as Figure 2 As shown, the method may include the following steps:

[0052] Step S202, determining the operation type of the operation request to be forwarded;

[0053] Step S204, determining a target database for processing the operation request to be forwarded according to the operation type;

[0054] Step S206, when the target database is a slave database, forward the operation request to be forwarded to a target slave database among multiple slave databases according to a preset weight rule, wherein the preset weight rule is set according to the operation performance of each slave database among the multiple slave databases.

[0055] Through the above steps S202 to S206, a preset weight rule is determined according to the operating performance of the slave database, and the preset weight rule is used to forward the operation request from the slave database. Since the preset weight rule is determined according to the operating performance of each slave database, the operating performance of the slave database can be used as a basis when polling and forwarding operation requests from multiple slave databases, so that the resources provided by each slave database can match its load, thereby achieving the purpose of forwarding operation requests to the slave database according to the operating performance of the slave database, so that the operation requests processed by the slave database are matched with its operating performance, thereby achieving the technical effect of improving the processing efficiency of operation requests, and then solving the technical problem of low processing efficiency of operation requests.

[0056] Optionally, in this embodiment, the method for forwarding the operation request may be, but is not limited to, applied to a middleware deployed between an application and a database, where the middleware is connected to the application and the database and is used to forward the received operation request.

[0057] In the technical solution provided in step S202, the operation type may include but is not limited to write requests (such as operations such as adding, deleting, and modifying) and read requests (such as query operations).

[0058] Optionally, in this embodiment, the operation request to be forwarded may include, but is not limited to, SQL statements (Structured Query Language) and the like.

[0059] In the technical solution provided in step S204, the target database may include, but is not limited to, a master database, a slave database, etc. The master database stores the latest version of data and copies the data to the slave database.

[0060] In the technical solution provided in step S206, the number of slave databases corresponding to the master database may be but is not limited to multiple. If the database type of the database that processes the operation request to be forwarded is a slave database, the operation request to be forwarded can be forwarded to one of the multiple slave databases for processing.

[0061] Optionally, in this embodiment, the maximum number of queries that can be processed per second TPS (Transactions PerSecond, the number of transactions processed per second), the number of concurrency, the response time, etc. can represent the operational performance of the database, but are not limited to the use of the above indicators. The operational performance of the slave database can also be defined by comprehensively considering the above indicators. The stronger the operational performance of the slave database, the larger the performance weight can be set for the slave database so that it can carry more load.

[0062] Optionally, in this embodiment, the preset weight rule is set according to the operation performance of each slave database in the multiple slave databases. That is, when forwarding operation requests in the multiple slave databases, the operation requests are allocated according to the operation performance of each slave database, so that the operation requests allocated to each slave database match its processing capacity.

[0063] As an optional embodiment, forwarding the operation request to be forwarded to a target slave database among multiple slave databases according to the preset weight rule includes:

[0064] S11, determining an initial slave database that receives a previous operation request, and an initial consecutive number corresponding to the initial slave database, wherein the initial consecutive number is the number of operation requests that the initial slave database has continuously received;

[0065] S12, determining whether the initial consecutive number reaches the consecutive number corresponding to the initial slave database, wherein the preset weight rule is used to indicate the forwarding order of forwarding operation requests to the multiple slave databases and the consecutive number corresponding to each slave database, and the consecutive number corresponding to each slave database is proportional to the operation performance of each slave database;

[0066] S13, when the initial consecutive number has reached the consecutive number corresponding to the initial slave database, determining the next slave database of the initial slave database in the forwarding sequence as the target slave database;

[0067] S14, when the initial consecutive number does not reach the consecutive number corresponding to the initial slave database, determining the initial slave database as the target slave database;

[0068] S15, forwarding the operation request to be forwarded to the target from the database.

[0069] Optionally, in this embodiment, the preset weight rule is used to indicate the forwarding order of forwarding operation requests to multiple slave databases and the consecutive number of times corresponding to each slave database. A performance weight can be set for each slave database according to the operating performance of each slave database. The larger the value of the performance weight, the stronger the operating performance of the slave database. The consecutive number of times corresponding to each slave database can be determined according to the performance weight corresponding to each slave database. The larger the performance weight, the larger the set consecutive number.

[0070] Optionally, in this embodiment, a preset weight rule indicates the forwarding order of forwarding operation requests to multiple slave databases, the operation requests are forwarded according to the forwarding order, and each slave database corresponds to a consecutive number of times, which can be used to indicate the number of loads that each slave database can process continuously or simultaneously.

[0071] Optionally, in this embodiment, according to the number of operation requests that the initial slave database has continuously received and the number of consecutive times corresponding to the initial slave database, it can be determined whether the slave database that forwards the operation request this time is the initial slave database that receives the previous operation request, or the slave database that is next to the initial slave database in the forwarding order. For example, if the number of consecutive times corresponding to the initial slave database is 4 times, if the previous operation request received is the operation request forwarded to the initial slave database for the 1st time, or the 2nd time, or the 3rd time, it is determined that the initial consecutive times have not reached the number of consecutive times corresponding to the initial slave database, and if the previous operation request received is the operation request forwarded to the initial slave database for the 4th time, it is determined that the initial consecutive times have reached the number of consecutive times corresponding to the initial slave database.

[0072] Optionally, in this embodiment, if the initial consecutive number has reached the consecutive number corresponding to the initial slave database, it can be determined that the current load of the initial slave database has reached the limit of the resources it can provide, and the operation request to be forwarded can be forwarded to the next slave database arranged after the initial slave database for processing. If the initial consecutive number does not reach the consecutive number corresponding to the initial slave database, it can be determined that the initial slave database can continue to process the operation request, and the operation request to be forwarded can continue to be forwarded to the initial slave database for processing.

[0073] In an optional implementation, a process for forwarding an operation request is provided. Figure 3 is a schematic diagram of a process of forwarding an operation request according to an optional implementation mode of the present application, such as Figure 3As shown, Master is the main database of the application system, Slave0 and Slave1 are two slave databases of the application system respectively, and connection pools corresponding to each database (Master connection pool, Slave0 connection pool and Slave1 connection pool) can be configured on the middleware to create and manage connections with each database respectively. When the database type of the operation request to be processed and forwarded is a slave database, the performance weight of Slave0 can be set to 1 and the performance weight of Slave1 can be set to 2 according to the operation performance of the slave database. The preset weight rule can be {S0, S1, S1}. When forwarding the operation request to be forwarded to the slave database according to the preset weight rule, it is first determined that the initial slave database receiving the previous operation request is Sla0 and the initial consecutive number corresponding to Slave0 is 1. The initial consecutive number has reached the consecutive number 1 corresponding to Slave0, then the next slave database Slave1 of Slave0 in the forwarding order is determined as the target slave database to forward the current operation request. That is, after forwarding an operation request to the slave database Slave0 once, the operation request is forwarded to the slave database Slave1 twice in succession, and then the operation request is forwarded to the slave database Slave0 once, and then the operation request is forwarded to the slave database Slave1 twice in succession, and so on.

[0074] As an optional embodiment, before forwarding the operation request to be forwarded to a target slave database among multiple slave databases according to a preset weight rule, the method further includes:

[0075] S21, configuring a preset polling mechanism, wherein the preset polling mechanism is used to indicate a forwarding order of forwarding operation requests to the multiple slave databases;

[0076] S22, obtaining the operation performance of each slave database;

[0077] S23, determining the number of consecutive times corresponding to each slave database according to the operation performance, wherein the number of consecutive times is used to indicate the number of operation requests that each slave database can process simultaneously or continuously;

[0078] S24, recording the consecutive times into the preset polling mechanism to obtain the preset weight rule.

[0079] Optionally, in this embodiment, the preset polling mechanism may be but is not limited to a round-robin mechanism, for example: setting the forwarding order of multiple slave databases. Taking three slave databases (S1, S2, S3) as an example, the preset polling mechanism may be S1, S2, S3, or S2, S1, S3, or S3, S2, S1, and so on.

[0080] Optionally, in this embodiment, the target polling order is determined based on a preset polling mechanism and a performance weight corresponding to each of a plurality of slave databases. For example, the preset polling mechanism may be S1, S2, and S3, wherein the performance weight corresponding to S1 is used to indicate that the operating performance of S1 is the strongest among the three slave databases, the performance weight corresponding to S2 is used to indicate that the operating performance of S2 is the weakest among the three slave databases, and the performance weight corresponding to S3 is used to indicate that the operating performance of S3 is medium among the three slave databases. Then, the target polling order may be set based on the order of S1, S2, and S3, and more operation requests may be allocated to S1, fewer operation requests may be allocated to S2, and a medium number of operation requests may be allocated to S3.

[0081] Optionally, in this embodiment, the operation performance is proportional to the number of consecutive times, that is, the stronger the operation performance of the slave database is, the higher the number of consecutive times can be set for it.

[0082] Optionally, in this embodiment, the recording method of the preset weight rules can be, but not limited to, a list method, and can also be, but not limited to, an ordered key-value pair method. For example: taking the above three slave databases, the preset polling mechanism is S1, S2, and S3 as an example, the preset weight rules recorded in the list method can be expressed as S1, S1, S1, S1, S2, S3, S3. It can be seen that S1 has the strongest operating performance, and the performance weight that can be set for it is 4, indicating the number of consecutive forwarding operation requests for it. S2 has the weakest operating performance, and the performance weight that can be set for it is 1, indicating the number of consecutive forwarding operation requests for it. S3 has medium operating performance, and the performance weight that can be set for it is 2, indicating the number of consecutive forwarding operation requests for it. The ordered key-value pair method can be expressed as S1-4, S2-1, and S3-2, that is, the preset weight rules can be recorded with the identifier of the slave database as the key and the number of consecutive times as the value.

[0083] In the above optional implementation, if Figure 3 As shown, the preset polling mechanism can be set to S0, S1. The consecutive number of times corresponding to S0 is determined to be 1 according to the operating performance of S0, and the consecutive number of times corresponding to S1 is determined to be 2 according to the operating performance of S1. The preset weight rule can be but is not limited to being expressed as S0, S1, S1.

[0084] As an optional embodiment, before determining the operation type of the operation request to be forwarded, the method further includes:

[0085] S31, acquiring indication information from the operation request to be forwarded, wherein the indication information is used to indicate a database specified by the operation request to be forwarded;

[0086] S32, when the indication information is obtained, forwarding the operation request to be forwarded to a database specified by the operation request to be forwarded;

[0087] S33, when the indication information is not obtained, executing the step of determining the operation type of the operation request to be forwarded.

[0088] Optionally, in this embodiment, the identifier of the forwarding node can be carried as indication information in the operation request to be forwarded by means of a hint, but is not limited to the hint. The indication information can specify a database to process the operation request. For example, if the operation request to be forwarded is a request for a read operation, but the indication information it carries indicates that it is designated as the primary database, then the read operation request is forwarded to the primary database for processing.

[0089] Optionally, in this embodiment, for an operation request to be forwarded that does not carry indication information, a step of determining an operation type of the operation request to be forwarded is performed, and the operation request is forwarded according to the operation type.

[0090] Through the above steps, the operation request can be used to specify the database to process it. For example, a read operation request that needs to obtain the latest version of data can be forwarded to the primary database for processing by specifying the primary database, thereby achieving the purpose of forwarding the operation request to be forwarded carrying the indication information to the specified database, thereby realizing the directional read and write operations on the database.

[0091] As an optional embodiment, before obtaining the indication information from the operation request to be forwarded, the method further includes:

[0092] S41, determining the transaction type of the transaction corresponding to the operation request to be forwarded;

[0093] S42, when the transaction type is an explicit transaction, forwarding the operation request to be forwarded to the primary database;

[0094] S43, when the transaction type is a non-explicit transaction, executing the step of obtaining indication information from the operation request to be forwarded.

[0095] Optionally, in this embodiment, the transaction type may include, but is not limited to, explicit transactions, non-explicit transactions, and the like. An explicit transaction is a transaction in which the start and end of a transaction can be explicitly defined, and transactions other than explicit transactions may be referred to as non-explicit transactions. For example, non-explicit transactions may include, but are not limited to, implicit transactions, and the like.

[0096] Optionally, in this embodiment, the operation request can be forwarded according to the transaction type of the transaction to which the operation request corresponds. For explicit transactions, due to the attribute characteristics of this type of transaction, it requires the latest version of data in the operation database, so the operation requests corresponding to this type of transaction can be forwarded to the main database for processing to meet the data requirements of the explicit transaction. For non-explicit transactions, the step of obtaining indication information from the operation request to be forwarded can be performed.

[0097] Through the above steps, all operation requests to be forwarded for explicit transactions are forwarded to the primary database, thereby ensuring the data requirements of explicit transactions.

[0098] As an optional embodiment, determining, according to the operation type, a target database for processing the operation request to be forwarded includes:

[0099] S51, when the operation type is a write request, determining that the target database is a primary database;

[0100] S52: When the operation type is a read request, determine that the target database is a slave database.

[0101] Optionally, in this embodiment, the write request may include, but is not limited to, requests for an add operation (INSERT), an update operation (UPDATE), a delete operation (DELETE), and the like.

[0102] Optionally, in this embodiment, the read request may include, but is not limited to, a request for a query operation (SELECT) or the like.

[0103] Through the above steps, the type of database for processing the operation request to be forwarded is determined according to the operation type of the operation request to be forwarded, thereby realizing the read-write separation of the database and improving the processing efficiency and stability of the database.

[0104] Optionally, in this embodiment, after determining that the target database is the primary database, the operation request to be forwarded is forwarded to the primary database, wherein the operation request to be forwarded is used to request the primary database to perform a write operation.

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

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

[0107] According to another aspect of an embodiment of the present application, a device for forwarding an operation request for implementing the above-mentioned method for forwarding an operation request is also provided. Figure 4 is a schematic diagram of an optional operation request forwarding device according to an embodiment of the present application, such as Figure 4 As shown, the device may include:

[0108] A first determination module 42, configured to determine an operation type of the operation request to be forwarded;

[0109] A second determination module 44, configured to determine a target database for processing the operation request to be forwarded according to the operation type;

[0110] The first forwarding module 46 is used to forward the operation request to be forwarded to a target slave database among multiple slave databases according to a preset weight rule when the target database is a slave database, wherein the preset weight rule is set according to the operation performance of each slave database among the multiple slave databases.

[0111] It should be noted that the first determination module 42 in this embodiment can be used to execute step S202 in the embodiment of the present application, the second determination module 44 in this embodiment can be used to execute step S204 in the embodiment of the present application, and the first forwarding module 46 in this embodiment can be used to execute step S206 in the embodiment of the present application.

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

[0113] Through the above-mentioned module, a preset weight rule is determined according to the operating performance of the slave database, and the preset weight rule is used to forward the operation request from the slave database. Since the preset weight rule is determined according to the operating performance of each slave database, the operating performance of the slave database can be used as a basis when polling and forwarding operation requests from multiple slave databases, so that the resources provided by each slave database can match its load, thereby achieving the purpose of forwarding operation requests to the slave database according to the operating performance of the slave database, so that the operation requests processed by the slave database are matched with its operating performance, thereby achieving the technical effect of improving the processing efficiency of operation requests, and then solving the technical problem of low processing efficiency of operation requests.

[0114] As an optional embodiment, the first forwarding module includes:

[0115] A first determining unit, configured to determine an initial slave database that receives a previous operation request, and an initial consecutive number of times corresponding to the initial slave database, wherein the initial consecutive number of times is the number of operation requests that the initial slave database has continuously received;

[0116] A second determining unit is used to determine whether the initial consecutive number reaches the consecutive number corresponding to the initial slave database, wherein the preset weight rule is used to indicate the forwarding order of forwarding operation requests to the multiple slave databases and the consecutive number corresponding to each slave database, and the consecutive number corresponding to each slave database is proportional to the operation performance of each slave database;

[0117] A third determining unit is configured to determine the next slave database of the initial slave database in the forwarding sequence as the target slave database when the initial consecutive number has reached the consecutive number corresponding to the initial slave database;

[0118] A fourth determining unit, configured to determine the initial slave database as the target slave database when the initial consecutive number does not reach the consecutive number corresponding to the initial slave database;

[0119] A forwarding unit is used to forward the operation request to be forwarded to the target slave database.

[0120] As an optional embodiment, the device further includes:

[0121] A configuration module, used for configuring a preset polling mechanism before forwarding the operation request to be forwarded to a target slave database among multiple slave databases according to a preset weight rule, wherein the preset polling mechanism is used to indicate a forwarding order of forwarding the operation request to the multiple slave databases;

[0122] A first acquisition module, used to acquire the operation performance of each slave database;

[0123] A third determining module is used to determine the number of consecutive times corresponding to each slave database according to the operation performance, wherein the number of consecutive times is used to indicate the number of operation requests that each slave database can process simultaneously or continuously;

[0124] The recording module is used to record the continuous times into the preset polling mechanism to obtain the preset weight rule.

[0125] As an optional embodiment, the device further includes:

[0126] A second acquisition module, configured to acquire indication information from the operation request to be forwarded before determining the operation type of the operation request to be forwarded, wherein the indication information is used to indicate a database specified by the operation request to be forwarded;

[0127] A second forwarding module, configured to forward the operation request to be forwarded to a database specified by the operation request to be forwarded when the indication information is acquired;

[0128] The first execution module is used to execute the step of determining the operation type of the operation request to be forwarded when the indication information is not obtained.

[0129] As an optional embodiment, the device further includes:

[0130] A fourth determination module, configured to determine a transaction type of a transaction corresponding to the operation request to be forwarded before obtaining indication information from the operation request to be forwarded;

[0131] A third forwarding module, configured to forward the operation request to be forwarded to a primary database when the transaction type is an explicit transaction;

[0132] The second execution module is used to execute the step of obtaining indication information from the operation request to be forwarded when the transaction type is a non-explicit transaction.

[0133] As an optional embodiment, the second determining module includes:

[0134] A fifth determining unit, configured to determine, when the operation type is a write request, that the target database is a primary database;

[0135] A sixth determining unit is configured to determine, when the operation type is a read request, that the target database is a slave database.

[0136] As an optional embodiment, the device further includes:

[0137] A fourth forwarding module is used to forward the operation request to be forwarded to the primary database after determining that the target database is the primary database, wherein the operation request to be forwarded is used to request the primary database to perform a write operation.

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

[0139] According to another aspect of an embodiment of the present application, an electronic device for implementing the above-mentioned method for forwarding an operation request is also provided.

[0140] Figure 5 is a structural block diagram of an electronic device according to an embodiment of the present application, such as Figure 5 As shown, the electronic device may include: one or more (only one is shown in the figure) processors 501, a memory 503, and a transmission device 505, such as Figure 5 As shown, the electronic device may further include an input / output device 507 .

[0141] Wherein, the memory 503 can be used to store software programs and modules, such as the forwarding method and program instructions / modules corresponding to the device of the operation request in the embodiment of the present application, and the processor 501 executes various functional applications and data processing by running the software programs and modules stored in the memory 503, that is, realizing the forwarding method of the above-mentioned operation request. The memory 503 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory or other non-volatile solid-state memory. In some instances, the memory 503 may further include a memory remotely arranged relative to the processor 501, and these remote memories may be connected to the electronic device via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network and a combination thereof.

[0142] The above-mentioned transmission device 505 is used to receive or send data via a network, and can also be used for data transmission between a processor and a memory. The above-mentioned network specific examples may include wired networks and wireless networks. In one example, the transmission device 505 includes a network adapter (Network Interface Controller, NIC), which can be connected to other network devices and routers via a network cable so as to communicate with the Internet or a local area network. In one example, the transmission device 505 is a radio frequency (Radio Frequency, RF) module, which is used to communicate with the Internet wirelessly.

[0143] Specifically, the memory 503 is used to store application programs.

[0144] The processor 501 may call the application stored in the memory 503 through the transmission device 505 to perform the following steps:

[0145] Determine the operation type of the operation request to be forwarded;

[0146] Determine, according to the operation type, a target database for processing the operation request to be forwarded;

[0147] When the target database is a slave database, the operation request to be forwarded is forwarded to a target slave database among multiple slave databases according to a preset weight rule, wherein the preset weight rule is set according to the operation performance of each slave database among the multiple slave databases.

[0148] By adopting the embodiment of the present application, a scheme for forwarding operation requests is provided. A preset weight rule is determined according to the operation performance of a slave database, and when forwarding operation requests from the slave database, the preset weight rule is used for forwarding. Since the preset weight rule is determined according to the operation performance of each slave database, the operation performance of the slave database can be used as a basis when polling and forwarding operation requests from multiple slave databases, so that the resources provided by each slave database can match its load, and the purpose of forwarding operation requests to the slave database according to the operation performance of the slave database is achieved, so that the operation requests processed by the slave database match its operation performance, thereby achieving the technical effect of improving the processing efficiency of operation requests, and then solving the technical problem of low processing efficiency of operation requests.

[0149] Optionally, the specific examples in this embodiment may refer to the examples described in the above embodiments, and this embodiment will not be described in detail here.

[0150] It can be understood by those skilled in the art that Figure 5The structure shown is for illustration only, and the electronic device may be a smart phone (such as an Android phone, an iOS phone, etc.), a tablet computer, a PDA, a mobile Internet device (MID), a PAD, or other electronic devices. Figure 5 The structure of the electronic device is not limited. Figure 5 More or fewer components (such as network interfaces, display devices, etc.) shown in, or having Figure 5 Different configurations are shown.

[0151] A person of ordinary skill in the art can understand that all or part of the steps in the various methods of the above embodiments can be completed by instructing the hardware related to the electronic device through a program, and the program can be stored in a computer-readable storage medium, and the storage medium may include: a flash drive, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, etc.

[0152] The embodiment of the present application further provides a storage medium. Optionally, in this embodiment, the storage medium can be used to execute the program code of the method for forwarding an operation request.

[0153] Optionally, in this embodiment, the storage medium may be located on at least one network device among a plurality of network devices in the network shown in the above embodiment.

[0154] Optionally, in this embodiment, the storage medium is configured to store program codes for executing the following steps:

[0155] Determine the operation type of the operation request to be forwarded;

[0156] Determine, according to the operation type, a target database for processing the operation request to be forwarded;

[0157] When the target database is a slave database, the operation request to be forwarded is forwarded to a target slave database among multiple slave databases according to a preset weight rule, wherein the preset weight rule is set according to the operation performance of each slave database among the multiple slave databases.

[0158] Optionally, the specific examples in this embodiment may refer to the examples described in the above embodiments, and this embodiment will not be described in detail here.

[0159] Optionally, in this embodiment, the above-mentioned storage medium may include but is not limited to: a USB flash drive, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk or an optical disk, and other media that can store program codes.

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

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

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

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

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

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

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

Claims

1. A method for forwarding an operation request, characterized in that: include: Determine the operation type of the operation request to be forwarded; Determine, according to the operation type, a target database for processing the operation request to be forwarded; When the target database is a slave database, forwarding the operation request to be forwarded to a target slave database among the multiple slave databases according to a preset weight rule, wherein the preset weight rule is set according to the operation performance of each slave database among the multiple slave databases; Forwarding the operation request to be forwarded to a target slave database among multiple slave databases according to the preset weight rule includes: Determine the initial slave database that receives the last operation request, and the initial consecutive number of times corresponding to the initial slave database, wherein the initial consecutive number of times is the number of operation requests that the initial slave database has continuously received; Determine whether the initial consecutive number reaches the consecutive number corresponding to the initial slave database, wherein the preset weight rule is used to indicate the forwarding order of forwarding operation requests to the multiple slave databases and the consecutive number corresponding to each slave database, and the consecutive number corresponding to each slave database is proportional to the operation performance of each slave database; When the initial consecutive number has reached the consecutive number corresponding to the initial slave database, determining the next slave database of the initial slave database in the forwarding sequence as the target slave database; When the initial consecutive number does not reach the consecutive number corresponding to the initial slave database, determining the initial slave database as the target slave database; forwarding the operation request to be forwarded from the database to the target; Before forwarding the operation request to be forwarded to a target slave database among multiple slave databases according to a preset weight rule, the method further includes: Configuring a preset polling mechanism, wherein the preset polling mechanism is used to indicate a forwarding order of forwarding operation requests to the multiple slave databases; Obtaining the operation performance of each slave database; Determine the number of consecutive times corresponding to each slave database according to the operation performance, wherein the number of consecutive times is used to indicate the number of operation requests that each slave database can process simultaneously or continuously; The continuous number is recorded in the preset polling mechanism to obtain the preset weight rule.

2. The method according to claim 1, characterized in that Before determining the operation type of the operation request to be forwarded, the method further includes: Acquire indication information from the operation request to be forwarded, wherein the indication information is used to indicate a database specified by the operation request to be forwarded; When the indication information is obtained, forwarding the operation request to be forwarded to a database specified by the operation request to be forwarded; When the indication information is not obtained, a step of determining the operation type of the operation request to be forwarded is performed.

3. The method according to claim 2, characterized in that Before obtaining the indication information from the operation request to be forwarded, the method further includes: Determine the transaction type of the transaction corresponding to the operation request to be forwarded; When the transaction type is an explicit transaction, forwarding the operation request to be forwarded to the primary database; When the transaction type is a non-explicit transaction, a step of acquiring indication information from the operation request to be forwarded is performed.

4. The method according to claim 1, characterized in that Determining, according to the operation type, a target database for processing the operation request to be forwarded includes: When the operation type is a write request, determining that the target database is a primary database; When the operation type is a read request, the target database is determined to be a slave database.

5. The method according to claim 4, characterized in that After determining that the target database is the primary database, the method further includes: The operation request to be forwarded is forwarded to the primary database, wherein the operation request to be forwarded is used to request the primary database to perform a write operation.

6. A device for forwarding an operation request, characterized in that: include: A first determination module, used to determine the operation type of the operation request to be forwarded; A second determination module, configured to determine, according to the operation type, a target database for processing the operation request to be forwarded; A first forwarding module, configured to forward the operation request to be forwarded to a target slave database among the multiple slave databases according to a preset weight rule when the target database is a slave database, wherein the preset weight rule is set according to the operation performance of each slave database among the multiple slave databases; The first forwarding module includes: A first determining unit, configured to determine an initial slave database that receives a previous operation request, and an initial consecutive number of times corresponding to the initial slave database, wherein the initial consecutive number of times is the number of operation requests that the initial slave database has continuously received; A second determining unit is used to determine whether the initial consecutive number reaches the consecutive number corresponding to the initial slave database, wherein the preset weight rule is used to indicate the forwarding order of forwarding operation requests to the multiple slave databases and the consecutive number corresponding to each slave database, and the consecutive number corresponding to each slave database is proportional to the operation performance of each slave database; A third determining unit is configured to determine the next slave database of the initial slave database in the forwarding sequence as the target slave database when the initial consecutive number has reached the consecutive number corresponding to the initial slave database; A fourth determining unit, configured to determine the initial slave database as the target slave database when the initial consecutive number does not reach the consecutive number corresponding to the initial slave database; A forwarding unit, configured to forward the operation request to be forwarded to the target from the database; The device also includes: A configuration module, used for configuring a preset polling mechanism before forwarding the operation request to be forwarded to a target slave database among multiple slave databases according to a preset weight rule, wherein the preset polling mechanism is used to indicate a forwarding order of forwarding the operation request to the multiple slave databases; A first acquisition module, used to acquire the operation performance of each slave database; A third determining module is used to determine the number of consecutive times corresponding to each slave database according to the operation performance, wherein the number of consecutive times is used to indicate the number of operation requests that each slave database can process simultaneously or continuously; The recording module is used to record the continuous times into the preset polling mechanism to obtain the preset weight rule.

7. A storage medium, characterized in that: The storage medium includes a stored program, wherein the program executes the method described in any one of claims 1 to 5 when executed.

8. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: The processor executes the method described in any one of claims 1 to 5 through the computer program.

Citation Information

Patent Citations

  • Data processing method and device for internet application

    CN104796451A

  • Read-write separation method, device, computer device and storage medium

    CN109344157A

  • Database read-write separation method and device, service system, equipment and medium

    CN109614390A

  • Web cluster cache utilization system and optimization method

    CN109634746A

  • Database read-write method and device, computer equipment and storage medium

    CN110781214A