WO2023207082A1 - Load balance method and apparatus, and electronic device - Google Patents

Load balance method and apparatus, and electronic device Download PDF

Info

Publication number
WO2023207082A1
WO2023207082A1 PCT/CN2022/135418 CN2022135418W WO2023207082A1 WO 2023207082 A1 WO2023207082 A1 WO 2023207082A1 CN 2022135418 W CN2022135418 W CN 2022135418W WO 2023207082 A1 WO2023207082 A1 WO 2023207082A1
Authority
WO
WIPO (PCT)
Prior art keywords
blockchain
transaction request
transaction
consensus
node device
Prior art date
Application number
PCT/CN2022/135418
Other languages
French (fr)
Chinese (zh)
Inventor
林鹏
邓福喜
Original Assignee
蚂蚁区块链科技(上海)有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 蚂蚁区块链科技(上海)有限公司 filed Critical 蚂蚁区块链科技(上海)有限公司
Publication of WO2023207082A1 publication Critical patent/WO2023207082A1/en

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/01Protocols
    • H04L67/10Protocols in which an application is distributed across nodes in the network
    • H04L67/1001Protocols in which an application is distributed across nodes in the network for accessing one among a plurality of replicated servers
    • H04L67/1004Server selection for load balancing
    • H04L67/1025Dynamic adaptation of the criteria on which the server selection is based

Definitions

  • One or more embodiments of this specification relate to the field of blockchain technology, and in particular, to a load balancing method and device and electronic equipment.
  • Blockchain technology also known as distributed ledger technology, is an emerging technology in which several computing devices jointly participate in "bookkeeping" and jointly maintain a complete distributed database. Because blockchain technology is decentralized, open and transparent, each computing device can participate in database records, and data can be synchronized quickly between computing devices, blockchain technology has been widely used in many fields. Apply.
  • the embodiments of this specification provide a method, device and electronic equipment for improving information security.
  • a load balancing method is provided, applied to an access program corresponding to a blockchain, and the method includes:
  • the transaction request is a transaction request related to a blockchain transaction
  • the node device participating in the consensus in the blockchain provides the transaction with Request allocation of target node equipment, and send the transaction request to the allocated target node equipment for processing; wherein, different types of consensus algorithms supported by the blockchain respectively correspond to different load balancing strategies.
  • the method also includes:
  • the transaction request is a transaction request that is not related to the blockchain transaction, based on the preset load balancing strategy, allocate the node device with the optimal load to the transaction request from the node devices that do not participate in the consensus in the blockchain. , and send the transaction request to the node device for processing.
  • the consensus algorithm supported by the blockchain includes an asynchronous consensus algorithm;
  • the transaction requests related to blockchain transactions include blockchain transactions and query requests for blockchain transactions;
  • the method of allocating a target node device to the transaction request from the node devices participating in the consensus in the blockchain based on the load balancing strategy corresponding to the consensus algorithm supported by the blockchain includes:
  • the transaction request is a blockchain transaction, based on the load balancing strategy corresponding to the asynchronous consensus algorithm, the target of allocating the optimal load to the blockchain transaction from the node devices participating in the consensus in the blockchain Node equipment, and establish a binding relationship between the blockchain transaction and the target node equipment;
  • the transaction request is a query request corresponding to a blockchain transaction
  • the binding relationship is queried, and the target node device bound to the blockchain transaction is assigned to the query request.
  • the consensus algorithm supported by the blockchain also includes a synchronous consensus algorithm
  • the method of allocating a target node device to the transaction request from the node devices participating in the consensus in the blockchain based on the load balancing strategy corresponding to the consensus algorithm supported by the blockchain includes:
  • the target node device with the optimal load is allocated to the transaction request from the node devices participating in the consensus in the blockchain.
  • the optimally loaded node device includes a randomly designated node device.
  • the synchronous consensus algorithm includes the pbft consensus algorithm; the asynchronous consensus algorithm includes the honeybadger consensus algorithm.
  • the access program includes an SDK program for accessing the blockchain.
  • the SDK program includes an SDK access program installed on the user client;
  • the reception of transaction requests submitted by users includes:
  • the SDK program includes an SDK access service program corresponding to the user client mounted on the blockchain service platform;
  • the reception of transaction requests submitted by users includes:
  • the access program maintains a first connection pool based on connections with each node device that participates in consensus in the blockchain; and, based on connections with nodes that do not participate in consensus in the blockchain A second connection pool composed of connections between various node devices;
  • Allocating a target node device to the transaction request from the node devices participating in the consensus in the blockchain, and sending the transaction request to the assigned target node device for processing including:
  • Allocating the node device with the optimal load to the transaction request from the node devices that do not participate in the consensus in the blockchain, and sending the transaction request to the node device for processing includes:
  • the method also includes:
  • Timing detection determines whether the connections in the first connection pool and the second connection pool are available, and based on the detection results, adds an indication that the connection is available to the connections in the first connection pool and the second connection pool. available tags;
  • Allocating a target connection for the transaction request from the first connection pool includes:
  • Allocating a target connection for the transaction request from the second connection pool includes:
  • the timing to determine whether connections in the first connection pool and the second connection pool are available includes:
  • the preset timestamp range includes a timestamp range corresponding to a specified block in the blockchain.
  • a load balancing device which is applied to the access program corresponding to the blockchain.
  • the device includes:
  • the receiving unit receives transaction requests submitted by users
  • a determining unit that determines the type of the transaction request in response to the received transaction request submitted by the user
  • a balancing unit when the transaction request is a transaction request related to a blockchain transaction, based on the load balancing strategy corresponding to the consensus algorithm supported by the blockchain, from the node devices participating in the consensus in the blockchain Allocate a target node device to the transaction request, and send the transaction request to the assigned target node device for processing; wherein, the different types of consensus algorithms supported by the blockchain respectively correspond to different load balancing strategies. .
  • the balancing unit is also configured to remove node devices that do not participate in the consensus from the blockchain based on a preset load balancing strategy when the transaction request is a transaction request that is not related to a blockchain transaction. Allocate the node device with the optimal load to the transaction request, and send the transaction request to the node device for processing.
  • the consensus algorithm supported by the blockchain includes an asynchronous consensus algorithm;
  • the transaction requests related to blockchain transactions include blockchain transactions and query requests for blockchain transactions;
  • the balancing unit is also configured to, when the transaction request is a blockchain transaction, based on the load balancing strategy corresponding to the asynchronous consensus algorithm, from the node devices participating in the consensus in the blockchain, provide the balance for the zone.
  • the block chain transaction allocates the target node device with the optimal load, and establishes a binding relationship between the block chain transaction and the target node device; and, when the transaction request is a query request corresponding to the block chain transaction, based on The load balancing strategy corresponding to the asynchronous consensus algorithm queries the binding relationship, and allocates the target node device bound to the blockchain transaction to the query request.
  • the consensus algorithm supported by the blockchain also includes a synchronous consensus algorithm
  • the balancing unit is also configured to allocate the target node device with the optimal load to the transaction request from the node devices participating in the consensus in the blockchain based on the load balancing strategy corresponding to the synchronous consensus algorithm.
  • the optimally loaded node device includes a randomly designated node device.
  • the synchronous consensus algorithm includes the pbft consensus algorithm; the asynchronous consensus algorithm includes the honeybadger consensus algorithm.
  • the access program includes an SDK program for accessing the blockchain.
  • the SDK program includes an SDK access program installed on the user client;
  • the receiving unit is also used to obtain the transaction request initiated by the user on the user client.
  • the SDK program includes an SDK access service program corresponding to the user client mounted on the blockchain service platform;
  • the receiving unit is also configured to receive a transaction request submitted by the user client by calling the service interface deployed on the blockchain service platform and corresponding to the SDK access service program.
  • the access program maintains a first connection pool based on connections with each node device that participates in consensus in the blockchain; and, based on connections with nodes that do not participate in consensus in the blockchain A second connection pool composed of connections between various node devices;
  • the balancing unit allocates a target node device for the transaction request from the node devices participating in the consensus in the blockchain, and sends the transaction request to the assigned target node device for processing, including:
  • the balancing unit allocates the node device with the optimal load for the transaction request from the node devices in the blockchain that do not participate in the consensus, and sends the transaction request to the node device for processing, including:
  • the device also includes:
  • a detection unit that periodically detects and determines whether the connections in the first connection pool and the second connection pool are available, and adds the indication to the connections in the first connection pool and the second connection pool based on the detection results. Connect to available tags available;
  • the balancing unit allocates a target connection for the transaction request from the first connection pool, including:
  • the balancing unit allocates a target connection for the transaction request from the second connection pool, including:
  • the detection unit is also configured to regularly send an asynchronous query request to the node device corresponding to the connection in the first connection pool and the second connection pool; if the request is received within the preset timestamp range, If the response data returned by the node device is received, it is determined that the connection is available; if the response data returned by the node device is not received within the preset timestamp range, the connection is determined to be unavailable.
  • the preset timestamp range includes a timestamp range corresponding to a specified block in the blockchain.
  • an electronic device including:
  • Memory used to store instructions executable by the processor
  • the processor is configured for any one of the above load balancing methods.
  • the embodiment of this specification provides a load balancing solution that sets different load balancing strategies for different types of consensus algorithms supported by the blockchain to adapt to the load differences caused by different types of consensus algorithms; in this way, for users
  • the submitted transaction request related to the blockchain transaction can be assigned a target from the node devices participating in the consensus in the blockchain according to the load balancing strategy corresponding to the consensus algorithm for the transaction request. node device for processing. Since the load balancing strategy takes into account the load difference of the consensus algorithm, the allocated target node device is the current optimal node device. Based on the target node device, the transaction request can be quickly responded to, thereby avoiding the problem of slow response caused by excessive load on some node devices. .
  • Figure 1 is a flow chart of a load balancing method provided by an exemplary embodiment
  • Figure 2 is a system architecture diagram of load balancing provided by an exemplary embodiment
  • Figure 3 is a schematic structural diagram of an electronic device provided by an exemplary embodiment
  • Figure 4 is a block diagram of a load balancing device provided by an exemplary embodiment.
  • the steps of the corresponding method are not necessarily performed in the order shown and described in this specification.
  • methods may include more or fewer steps than described in this specification.
  • a single step described in this specification may be broken down into multiple steps for description in other embodiments; and multiple steps described in this specification may also be combined into a single step in other embodiments. describe.
  • this manual provides a load balancing solution specifically suitable for blockchain scenarios, which can efficiently allocate transaction requests, enable node devices in the blockchain to process transaction requests in a balanced manner, and solve the load of each node device. Problem of imbalance.
  • Figure 1 is a flow chart of a load balancing method provided by an exemplary embodiment.
  • the method can be applied to the access program corresponding to the blockchain; the method can include the following steps:
  • Step 110 Receive the transaction request submitted by the user
  • Step 120 In response to the received transaction request submitted by the user, determine the type of the transaction request;
  • Step 130 If the transaction request is a transaction request related to a blockchain transaction, based on the load balancing strategy corresponding to the consensus algorithm supported by the blockchain, from the node devices participating in the consensus in the blockchain, The transaction request is assigned to a target node device, and the transaction request is sent to the assigned target node device for processing; wherein, different types of consensus algorithms supported by the blockchain respectively correspond to different load balancing strategies.
  • the blockchain described in this manual can specifically include any type of blockchain network; in practical applications, any one of public blockchain, private blockchain and consortium blockchain can be used. kind. In addition, there can also be a combination of the above types, such as private chain + alliance chain, alliance chain + public chain, etc.
  • the public chain is the most decentralized. Participants who join the public chain (also called node devices in the blockchain) can read data records on the chain, participate in transactions, and compete for the accounting rights of new blocks, etc. Moreover, each node device can freely join or exit the network and perform related operations.
  • the private chain has the writing permission of the network controlled by an organization or institution, and the data reading permission is regulated by the organization.
  • a private chain can be a weakly centralized system with strict restrictions on node equipment and a small number of node equipment. This type of blockchain is more suitable for internal use within specific organizations.
  • the alliance chain is a blockchain between the public chain and the private chain, which can achieve "partial decentralization".
  • Each node device in the alliance chain usually has a corresponding entity or organization; the node device joins the network through authorization and forms an alliance of stakeholders to jointly maintain the operation of the blockchain.
  • FIG. 2 is a load balancing system architecture diagram described in this manual.
  • the load balancing system may include a user client, an access program and a blockchain.
  • the above-mentioned user client (such as an APP application) can provide users with a service portal of the blockchain. Users can submit transaction requests to the access program through the service portal shown above, and the access program will transfer all transactions based on the load balancing strategy. The transaction request is sent to the target node device with the optimal load in the blockchain, so that the target node device processes the transaction request.
  • the above-mentioned access program may refer to the intermediate system between the blockchain and the user client, which does not belong to the blockchain.
  • the access program can maintain a connection pool that connects each user client to each node device in the blockchain. That is, the access program maintains a corresponding connection pool for each user client.
  • the above-mentioned access program may specifically include an SDK (Software Development Kit) program for accessing the blockchain.
  • SDK Software Development Kit
  • the load balancing implementation code provided in this manual can be integrated into the SDK program to achieve the load balancing goal of the blockchain based on the SDK program.
  • the SDK program may include an SDK access program installed on the user client;
  • the above step 110 may include obtaining the transaction request initiated by the user on the user client.
  • the SDK program includes an SDK access service program corresponding to the user client mounted on the blockchain service platform;
  • the above step 110 may include receiving a transaction request submitted by the user client by calling a service interface deployed on the blockchain service platform corresponding to the SDK access service program.
  • any transaction request submitted by a user client will first be sent to the access program; then the access program will confirm an optimal load target node device from the connection pool corresponding to the user client; then the access program will The entry program sends the transaction request to the target node device in the blockchain; finally, the target node device in the blockchain responds and processes the transaction request submitted by the user client.
  • the access program performs load balancing in advance before submitting transaction requests to the blockchain, so that the target node equipment responsible for processing the transaction request is optimal each time.
  • Loaded node equipment in this way, it avoids the problem of load imbalance such that some node equipment is overloaded but has to process more transaction requests, while some node equipment is underloaded but has no transaction requests to process.
  • the processing capabilities of node devices that are originally idle and have no transaction requests can be reasonably utilized, thereby improving the overall processing efficiency of the blockchain and reducing the response time of blockchain processing requests.
  • a transaction request for the blockchain may refer to a request produced in a standard transaction format supported by the blockchain, and the request contains the data required for the business to be performed by the blockchain.
  • any real data generated in the physical world can be constructed into a standard transaction format supported by the blockchain, and then published to the blockchain and received by the node pairs in the blockchain.
  • the transaction is processed, and the node in the blockchain, which is the accounting node, packages the transaction into a block and makes a persistent certificate in the blockchain.
  • transaction requests can be divided into transaction requests related to blockchain transactions and transaction requests unrelated to blockchain transactions.
  • the transaction request requires consensus before execution. That is, after receiving the transaction request, the node device participating in the consensus in the blockchain first needs to perform consensus processing on the transaction request. After the consensus is passed, the transaction request will be processed.
  • the block The node in the chain which serves as the accounting node, packages the transaction into a block and stores it permanently in the blockchain. Transaction requests do not require consensus before execution.
  • the aforementioned step 230 can be performed. That is, if the transaction request is a transaction request related to a blockchain transaction, based on the consensus algorithm corresponding to the blockchain support
  • the load balancing strategy is to allocate target node equipment for the transaction request from the node equipment participating in the consensus in the blockchain, and send the transaction request to the allocated target node equipment for processing; wherein, the zone
  • the different types of consensus algorithms supported by the blockchain correspond to different load balancing strategies.
  • step 240 can be performed:
  • the transaction request is a transaction request that is not related to the blockchain transaction, based on the preset load balancing strategy, allocate the node device with the optimal load to the transaction request from the node devices that do not participate in the consensus in the blockchain. , and send the transaction request to the node device for processing.
  • the node device that does not participate in consensus may be a light node.
  • Light nodes do not store blockchain ledgers locally, so transaction requests related to blockchain transactions cannot be sent to such node devices for processing.
  • this manual also provides different load balancing strategies for different consensus algorithms to further improve the performance and efficiency of load balancing.
  • publishing a transaction is divided into two steps.
  • the first step is to publish the transaction request to the blockchain.
  • the second step is to query the blockchain based on the transaction hash to execute the transaction execution result generated after the first step of the transaction request. .
  • For the blockchain it will first receive the transaction request and then the transaction query, so the transaction request and transaction execution result need to be combined into a response result and returned to the user client.
  • the transaction request related to the blockchain transaction includes a blockchain transaction and a query request for the blockchain transaction;
  • the target node device is allocated to the transaction request from the node devices participating in the consensus in the blockchain. Further, it can be include:
  • the transaction request is a blockchain transaction, based on the load balancing strategy corresponding to the asynchronous consensus algorithm, the target of allocating the optimal load to the blockchain transaction from the node devices participating in the consensus in the blockchain Node equipment, and establish a binding relationship between the blockchain transaction and the target node equipment;
  • the transaction request is a query request corresponding to a blockchain transaction
  • the binding relationship is queried, and the target node device bound to the blockchain transaction is assigned to the query request.
  • the asynchronous consensus algorithm since the asynchronous consensus algorithm will not broadcast the transaction execution result generated after the blockchain executes the first step transaction request to each node device, only the current node device that accepted the first step transaction request and executed the transaction request itself has the certificate. There are transaction execution results. Therefore, when performing the second step, except for the current node device, other node devices do not have a certificate of transaction execution results, so they cannot query the transaction execution results when performing the second step. Therefore, for the asynchronous consensus algorithm, the binding relationship between the blockchain transaction and the target node device can be established when performing the first step, and then the query transaction is also forced to be loaded to the target of the first step when performing the second step. on the node device. In this way, there will be no problem of not being able to query the transaction execution results.
  • the asynchronous consensus algorithm may include the honeybadger consensus algorithm.
  • the consensus algorithm supported by the blockchain also includes a synchronous consensus algorithm
  • allocating the target node device for the transaction request from the node devices participating in the consensus in the blockchain may include :
  • the target node device with the optimal load is allocated to the transaction request from the node devices participating in the consensus in the blockchain.
  • the synchronous consensus algorithm will broadcast the transaction execution result generated after the blockchain executes the first step of the transaction request to each node device, so that each node device can locally store the transaction execution result. Therefore, for the synchronous consensus algorithm, any node device that receives the transaction execution result can be used as the node device that receives the transaction query in the second step. Based on this, when doing load balancing, the target node device with the optimal load for the transaction request can be allocated from the node devices participating in the consensus in the blockchain.
  • the synchronous consensus algorithm may include a PBFT (Practical Byzantine Fault Tolerance, Practical Byzantine Fault Tolerance) consensus algorithm.
  • the node device with the optimal load may include a randomly designated node device.
  • the optimal load node device is a randomly designated node device, due to the introduction of the mandatory load balancing of transaction requests and transaction result query requests to the same node
  • the load balancing mechanism of equipment processing can ensure that when the blockchain supports asynchronous consensus algorithms, the business system can obtain the transaction execution results in real time.
  • connection pool maintained in the access program is used to maintain the connection between the user client and the node device in the blockchain, and records the load status of each node device.
  • Transaction requests can be divided into transaction requests related to blockchain transactions and transaction requests unrelated to blockchain transactions. Among them, the transaction request requires consensus before execution. That is, after receiving the transaction request, the node device participating in the consensus in the blockchain first needs to perform consensus processing on the transaction request. After the consensus is passed, the transaction request will be processed. The block The node in the chain, which serves as the accounting node, packages the transaction into a block and stores it permanently in the blockchain. Transaction requests do not require consensus before execution.
  • connection pools can also be classified in this specification.
  • the access program can maintain a first connection pool based on connections with each node device participating in the consensus in the blockchain; And, a second connection pool based on connections with various node devices in the blockchain that do not participate in consensus;
  • a target node device is assigned to the transaction request from the node devices participating in the consensus in the blockchain, and the transaction request is sent to the assigned target node device for processing, Further can include:
  • step 140 the node device with the optimal load is allocated to the transaction request from the node devices in the blockchain that do not participate in the consensus, and the transaction request is sent to the node device for processing, and further Can include:
  • Timing detection determines whether the connections in the first connection pool and the second connection pool are available, and based on the detection results, adds an indication that the connection is available to the connections in the first connection pool and the second connection pool. Available tags to update the connection pool corresponding to the user client.
  • the user client when the user client is started, it can create a connection with each node device based on the configured IP and port of each node on the blockchain, and it is managed by the connection pool. At the same time, you can set up a scheduled task to detect the connections in the connection pool. Scheduled tasks can send asynchronous query requests to all connections, and each node device can return response data after receiving the asynchronous query request. In this way, the scheduled task can update the connection pool based on whether the connection corresponding to each node device returns response data.
  • the aforementioned allocating a target connection for the transaction request from the first connection pool may include:
  • the aforementioned allocating a target connection for the transaction request from the second connection pool may include:
  • the timing to determine whether connections in the first connection pool and the second connection pool are available includes:
  • connection is unavailable (the connection between the connection pool and the node device is marked as unavailable).
  • the timeout mechanism of the scheduled task will automatically confirm the timeout, thereby marking the connection with the node device as unavailable.
  • unavailable node devices obviously cannot be used, and the target node device can only be determined from the available connections in the connection pool.
  • the connection pool can be updated periodically through scheduled tasks to update the latest load status of each node equipment.
  • the preset timestamp range includes a timestamp range corresponding to a specified block in the blockchain.
  • the timestamp range corresponding to the latest block in the blockchain or the timestamp range corresponding to the most recent blocks in the blockchain.
  • this specification provides a load balancing solution that adapts to the load differences caused by different types of consensus algorithms by setting different load balancing strategies for different types of consensus algorithms supported by the blockchain; thus, For a transaction request related to a blockchain transaction submitted by a user, the transaction request can be processed from the node devices participating in the consensus in the blockchain according to the load balancing strategy corresponding to the consensus algorithm for the transaction request. Assign target node devices for processing. Since the load balancing strategy takes into account the load difference of the consensus algorithm, the allocated target node device is the current optimal node device. Based on the target node device, the transaction request can be quickly responded to, thereby avoiding the problem of slow response caused by excessive load on some node devices. .
  • this specification also provides an embodiment of a load balancing device.
  • the embodiments of the load balancing device in this specification can be applied to electronic equipment.
  • the device embodiments may be implemented by software, or may be implemented by hardware or a combination of software and hardware.
  • Taking software implementation as an example as a logical device, it is formed by reading the corresponding computer program instructions in the non-volatile memory into the memory and running them through the processor of the electronic device where it is located.
  • FIG. 3 it is a hardware structure diagram of the electronic equipment where the load balancing device of this specification is located.
  • the electronic device where the device in the embodiment is located may also include other hardware according to the actual functions of the electronic device, which will not be described again.
  • FIG. 4 is a block diagram of a load balancing device according to an exemplary embodiment of this specification.
  • the load balancing device can be applied to the access program corresponding to the blockchain, and the device includes:
  • the receiving unit 410 receives the transaction request submitted by the user
  • the determining unit 420 determines the type of the transaction request in response to the received transaction request submitted by the user;
  • the balancing unit 430 when the transaction request is a transaction request related to a blockchain transaction, based on the load balancing strategy corresponding to the consensus algorithm supported by the blockchain, node devices participating in the consensus from the blockchain Allocate target node equipment to the transaction request in , and send the transaction request to the allocated target node equipment for processing; wherein, the different types of consensus algorithms supported by the blockchain respectively correspond to different load balancing Strategy.
  • the balancing unit 430 is also configured to remove nodes from the blockchain that do not participate in the consensus based on a preset load balancing strategy when the transaction request is a transaction request that is not related to a blockchain transaction.
  • the device allocates the node device with the optimal load for the transaction request, and sends the transaction request to the node device for processing.
  • the consensus algorithm supported by the blockchain includes an asynchronous consensus algorithm;
  • the transaction requests related to blockchain transactions include blockchain transactions and query requests for blockchain transactions;
  • the balancing unit 430 is also configured to, when the transaction request is a blockchain transaction, based on the load balancing strategy corresponding to the asynchronous consensus algorithm, from the node devices participating in the consensus in the blockchain, for the The blockchain transaction allocates the target node device with the optimal load, and establishes a binding relationship between the blockchain transaction and the target node device; and, when the transaction request is a query request corresponding to the blockchain transaction, Based on the load balancing strategy corresponding to the asynchronous consensus algorithm, the binding relationship is queried, and the target node device bound to the blockchain transaction is assigned to the query request.
  • the consensus algorithm supported by the blockchain also includes a synchronous consensus algorithm
  • the balancing unit 430 is also configured to allocate the target node device with the optimal load for the transaction request from the node devices participating in the consensus in the blockchain based on the load balancing strategy corresponding to the synchronous consensus algorithm.
  • the optimally loaded node device includes a randomly designated node device.
  • the synchronous consensus algorithm includes the pbft consensus algorithm; the asynchronous consensus algorithm includes the honeybadger consensus algorithm.
  • the access program includes an SDK program for accessing the blockchain.
  • the SDK program includes an SDK access program installed on the user client;
  • the receiving unit 410 is also used to obtain the transaction request initiated by the user on the user client.
  • the SDK program includes an SDK access service program corresponding to the user client mounted on the blockchain service platform;
  • the receiving unit 410 is also configured to receive a transaction request submitted by the user client by calling the service interface deployed on the blockchain service platform and corresponding to the SDK access service program.
  • the access program maintains a first connection pool based on connections with each node device that participates in consensus in the blockchain; and, based on connections with nodes that do not participate in consensus in the blockchain A second connection pool composed of connections between various node devices;
  • the balancing unit 430 allocates a target node device for the transaction request from the node devices participating in the consensus in the blockchain, and sends the transaction request to the assigned target node device for processing, including:
  • the balancing unit 430 allocates the node device with the optimal load for the transaction request from the node devices that do not participate in the consensus in the blockchain, and sends the transaction request to the node device for processing, including:
  • the device also includes:
  • a detection unit that periodically detects and determines whether the connections in the first connection pool and the second connection pool are available, and adds the indication to the connections in the first connection pool and the second connection pool based on the detection results. Connect to available tags available;
  • the balancing unit 430 allocates a target connection for the transaction request from the first connection pool, including:
  • the balancing unit 430 allocates a target connection for the transaction request from the second connection pool, including:
  • the detection unit is also configured to regularly send an asynchronous query request to the node device corresponding to the connection in the first connection pool and the second connection pool; if the request is received within the preset timestamp range, If the response data returned by the node device is received, it is determined that the connection is available; if the response data returned by the node device is not received within the preset timestamp range, the connection is determined to be unavailable.
  • the preset timestamp range includes a timestamp range corresponding to a specified block in the blockchain.
  • a typical implementation device is a computer, which may be in the form of a personal computer, a laptop, a cellular phone, a camera phone, a smart phone, a personal digital assistant, a media player, a navigation device, an email transceiver, or a game controller. desktop, tablet, wearable device, or a combination of any of these devices.
  • a computer includes one or more processors (CPUs), input/output interfaces, network interfaces, and memory.
  • processors CPUs
  • input/output interfaces network interfaces
  • memory volatile and non-volatile memory
  • Memory may include non-permanent storage in computer-readable media, random access memory (RAM) and/or non-volatile memory in the form of read-only memory (ROM) or flash memory (flash RAM). Memory is an example of computer-readable media.
  • RAM random access memory
  • ROM read-only memory
  • flash RAM flash random access memory
  • Computer-readable media includes both persistent and non-volatile, removable and non-removable media that can be implemented by any method or technology for storage of information.
  • Information may be computer-readable instructions, data structures, modules of programs, or other data.
  • Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), and read-only memory.
  • PRAM phase change memory
  • SRAM static random access memory
  • DRAM dynamic random access memory
  • RAM random access memory
  • read-only memory read-only memory
  • ROM read-only memory
  • EEPROM electrically erasable programmable read-only memory
  • flash memory or other memory technology
  • compact disc read-only memory CD-ROM
  • DVD digital versatile disc
  • Magnetic tape cartridges magnetic disk storage, quantum memory, graphene-based storage media or other magnetic storage devices, or any other non-transmission medium, can be used to store information that can be accessed by computing devices.
  • computer-readable media does not include transitory media, such as modulated data signals and carrier waves.
  • first, second, third, etc. may use the terms first, second, third, etc. to describe various information, the information should not be limited to these terms. These terms are only used to distinguish information of the same type from each other.
  • first information may also be called second information, and similarly, the second information may also be called first information.
  • word “if” as used herein may be interpreted as "when” or “when” or “in response to determining.”

Abstract

A load balance method and apparatus, and an electronic device. The method comprises: receiving a transaction request submitted by a user; in response to the received transaction request submitted by the user, determining the type of the transaction request; and, if the transaction request is a transaction request related to a blockchain transaction, allocating, on the basis of a load balance policy corresponding to a consensus algorithm supported by a blockchain, the transaction request a target node device amongst node devices in the blockchain participating in a consensus, and sending to the allocated target node device the transaction request to be processed, consensus algorithms of different types supported by the blockchain respectively corresponding to different load balance policies.

Description

负载均衡方法及装置和电子设备Load balancing method and device and electronic equipment
本申请要求于2022年04月29日提交中国专利局、申请号为202210473991.X、发明名称为“负载均衡方法及装置和电子设备”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。This application claims priority to the Chinese patent application filed with the China Patent Office on April 29, 2022, with application number 202210473991. in this application.
技术领域Technical field
本说明书一个或多个实施例涉及区块链技术领域,尤其涉及一种负载均衡方法及装置和电子设备。One or more embodiments of this specification relate to the field of blockchain technology, and in particular, to a load balancing method and device and electronic equipment.
背景技术Background technique
区块链技术,也被称之为分布式账本技术,是一种由若干台计算设备共同参与“记账”,共同维护一份完整的分布式数据库的新兴技术。由于区块链技术具有去中心化、公开透明、每台计算设备可以参与数据库记录、并且各计算设备之间可以快速的进行数据同步的特性,使得区块链技术已在众多的领域中广泛的进行应用。Blockchain technology, also known as distributed ledger technology, is an emerging technology in which several computing devices jointly participate in "bookkeeping" and jointly maintain a complete distributed database. Because blockchain technology is decentralized, open and transparent, each computing device can participate in database records, and data can be synchronized quickly between computing devices, blockchain technology has been widely used in many fields. Apply.
发明内容Contents of the invention
本说明书实施例提供的一种提高信息安全的方法及装置和电子设备。The embodiments of this specification provide a method, device and electronic equipment for improving information security.
根据本说明书实施例的第一方面,提供一种负载均衡方法,应用于与区块链对应的接入程序,所述方法包括:According to a first aspect of the embodiments of this specification, a load balancing method is provided, applied to an access program corresponding to a blockchain, and the method includes:
接收用户提交的交易请求;Receive transaction requests submitted by users;
响应于接收到的用户提交的交易请求,确定所述交易请求的类型;In response to receiving a transaction request submitted by the user, determining the type of the transaction request;
如果所述交易请求为与区块链交易相关的交易请求,基于与所述区块链支持的共识算法对应的负载均衡策略,从所述区块链中参与共识的节点设备中为所述交易请求分配目标节点设备,并将所述交易请求发送至分配的所述目标节点设备进行处理;其中,所述区块链支持的不同类型的共识算法,分别对应不同的负载均衡策略。If the transaction request is a transaction request related to a blockchain transaction, based on the load balancing strategy corresponding to the consensus algorithm supported by the blockchain, the node device participating in the consensus in the blockchain provides the transaction with Request allocation of target node equipment, and send the transaction request to the allocated target node equipment for processing; wherein, different types of consensus algorithms supported by the blockchain respectively correspond to different load balancing strategies.
可选的,所述方法还包括:Optionally, the method also includes:
如果所述交易请求为与区块链交易无关的交易请求,基于预设的负载均衡策略,从所述区块链中不参与共识的节点设备中为所述交易请求分配负载最优的节点设备,并将所述交易请求发送至该节点设备进行处理。If the transaction request is a transaction request that is not related to the blockchain transaction, based on the preset load balancing strategy, allocate the node device with the optimal load to the transaction request from the node devices that do not participate in the consensus in the blockchain. , and send the transaction request to the node device for processing.
可选的,所述区块链支持的共识算法包括异步共识算法;所述与区块链交易相关的交易请求包括区块链交易和针对区块链交易的查询请求;Optionally, the consensus algorithm supported by the blockchain includes an asynchronous consensus algorithm; the transaction requests related to blockchain transactions include blockchain transactions and query requests for blockchain transactions;
所述基于与所述区块链支持的共识算法对应的负载均衡策略,从所述区块链中参与共识的节点设备中为所述交易请求分配目标节点设备,包括:The method of allocating a target node device to the transaction request from the node devices participating in the consensus in the blockchain based on the load balancing strategy corresponding to the consensus algorithm supported by the blockchain includes:
如果所述交易请求为区块链交易,基于与所述异步共识算法对应的负载均衡策略,从所述区块链中参与共识的节点设备中为所述区块链交易分配最优负载的目标节点设备,并建立所述区块链交易与所述目标节点设备的绑定关系;If the transaction request is a blockchain transaction, based on the load balancing strategy corresponding to the asynchronous consensus algorithm, the target of allocating the optimal load to the blockchain transaction from the node devices participating in the consensus in the blockchain Node equipment, and establish a binding relationship between the blockchain transaction and the target node equipment;
如果所述交易请求为与区块链交易对应的查询请求,基于与所述异步共识算法对应的负载均衡策略,查询所述绑定关系,将与所述区块链交易绑定的目标节点设备分配给所述查询请求。If the transaction request is a query request corresponding to a blockchain transaction, based on the load balancing strategy corresponding to the asynchronous consensus algorithm, the binding relationship is queried, and the target node device bound to the blockchain transaction is assigned to the query request.
可选的,所述区块链支持的共识算法还包括同步共识算法;Optionally, the consensus algorithm supported by the blockchain also includes a synchronous consensus algorithm;
所述基于与所述区块链支持的共识算法对应的负载均衡策略,从所述区块链中参与共识的节点设备中为所述交易请求分配目标节点设备,包括:The method of allocating a target node device to the transaction request from the node devices participating in the consensus in the blockchain based on the load balancing strategy corresponding to the consensus algorithm supported by the blockchain includes:
基于与所述同步共识算法对应的负载均衡策略,从所述区块链中参与共识的节点设备中为所述交易请求分配最优负载的目标节点设备。Based on the load balancing strategy corresponding to the synchronous consensus algorithm, the target node device with the optimal load is allocated to the transaction request from the node devices participating in the consensus in the blockchain.
可选的,所述最优负载的节点设备包括随机指定的节点设备。Optionally, the optimally loaded node device includes a randomly designated node device.
可选的,所述同步共识算法包括pbft共识算法;所述异步共识算法包括honeybadger共识算法。Optionally, the synchronous consensus algorithm includes the pbft consensus algorithm; the asynchronous consensus algorithm includes the honeybadger consensus algorithm.
可选的,所述接入程序包括用于接入区块链的SDK程序。Optionally, the access program includes an SDK program for accessing the blockchain.
可选的,所述SDK程序包括用户客户端搭载的SDK接入程序;Optionally, the SDK program includes an SDK access program installed on the user client;
所述接收用户提交的交易请求,包括:The reception of transaction requests submitted by users includes:
获取用户在所述用户客户端上发起的交易请求。Obtain the transaction request initiated by the user on the user client.
可选的,所述SDK程序包括区块链服务平台上搭载的与用户客户端对应的SDK接入服务程序;Optionally, the SDK program includes an SDK access service program corresponding to the user client mounted on the blockchain service platform;
所述接收用户提交的交易请求,包括:The reception of transaction requests submitted by users includes:
接收所述用户客户端通过调用所述区块链服务平台上部署的与所述SDK接入服务程序对应服务接口提交的交易请求。Receive a transaction request submitted by the user client by calling a service interface deployed on the blockchain service platform corresponding to the SDK access service program.
可选的,所述接入程序维护了基于与所述区块链中参与共识的各个节点设备之间的连接构成的第一连接池;以及,基于与所述区块链中不参与共识的各个节点设备之间的连接构成的第二连接池;Optionally, the access program maintains a first connection pool based on connections with each node device that participates in consensus in the blockchain; and, based on connections with nodes that do not participate in consensus in the blockchain A second connection pool composed of connections between various node devices;
所述从所述区块链中参与共识的节点设备中为所述交易请求分配目标节点设备,并将所述交易请求发送至分配的所述目标节点设备进行处理,包括:Allocating a target node device to the transaction request from the node devices participating in the consensus in the blockchain, and sending the transaction request to the assigned target node device for processing, including:
从所述第一连接池中为所述交易请求分配目标连接,并基于所述目标连接将所述交易请求发送至与所述目标连接对应的目标节点设备进行处理;Allocate a target connection to the transaction request from the first connection pool, and send the transaction request to the target node device corresponding to the target connection for processing based on the target connection;
所述从所述区块链中不参与共识的节点设备中为所述交易请求分配负载最优的节点设备,并将所述交易请求发送至该节点设备进行处理,包括:Allocating the node device with the optimal load to the transaction request from the node devices that do not participate in the consensus in the blockchain, and sending the transaction request to the node device for processing includes:
从所述第二连接池中为所述交易请求分配目标连接,并基于所述目标连接将所述交易请求发送至与所述目标连接对应的目标节点设备进行处理。Allocate a target connection to the transaction request from the second connection pool, and send the transaction request to a target node device corresponding to the target connection for processing based on the target connection.
可选的,所述方法还包括:Optionally, the method also includes:
定时检测确定所述第一连接池和所述第二连接池中的连接是否可用,并基于检测结果对所述第一连接池和所述第二连接池中的连接添加指示所述连接为可用的可用标签;Timing detection determines whether the connections in the first connection pool and the second connection pool are available, and based on the detection results, adds an indication that the connection is available to the connections in the first connection pool and the second connection pool. available tags;
所述从所述第一连接池中为所述交易请求分配目标连接,包括:Allocating a target connection for the transaction request from the first connection pool includes:
从所述第一连接池内被添加了可用标签的连接中为所述交易请求分配可用的目标连接;Allocate available target connections for the transaction request from the connections added with available tags in the first connection pool;
所述从所述第二连接池中为所述交易请求分配目标连接,包括:Allocating a target connection for the transaction request from the second connection pool includes:
从所述第二连接池内被添加了可用标签的连接中为所述交易请求分配可用的目标连接。Allocate available target connections for the transaction request from connections added with available tags in the second connection pool.
可选的,所述定时确定所述第一连接池和所述第二连接池中的连接是否可用,包括:Optionally, the timing to determine whether connections in the first connection pool and the second connection pool are available includes:
定时向所述第一连接池和所述第二连接池中的连接对应的节点设备发送异步查询请求;Regularly sending asynchronous query requests to node devices corresponding to connections in the first connection pool and the second connection pool;
如果在预设的时间戳范围内接收到所述节点设备返回的响应数据,则确定该连接可用;If the response data returned by the node device is received within the preset timestamp range, it is determined that the connection is available;
如果在预设的时间戳范围内未接收到所述节点设备返回的响应数据,则确定该连接不可用。If the response data returned by the node device is not received within the preset timestamp range, it is determined that the connection is unavailable.
可选的,所述预设的时间戳范围包括与所述区块链中指定区块对应的时间戳范围。Optionally, the preset timestamp range includes a timestamp range corresponding to a specified block in the blockchain.
根据本说明书实施例的第二方面,提供一种负载均衡装置,应用于与区块链对应的接入程序,所述装置包括:According to the second aspect of the embodiment of this specification, a load balancing device is provided, which is applied to the access program corresponding to the blockchain. The device includes:
接收单元,接收用户提交的交易请求;The receiving unit receives transaction requests submitted by users;
确定单元,响应于接收到的用户提交的交易请求,确定所述交易请求的类型;a determining unit that determines the type of the transaction request in response to the received transaction request submitted by the user;
均衡单元,在所述交易请求为与区块链交易相关的交易请求时,基于与所述区块链支持的共识算法对应的负载均衡策略,从所述区块链中参与共识的节点设备中为所述交易请求分配目标节点设备,并将所述交易请求发送至分配的所述目标节点设备进行处理;其中,所述区块链支持的不同类型的共识算法,分别对应不同的负载均衡策略。A balancing unit, when the transaction request is a transaction request related to a blockchain transaction, based on the load balancing strategy corresponding to the consensus algorithm supported by the blockchain, from the node devices participating in the consensus in the blockchain Allocate a target node device to the transaction request, and send the transaction request to the assigned target node device for processing; wherein, the different types of consensus algorithms supported by the blockchain respectively correspond to different load balancing strategies. .
可选的,所述均衡单元,还用于在所述交易请求为与区块链交易无关的交易请求时,基于预设的负载均衡策略,从所述区块链中不参与共识的节点设备中为所述交易请求分配负载最优的节点设备,并将所述交易请求发送至该节点设备进行处理。Optionally, the balancing unit is also configured to remove node devices that do not participate in the consensus from the blockchain based on a preset load balancing strategy when the transaction request is a transaction request that is not related to a blockchain transaction. Allocate the node device with the optimal load to the transaction request, and send the transaction request to the node device for processing.
可选的,所述区块链支持的共识算法包括异步共识算法;所述与区块链交易相关的交易请求包括区块链交易和针对区块链交易的查询请求;Optionally, the consensus algorithm supported by the blockchain includes an asynchronous consensus algorithm; the transaction requests related to blockchain transactions include blockchain transactions and query requests for blockchain transactions;
所述均衡单元,还用于在所述交易请求为区块链交易时,基于与所述异步共识算法对应的负载均衡策略,从所述区块链中参与共识的节点设备中为所述区块链交易分配最优负载的目标节点设备,并建立所述区块链交易与所述目标节点设备的绑定关系;以及,在所述交易请求为与区块链交易对应的查询请求,基于与所述异步共识算法对应的负载均衡策略,查询所述绑定关系,将与所述区块链交易绑定的目标节点设备分配给所述查询请求。The balancing unit is also configured to, when the transaction request is a blockchain transaction, based on the load balancing strategy corresponding to the asynchronous consensus algorithm, from the node devices participating in the consensus in the blockchain, provide the balance for the zone. The block chain transaction allocates the target node device with the optimal load, and establishes a binding relationship between the block chain transaction and the target node device; and, when the transaction request is a query request corresponding to the block chain transaction, based on The load balancing strategy corresponding to the asynchronous consensus algorithm queries the binding relationship, and allocates the target node device bound to the blockchain transaction to the query request.
可选的,所述区块链支持的共识算法还包括同步共识算法;Optionally, the consensus algorithm supported by the blockchain also includes a synchronous consensus algorithm;
所述均衡单元,还用于基于与所述同步共识算法对应的负载均衡策略,从所述区块链中参与共识的节点设备中为所述交易请求分配最优负载的目标节点设备。The balancing unit is also configured to allocate the target node device with the optimal load to the transaction request from the node devices participating in the consensus in the blockchain based on the load balancing strategy corresponding to the synchronous consensus algorithm.
可选的,所述最优负载的节点设备包括随机指定的节点设备。Optionally, the optimally loaded node device includes a randomly designated node device.
可选的,所述同步共识算法包括pbft共识算法;所述异步共识算法包括honeybadger共识算法。Optionally, the synchronous consensus algorithm includes the pbft consensus algorithm; the asynchronous consensus algorithm includes the honeybadger consensus algorithm.
可选的,所述接入程序包括用于接入区块链的SDK程序。Optionally, the access program includes an SDK program for accessing the blockchain.
可选的,所述SDK程序包括用户客户端搭载的SDK接入程序;Optionally, the SDK program includes an SDK access program installed on the user client;
所述接收单元,还用于获取用户在所述用户客户端上发起的交易请求。The receiving unit is also used to obtain the transaction request initiated by the user on the user client.
可选的,所述SDK程序包括区块链服务平台上搭载的与用户客户端对应的SDK接入服务程序;Optionally, the SDK program includes an SDK access service program corresponding to the user client mounted on the blockchain service platform;
所述接收单元,还用于接收所述用户客户端通过调用所述区块链服务平台上部署的与所述SDK接入服务程序对应服务接口提交的交易请求。The receiving unit is also configured to receive a transaction request submitted by the user client by calling the service interface deployed on the blockchain service platform and corresponding to the SDK access service program.
可选的,所述接入程序维护了基于与所述区块链中参与共识的各个节点设备之间的连接构成的第一连接池;以及,基于与所述区块链中不参与共识的各个节点设备之间的连接构成的第二连接池;Optionally, the access program maintains a first connection pool based on connections with each node device that participates in consensus in the blockchain; and, based on connections with nodes that do not participate in consensus in the blockchain A second connection pool composed of connections between various node devices;
所述均衡单元中从所述区块链中参与共识的节点设备中为所述交易请求分配目标节点设备,并将所述交易请求发送至分配的所述目标节点设备进行处理,包括:The balancing unit allocates a target node device for the transaction request from the node devices participating in the consensus in the blockchain, and sends the transaction request to the assigned target node device for processing, including:
从所述第一连接池中为所述交易请求分配目标连接,并基于所述目标连接将所述交易请求发送至与所述目标连接对应的目标节点设备进行处理;Allocate a target connection to the transaction request from the first connection pool, and send the transaction request to the target node device corresponding to the target connection for processing based on the target connection;
所述均衡单元中从所述区块链中不参与共识的节点设备中为所述交易请求分配负载最优的节点设备,并将所述交易请求发送至该节点设备进行处理,包括:The balancing unit allocates the node device with the optimal load for the transaction request from the node devices in the blockchain that do not participate in the consensus, and sends the transaction request to the node device for processing, including:
从所述第二连接池中为所述交易请求分配目标连接,并基于所述目标连接将所述交易请求发送至与所述目标连接对应的目标节点设备进行处理。Allocate a target connection to the transaction request from the second connection pool, and send the transaction request to a target node device corresponding to the target connection for processing based on the target connection.
可选的,所述装置还包括:Optionally, the device also includes:
检测单元,定时检测确定所述第一连接池和所述第二连接池中的连接是否可用,并基于检测结果对所述第一连接池和所述第二连接池中的连接添加指示所述连接为可用的可用标签;A detection unit that periodically detects and determines whether the connections in the first connection pool and the second connection pool are available, and adds the indication to the connections in the first connection pool and the second connection pool based on the detection results. Connect to available tags available;
所述均衡单元中从所述第一连接池中为所述交易请求分配目标连接,包括:The balancing unit allocates a target connection for the transaction request from the first connection pool, including:
从所述第一连接池内被添加了可用标签的连接中为所述交易请求分配可用的目标连接;Allocate available target connections for the transaction request from the connections added with available tags in the first connection pool;
所述均衡单元中从所述第二连接池中为所述交易请求分配目标连接,包括:The balancing unit allocates a target connection for the transaction request from the second connection pool, including:
从所述第二连接池内被添加了可用标签的连接中为所述交易请求分配可用的目标连接。Allocate available target connections for the transaction request from connections added with available tags in the second connection pool.
可选的,所述检测单元,还用于定时向所述第一连接池和所述第二连接池中的连接对应的节点设备发送异步查询请求;如果在预设的时间戳范围内接收到所述节点设备返回的响应数据,则确定该连接可用;如果在预设的时间戳范围内未接收到所述节点设备返回的响应数据,则确定该连接不可用。Optionally, the detection unit is also configured to regularly send an asynchronous query request to the node device corresponding to the connection in the first connection pool and the second connection pool; if the request is received within the preset timestamp range, If the response data returned by the node device is received, it is determined that the connection is available; if the response data returned by the node device is not received within the preset timestamp range, the connection is determined to be unavailable.
可选的,所述预设的时间戳范围包括与所述区块链中指定区块对应的时间戳范围。Optionally, the preset timestamp range includes a timestamp range corresponding to a specified block in the blockchain.
根据本说明书实施例的第三方面,提供一种电子设备,包括:According to a third aspect of the embodiments of this specification, an electronic device is provided, including:
处理器;processor;
用于存储处理器可执行指令的存储器;Memory used to store instructions executable by the processor;
其中,所述处理器被配置为上述任一项负载均衡方法。Wherein, the processor is configured for any one of the above load balancing methods.
本说明书实施例,提供了一种负载均衡方案,通过为区块链支持的不同类型的共识算法设置对应不同的负载均衡策略,以适配不同类型的共识算法导致的负载差异;如此,针对用户提交的与区块链交易相关的交易请求,可以根据对该交易请求进行共识的共识算法所对应的负载均衡策略,从所述区块链中参与共识的节点设备中为所述交易请求分配目标节点设备进行处理。由于负载均衡策略考虑了共识算法的负载差异,因此分配的目标节点设备是当前最优的节点设备,基于目标节点设备可以快速响应交易请求,从而可以避免部分节点设备负载过多导致响应缓慢的问题。The embodiment of this specification provides a load balancing solution that sets different load balancing strategies for different types of consensus algorithms supported by the blockchain to adapt to the load differences caused by different types of consensus algorithms; in this way, for users The submitted transaction request related to the blockchain transaction can be assigned a target from the node devices participating in the consensus in the blockchain according to the load balancing strategy corresponding to the consensus algorithm for the transaction request. node device for processing. Since the load balancing strategy takes into account the load difference of the consensus algorithm, the allocated target node device is the current optimal node device. Based on the target node device, the transaction request can be quickly responded to, thereby avoiding the problem of slow response caused by excessive load on some node devices. .
附图说明Description of drawings
图1是一示例性实施例提供的一种负载均衡方法的流程图;Figure 1 is a flow chart of a load balancing method provided by an exemplary embodiment;
图2是一示例性实施例提供的一种负载均衡的系统架构图;Figure 2 is a system architecture diagram of load balancing provided by an exemplary embodiment;
图3是一示例性实施例提供的一种电子设备的结构示意图;Figure 3 is a schematic structural diagram of an electronic device provided by an exemplary embodiment;
图4是一示例性实施例提供的一种负载均衡装置的框图。Figure 4 is a block diagram of a load balancing device provided by an exemplary embodiment.
具体实施方式Detailed ways
这里将详细地对示例性实施例进行说明,其示例表示在附图中。下面的描述涉及附图时,除非另有表示,不同附图中的相同数字表示相同或相似的要素。以下示例性实施例中所描述的实现方式并不代表与本说明书一个或多个实施例相一致的所有实现方式。相反,它们仅是与如所附权利要求书中所详述的、本说明书一个或多个实施例的一些方面相一致的装置和方法的例子。Exemplary embodiments will be described in detail herein, examples of which are illustrated in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings refer to the same or similar elements unless otherwise indicated. The implementations described in the following exemplary embodiments do not represent all implementations consistent with one or more embodiments of this specification. Rather, they are merely examples of apparatus and methods consistent with some aspects of one or more embodiments of this specification as detailed in the appended claims.
需要说明的是:在其他实施例中并不一定按照本说明书示出和描述的顺序来执行相应方法的步骤。在一些其他实施例中,其方法所包括的步骤可以比本说明书所描述的更多或更少。此外,本说明书中所描述的单个步骤,在其他实施例中可能被分解为多个步骤进行描述;而本说明书中所描述的多个步骤,在其他实施例中也可能被合并为单个步骤进行描述。It should be noted that in other embodiments, the steps of the corresponding method are not necessarily performed in the order shown and described in this specification. In some other embodiments, methods may include more or fewer steps than described in this specification. In addition, a single step described in this specification may be broken down into multiple steps for description in other embodiments; and multiple steps described in this specification may also be combined into a single step in other embodiments. describe.
由于区块链相对于非区块链场景存在一定的特殊性,因而现有非区块链场景下的负载均衡算法或策略存在负载均衡效果不理想,无法满足区块链对负载均衡的需求。例如,由于区块链存在共识机制,需要对不同的交易类型进行共识,因此区块链通常支持多种不同的共识算法,而不同共识算法导致的负载结果并不相同。Since blockchain has certain particularities compared to non-blockchain scenarios, existing load balancing algorithms or strategies in non-blockchain scenarios have unsatisfactory load balancing effects and cannot meet the load balancing needs of blockchain. For example, since the blockchain has a consensus mechanism that requires consensus on different transaction types, the blockchain usually supports a variety of different consensus algorithms, and the load results caused by different consensus algorithms are not the same.
现有负载均衡方案并未考虑不同共识算法下区块链的负载均衡差异,依然采用统一的负载均衡方案,这样就容易导致区块链中局部的节点设备可能会出现过重的负载压力,而局部的节点设备却处于空闲状态。如此,容易导致区块链整体处理效率偏低,无法及时响应交易请求。Existing load balancing solutions do not consider the load balancing differences of blockchains under different consensus algorithms and still use a unified load balancing solution. This may easily lead to excessive load pressure on local node devices in the blockchain. The local node equipment is in idle state. In this way, it is easy to cause the overall processing efficiency of the blockchain to be low and unable to respond to transaction requests in a timely manner.
为此,本说明书针对区块链场景,提供一种专门适用于区块链的负载均衡方案,可以高效地分配交易请求,实现区块链中节点设备均衡地处理交易请求,解决各节点设备负载不均衡的问题。To this end, this manual provides a load balancing solution specifically suitable for blockchain scenarios, which can efficiently allocate transaction requests, enable node devices in the blockchain to process transaction requests in a balanced manner, and solve the load of each node device. Problem of imbalance.
以下请参见图1,图1是一示例性实施例提供的一种负载均衡方法的流程图。所述方法可以应用于与区块链对应的接入程序;所述方法可以包括以下步骤:Please refer to Figure 1 below, which is a flow chart of a load balancing method provided by an exemplary embodiment. The method can be applied to the access program corresponding to the blockchain; the method can include the following steps:
步骤110,接收用户提交的交易请求;Step 110: Receive the transaction request submitted by the user;
步骤120,响应于接收到的用户提交的交易请求,确定所述交易请求的类型;Step 120: In response to the received transaction request submitted by the user, determine the type of the transaction request;
步骤130,如果所述交易请求为与区块链交易相关的交易请求,基于与所述区块链支持的共识算法对应的负载均衡策略,从所述区块链中参与共识的节点设备中为所述交易请求分配目标节点设备,并将所述交易请求发送至分配的所述目标节点设备进行处理;其中,所述区块链支持的不同类型的共识算法,分别对应不同的负载均衡策略。Step 130: If the transaction request is a transaction request related to a blockchain transaction, based on the load balancing strategy corresponding to the consensus algorithm supported by the blockchain, from the node devices participating in the consensus in the blockchain, The transaction request is assigned to a target node device, and the transaction request is sent to the assigned target node device for processing; wherein, different types of consensus algorithms supported by the blockchain respectively correspond to different load balancing strategies.
本说明书描述的区块链,具体可以包括任意类型的区块链网络;在实际应用中,可以采用公有链(Public Blockchain),私有链(Private Blockchain)和联盟链(Consortium Blockchain)中的任意一种。此外,还可以有上述多种类型的结合,比如私有链+联盟链、联盟链+公有链等。The blockchain described in this manual can specifically include any type of blockchain network; in practical applications, any one of public blockchain, private blockchain and consortium blockchain can be used. kind. In addition, there can also be a combination of the above types, such as private chain + alliance chain, alliance chain + public chain, etc.
其中,去中心化程度最高的是公有链。加入公有链的参与者(也可称为区块链中的节点设备)可以读取链上的数据记录、参与交易、以及竞争新区块的记账权等。而且,各节点设备可自由加入或者退出网络,并进行相关操作。Among them, the public chain is the most decentralized. Participants who join the public chain (also called node devices in the blockchain) can read data records on the chain, participate in transactions, and compete for the accounting rights of new blocks, etc. Moreover, each node device can freely join or exit the network and perform related operations.
私有链则相反,该网络的写入权限由某个组织或者机构控制,数据读取权限受组织规定。简单来说,私有链可以为一个弱中心化系统,其对节点设备具有严格限制且节点设备数量较少。这种类型的区块链更适合于特定机构内部使用。On the contrary, the private chain has the writing permission of the network controlled by an organization or institution, and the data reading permission is regulated by the organization. Simply put, a private chain can be a weakly centralized system with strict restrictions on node equipment and a small number of node equipment. This type of blockchain is more suitable for internal use within specific organizations.
联盟链则是介于公有链以及私有链之间的区块链,可实现“部分去中心化”。联盟链中各个节点设备通常有与之相对应的实体机构或者组织;节点设备通过授权加入网络并组成利益相关联盟,共同维护区块链运行。The alliance chain is a blockchain between the public chain and the private chain, which can achieve "partial decentralization". Each node device in the alliance chain usually has a corresponding entity or organization; the node device joins the network through authorization and forms an alliance of stakeholders to jointly maintain the operation of the blockchain.
如图2为本说明书描述的一种负载均衡的系统架构图。所述负载均衡的系统可以包括用户客户端、接入程序和区块链。Figure 2 is a load balancing system architecture diagram described in this manual. The load balancing system may include a user client, an access program and a blockchain.
上述用户客户端(例如APP应用),可以面向用户提供区块链的服务入口,用户可以通过以上示出的服务入口,向接入程序提交交易请求,由接入程序基于负载均衡策略,将所述交易请求发送至所述区块链中最优负载的目标节点设备,以使所述目标节点设备处理所述交易请求。The above-mentioned user client (such as an APP application) can provide users with a service portal of the blockchain. Users can submit transaction requests to the access program through the service portal shown above, and the access program will transfer all transactions based on the load balancing strategy. The transaction request is sent to the target node device with the optimal load in the blockchain, so that the target node device processes the transaction request.
上述接入程序,可以是指区块链与用户客户端之间的中间系统,其不属于区块链。接入程序中可以维护有各个用户客户端与区块链中各个节点设备之间连接的连接池。即接入程序为每个用户客户端维护有对应的连接池。The above-mentioned access program may refer to the intermediate system between the blockchain and the user client, which does not belong to the blockchain. The access program can maintain a connection pool that connects each user client to each node device in the blockchain. That is, the access program maintains a corresponding connection pool for each user client.
在本说明书中,上述接入程序具体可以包括用于接入区块链的SDK(Software Development Kit,软件开发工具包)程序。In this specification, the above-mentioned access program may specifically include an SDK (Software Development Kit) program for accessing the blockchain.
该示例中,可以将本说明书提供的负载均衡的实现代码集成到SDK程序,从而基于SDK程序实现区块链的负载均衡的目标。In this example, the load balancing implementation code provided in this manual can be integrated into the SDK program to achieve the load balancing goal of the blockchain based on the SDK program.
在一种实现方式中,所述SDK程序可以包括用户客户端搭载的SDK接入程序;In one implementation, the SDK program may include an SDK access program installed on the user client;
相应地,上述步骤110,则可以包括获取用户在所述用户客户端上发起的交易请求。Accordingly, the above step 110 may include obtaining the transaction request initiated by the user on the user client.
在一种实现方式中,所述SDK程序包括区块链服务平台上搭载的与用户客户端对应的SDK接入服务程序;In one implementation, the SDK program includes an SDK access service program corresponding to the user client mounted on the blockchain service platform;
相应地,上述步骤110,则可以包括接收所述用户客户端通过调用所述区块链服务平台上部署的与所述SDK接入服务程序对应服务接口提交的交易请求。Accordingly, the above step 110 may include receiving a transaction request submitted by the user client by calling a service interface deployed on the blockchain service platform corresponding to the SDK access service program.
在应用中,任意一个用户客户端提交的交易请求,都会先发送到接入程序;然后由接入程序从该用户客户端对应的连接池中确认一个最优负载的目标节点设备;接着由接入程序将这个交易请求发送至区块链中的目标节点设备;最后由区块链中的目标节点设备响应处理所述用户客户端提交的交易请求。In the application, any transaction request submitted by a user client will first be sent to the access program; then the access program will confirm an optimal load target node device from the connection pool corresponding to the user client; then the access program will The entry program sends the transaction request to the target node device in the blockchain; finally, the target node device in the blockchain responds and processes the transaction request submitted by the user client.
如此,通过接入程序基于区块链中节点设备的真实负载状况,在将交易请求提交到区块链之间提前做了负载均衡,使得每次负责处理交易请求的目标节点设备都是最优负载的节点设备;如此,就避免了避免部分节点设备负载过多但还要处理更多交易请求,而部分节点设备负载过少却无交易请求处理这样负载不均衡的问题。并且负载均衡后,可以合理利用原本空闲无交易请求的节点设备的处理能力,从而提升区块链整体上处理效率,降低区块链处理请求的响应时间。In this way, based on the actual load status of the node equipment in the blockchain, the access program performs load balancing in advance before submitting transaction requests to the blockchain, so that the target node equipment responsible for processing the transaction request is optimal each time. Loaded node equipment; in this way, it avoids the problem of load imbalance such that some node equipment is overloaded but has to process more transaction requests, while some node equipment is underloaded but has no transaction requests to process. And after load balancing, the processing capabilities of node devices that are originally idle and have no transaction requests can be reasonably utilized, thereby improving the overall processing efficiency of the blockchain and reducing the response time of blockchain processing requests.
针对区块链的交易请求可以是指以区块链所支持的标准的交易(transaction)格式生产的请求,并且请求中包含了需要区块链所要执行业务所需的数据。也就是说,对于任何物理世界产生的真实数据,都可以将其构建成区块链所支持的标准的交易(transaction)格式,然后发布至区块链,由区块链中的节点对收到的交易进行处理,由区块链中作为记账节点的节点,将这笔交易打包进区块,在区块链中进行持久化存证。A transaction request for the blockchain may refer to a request produced in a standard transaction format supported by the blockchain, and the request contains the data required for the business to be performed by the blockchain. In other words, any real data generated in the physical world can be constructed into a standard transaction format supported by the blockchain, and then published to the blockchain and received by the node pairs in the blockchain. The transaction is processed, and the node in the blockchain, which is the accounting node, packages the transaction into a block and makes a persistent certificate in the blockchain.
一般的,交易请求可以分为与区块链交易相关的交易请求,以及与区块链交易无关的交易请求。其中,交易请求在执行前需要进行共识,即区块链中参与共识的节点设备在收到的交易请求后,首先需要对交易请求进行共识处理,在共识通过后才会进行处理,由区块链中作为记账节点的节点,将这笔交易打包进区块,在区块链中进行持久化存证。而交易请求在执行前不需要进行共识。Generally, transaction requests can be divided into transaction requests related to blockchain transactions and transaction requests unrelated to blockchain transactions. Among them, the transaction request requires consensus before execution. That is, after receiving the transaction request, the node device participating in the consensus in the blockchain first needs to perform consensus processing on the transaction request. After the consensus is passed, the transaction request will be processed. The block The node in the chain, which serves as the accounting node, packages the transaction into a block and stores it permanently in the blockchain. Transaction requests do not require consensus before execution.
针对交易请求,由于需要参与共识的节点设备进行共识,因此可以执行前述步骤230即如果所述交易请求为与区块链交易相关的交易请求,基于与所述区块链支持的共识算法对应的负载均衡策略,从所述区块链中参与共识的节点设备中为所述交易请求分配目标节点设备,并将所述交易请求发送至分配的所述目标节点设备进行处理;其中,所述区块链支持的不同类型的共识算法,分别对应不同的负载均衡策略。For the transaction request, since the node equipment participating in the consensus needs to reach consensus, the aforementioned step 230 can be performed. That is, if the transaction request is a transaction request related to a blockchain transaction, based on the consensus algorithm corresponding to the blockchain support The load balancing strategy is to allocate target node equipment for the transaction request from the node equipment participating in the consensus in the blockchain, and send the transaction request to the allocated target node equipment for processing; wherein, the zone The different types of consensus algorithms supported by the blockchain correspond to different load balancing strategies.
针对交易请求,由于无需进行共识,因此可以执行步骤240:For transaction requests, since consensus is not required, step 240 can be performed:
如果所述交易请求为与区块链交易无关的交易请求,基于预设的负载均衡策略,从所述区块链中不参与共识的节点设备中为所述交易请求分配负载最优的节点设备,并将所述交易请求发送至该节点设备进行处理。If the transaction request is a transaction request that is not related to the blockchain transaction, based on the preset load balancing strategy, allocate the node device with the optimal load to the transaction request from the node devices that do not participate in the consensus in the blockchain. , and send the transaction request to the node device for processing.
其中,所述不参与共识的节点设备可以是轻节点,轻节点本地不存储区块链账本,所以与区块链交易相关的交易请求不能发送给这类节点设备处理。The node device that does not participate in consensus may be a light node. Light nodes do not store blockchain ledgers locally, so transaction requests related to blockchain transactions cannot be sent to such node devices for processing.
通过上述实施例,考虑到交易请求的类型存在的差异,结合区块链中节点设备的不同,针对性的为交易请求和交易请求分别提供不同的负载均衡策略,实现区块链中节点设备均衡地处理交易请求,解决 各节点设备负载不均衡的问题。Through the above embodiments, taking into account the differences in the types of transaction requests and combining the differences in node equipment in the blockchain, different load balancing strategies are provided for transaction requests and transaction requests to achieve node equipment balancing in the blockchain. Process transaction requests efficiently and solve the problem of unbalanced load of equipment on each node.
进一步的,由于区块链可以支持不同的共识算法,本说明书还针对不同的共识算法分别提供不同的负载均衡策略,以进一步提高负载均衡的性能和效率。Furthermore, since the blockchain can support different consensus algorithms, this manual also provides different load balancing strategies for different consensus algorithms to further improve the performance and efficiency of load balancing.
一般的,一笔交易的发布分为两步,第一步是将交易请求发布至区块链,第二步是根据交易哈希查询区块链执行第一步交易请求后产生的交易执行结果。对于区块链来说,其会先接收交易请求再接收交易查询,因此需要将交易请求和交易执行结果合并为一个响应结果返回给用户客户端。Generally, publishing a transaction is divided into two steps. The first step is to publish the transaction request to the blockchain. The second step is to query the blockchain based on the transaction hash to execute the transaction execution result generated after the first step of the transaction request. . For the blockchain, it will first receive the transaction request and then the transaction query, so the transaction request and transaction execution result need to be combined into a response result and returned to the user client.
在一示例性的实施例中,如果所述区块链支持的共识算法包括异步共识算法;所述与区块链交易相关的交易请求包括区块链交易和针对区块链交易的查询请求;In an exemplary embodiment, if the consensus algorithm supported by the blockchain includes an asynchronous consensus algorithm; the transaction request related to the blockchain transaction includes a blockchain transaction and a query request for the blockchain transaction;
相应地,上述步骤230中,基于与所述区块链支持的共识算法对应的负载均衡策略,从所述区块链中参与共识的节点设备中为所述交易请求分配目标节点设备,进一步可以包括:Correspondingly, in the above step 230, based on the load balancing strategy corresponding to the consensus algorithm supported by the blockchain, the target node device is allocated to the transaction request from the node devices participating in the consensus in the blockchain. Further, it can be include:
如果所述交易请求为区块链交易,基于与所述异步共识算法对应的负载均衡策略,从所述区块链中参与共识的节点设备中为所述区块链交易分配最优负载的目标节点设备,并建立所述区块链交易与所述目标节点设备的绑定关系;If the transaction request is a blockchain transaction, based on the load balancing strategy corresponding to the asynchronous consensus algorithm, the target of allocating the optimal load to the blockchain transaction from the node devices participating in the consensus in the blockchain Node equipment, and establish a binding relationship between the blockchain transaction and the target node equipment;
如果所述交易请求为与区块链交易对应的查询请求,基于与所述异步共识算法对应的负载均衡策略,查询所述绑定关系,将与所述区块链交易绑定的目标节点设备分配给所述查询请求。If the transaction request is a query request corresponding to a blockchain transaction, based on the load balancing strategy corresponding to the asynchronous consensus algorithm, the binding relationship is queried, and the target node device bound to the blockchain transaction is assigned to the query request.
该示例中,由于异步共识算法不会将区块链执行第一步交易请求后产生的交易执行结果广播给各个节点设备,只有接受第一步交易请求并执行交易请求的当前节点设备本身存证有交易执行结果。因此,在进行第二步时,除了当前节点设备,其它节点设备由于本身没有存证交易执行结果因此也就无法在进行第二步时查询到交易执行结果。故针对异步共识算法,在进行第一步时可以建立所述区块链交易与所述目标节点设备的绑定关系,然后在进行第二步时强制将查询交易也负载到第一步的目标节点设备上。这样,就不会出现查询不到交易执行结果的问题。其中,所述异步共识算法可以包括honeybadger共识算法。In this example, since the asynchronous consensus algorithm will not broadcast the transaction execution result generated after the blockchain executes the first step transaction request to each node device, only the current node device that accepted the first step transaction request and executed the transaction request itself has the certificate. There are transaction execution results. Therefore, when performing the second step, except for the current node device, other node devices do not have a certificate of transaction execution results, so they cannot query the transaction execution results when performing the second step. Therefore, for the asynchronous consensus algorithm, the binding relationship between the blockchain transaction and the target node device can be established when performing the first step, and then the query transaction is also forced to be loaded to the target of the first step when performing the second step. on the node device. In this way, there will be no problem of not being able to query the transaction execution results. Wherein, the asynchronous consensus algorithm may include the honeybadger consensus algorithm.
在一示例性的实施例中,如果所述区块链支持的共识算法还包括同步共识算法;In an exemplary embodiment, if the consensus algorithm supported by the blockchain also includes a synchronous consensus algorithm;
相应地,上述步骤230中,基于与所述区块链支持的共识算法对应的负载均衡策略,从所述区块链中参与共识的节点设备中为所述交易请求分配目标节点设备,可以包括:Correspondingly, in the above step 230, based on the load balancing strategy corresponding to the consensus algorithm supported by the blockchain, allocating the target node device for the transaction request from the node devices participating in the consensus in the blockchain may include :
基于与所述同步共识算法对应的负载均衡策略,从所述区块链中参与共识的节点设备中为所述交易请求分配最优负载的目标节点设备。Based on the load balancing strategy corresponding to the synchronous consensus algorithm, the target node device with the optimal load is allocated to the transaction request from the node devices participating in the consensus in the blockchain.
该示例中,由于同步共识算法会将区块链执行第一步交易请求后产生的交易执行结果广播给各个节点设备,以便各节点设备本地存证交易执行结果。因此,针对同步共识算法,任何接收到交易执行结果的节点设备都可以作为第二步接收交易查询的节点设备。基于此,在做负载均衡时,可以从所述区块链中参与共识的节点设备中为所述交易请求分配最优负载的目标节点设备。所述同步共识算法可以包括PBFT(Practical Byzantine Fault Tolerance,实用拜占庭容错)共识算法。In this example, the synchronous consensus algorithm will broadcast the transaction execution result generated after the blockchain executes the first step of the transaction request to each node device, so that each node device can locally store the transaction execution result. Therefore, for the synchronous consensus algorithm, any node device that receives the transaction execution result can be used as the node device that receives the transaction query in the second step. Based on this, when doing load balancing, the target node device with the optimal load for the transaction request can be allocated from the node devices participating in the consensus in the blockchain. The synchronous consensus algorithm may include a PBFT (Practical Byzantine Fault Tolerance, Practical Byzantine Fault Tolerance) consensus algorithm.
在上述同步共识算法还是异步共识算法的示例中,所述最优负载的节点设备可以包括随机指定的节点设备。In the above example of the synchronous consensus algorithm or the asynchronous consensus algorithm, the node device with the optimal load may include a randomly designated node device.
值得一提的是,在采用异步共识算法的区块链中,虽然最优负载的节点设备为随机指定的节点设备,但是由于引入强制将交易请求和交易结果的查询请求负载均衡到同一个节点设备进行处理的负载均衡机制,可以确保在区块链支持异步共识算法时,业务系统能够实时获取到交易执行结果。It is worth mentioning that in a blockchain using an asynchronous consensus algorithm, although the optimal load node device is a randomly designated node device, due to the introduction of the mandatory load balancing of transaction requests and transaction result query requests to the same node The load balancing mechanism of equipment processing can ensure that when the blockchain supports asynchronous consensus algorithms, the business system can obtain the transaction execution results in real time.
如前所述,接入程序中维护的连接池是用于维护用户客户端与区块链中的节点设备之间连接的,并且记录有各个节点设备的负载状况。As mentioned before, the connection pool maintained in the access program is used to maintain the connection between the user client and the node device in the blockchain, and records the load status of each node device.
交易请求可以分为与区块链交易相关的交易请求,以及与区块链交易无关的交易请求。其中,交易请求在执行前需要进行共识,即区块链中参与共识的节点设备在收到的交易请求后,首先需要对交易请求进行共识处理,在共识通过后才会进行处理,由区块链中作为记账节点的节点,将这笔交易打包进区块,在区块链中进行持久化存证。而交易请求在执行前不需要进行共识。Transaction requests can be divided into transaction requests related to blockchain transactions and transaction requests unrelated to blockchain transactions. Among them, the transaction request requires consensus before execution. That is, after receiving the transaction request, the node device participating in the consensus in the blockchain first needs to perform consensus processing on the transaction request. After the consensus is passed, the transaction request will be processed. The block The node in the chain, which serves as the accounting node, packages the transaction into a block and stores it permanently in the blockchain. Transaction requests do not require consensus before execution.
为此,本说明书中也可以对连接池进行分类,具体地,所述接入程序中可以维护基于与所述区块链中参与共识的各个节点设备之间的连接构成的第一连接池;以及,基于与所述区块链中不参与共识的各个节点设备之间的连接构成的第二连接池;To this end, connection pools can also be classified in this specification. Specifically, the access program can maintain a first connection pool based on connections with each node device participating in the consensus in the blockchain; And, a second connection pool based on connections with various node devices in the blockchain that do not participate in consensus;
相应地,所述步骤130中,从所述区块链中参与共识的节点设备中为所述交易请求分配目标节点设备,并将所述交易请求发送至分配的所述目标节点设备进行处理,进一步可以包括:Correspondingly, in step 130, a target node device is assigned to the transaction request from the node devices participating in the consensus in the blockchain, and the transaction request is sent to the assigned target node device for processing, Further can include:
从所述第一连接池中为所述交易请求分配目标连接,并基于所述目标连接将所述交易请求发送至与所述目标连接对应的目标节点设备进行处理;Allocate a target connection to the transaction request from the first connection pool, and send the transaction request to the target node device corresponding to the target connection for processing based on the target connection;
另外,所述步骤140中,从所述区块链中不参与共识的节点设备中为所述交易请求分配负载最优的节点设备,并将所述交易请求发送至该节点设备进行处理,进一步可以包括:In addition, in step 140, the node device with the optimal load is allocated to the transaction request from the node devices in the blockchain that do not participate in the consensus, and the transaction request is sent to the node device for processing, and further Can include:
从所述第二连接池中为所述交易请求分配目标连接,并基于所述目标连接将所述交易请求发送至与所述目标连接对应的目标节点设备进行处理。Allocate a target connection to the transaction request from the second connection pool, and send the transaction request to a target node device corresponding to the target connection for processing based on the target connection.
以下针对连接池的建立和更新进行说明:The following describes the establishment and update of the connection pool:
针对每个用户客户端,建立所述用户客户端与所述区块链中参与共识的节点设备之间连接的第一连接池,以及所述用户客户端与所述区块链中不参与共识的节点设备之间连接的第二连接池;For each user client, establish a first connection pool between the user client and the node device participating in the consensus in the blockchain, and the user client and the node device in the blockchain that do not participate in the consensus. The second connection pool for connections between node devices;
定时检测确定所述第一连接池和所述第二连接池中的连接是否可用,并基于检测结果对所述第一连接池和所述第二连接池中的连接添加指示所述连接为可用的可用标签,以更新所述用户客户端对应的连接池。Timing detection determines whether the connections in the first connection pool and the second connection pool are available, and based on the detection results, adds an indication that the connection is available to the connections in the first connection pool and the second connection pool. Available tags to update the connection pool corresponding to the user client.
一般的,用户客户端在启动时可以根据配置的区块链上各节点IP和端口,创建与各节点设备的连接,并且由连接池管理。同时,可以设置一个定时任务对连接池中的连接进行检测。定时任务可以向所有的连接发送异步查询请求,各节点设备在接收到异步查询请求后,可以返回响应数据。这样定时任务就可以根据与各节点设备对应的连接是否返回响应数据来更新连接池。Generally, when the user client is started, it can create a connection with each node device based on the configured IP and port of each node on the blockchain, and it is managed by the connection pool. At the same time, you can set up a scheduled task to detect the connections in the connection pool. Scheduled tasks can send asynchronous query requests to all connections, and each node device can return response data after receiving the asynchronous query request. In this way, the scheduled task can update the connection pool based on whether the connection corresponding to each node device returns response data.
相应的,前述从所述第一连接池中为所述交易请求分配目标连接,可以包括:Correspondingly, the aforementioned allocating a target connection for the transaction request from the first connection pool may include:
从所述第一连接池内被添加了可用标签的连接中为所述交易请求分配可用的目标连接;Allocate available target connections for the transaction request from the connections added with available tags in the first connection pool;
相应地,前述从所述第二连接池中为所述交易请求分配目标连接,可以包括:Correspondingly, the aforementioned allocating a target connection for the transaction request from the second connection pool may include:
从所述第二连接池内被添加了可用标签的连接中为所述交易请求分配可用的目标连接。Allocate available target connections for the transaction request from connections added with available tags in the second connection pool.
在一示例性的实施例中,所述定时确定所述第一连接池和所述第二连接池中的连接是否可用,包括:In an exemplary embodiment, the timing to determine whether connections in the first connection pool and the second connection pool are available includes:
定时向所述第一连接池和所述第二连接池中的连接对应的节点设备发送异步查询请求;Regularly sending asynchronous query requests to node devices corresponding to connections in the first connection pool and the second connection pool;
如果在预设的时间戳范围内接收到所述节点设备返回的响应数据,则确定该连接可用(将所述连接池中与该节点设备之间的连接标记为可用);If the response data returned by the node device is received within the preset timestamp range, determine that the connection is available (mark the connection between the connection pool and the node device as available);
如果在预设的时间戳范围内未接收到所述节点设备返回的响应数据,则确定该连接不可用(将所述连接池中与该节点设备之间的连接标记为不可用)。If no response data returned by the node device is received within a preset timestamp range, it is determined that the connection is unavailable (the connection between the connection pool and the node device is marked as unavailable).
该实施例中,如果区块链中有节点设备未返回响应数据,则定时任务的超时机制会自动确认超时,从而将与该节点设备的连接标记为不可用。而在负载均衡时,不可用的节点设备显然是不能使用的,只能从连接池中可用的连接中确定目标节点设备。另外,由于区块链中节点设备的负载状况是经常发送变化的,因此通过定时任务可以周期性更新连接池,更新各节点设备最新的负载状况。In this embodiment, if there is a node device in the blockchain that does not return response data, the timeout mechanism of the scheduled task will automatically confirm the timeout, thereby marking the connection with the node device as unavailable. During load balancing, unavailable node devices obviously cannot be used, and the target node device can only be determined from the available connections in the connection pool. In addition, since the load status of node equipment in the blockchain often changes, the connection pool can be updated periodically through scheduled tasks to update the latest load status of each node equipment.
其中,所述预设的时间戳范围包括与所述区块链中指定区块对应的时间戳范围。例如,区块链中最新的一个区块对应的时间戳范围,或者区块链中最近的若干区块对应的时间戳范围。Wherein, the preset timestamp range includes a timestamp range corresponding to a specified block in the blockchain. For example, the timestamp range corresponding to the latest block in the blockchain, or the timestamp range corresponding to the most recent blocks in the blockchain.
综上所述,本说明书提供了一种负载均衡方案,通过为区块链支持的不同类型的共识算法设置对应不同的负载均衡策略,以适配不同类型的共识算法导致的负载差异;如此,针对用户提交的与区块链交易相关的交易请求,可以根据对该交易请求进行共识的共识算法所对应的负载均衡策略,从所述区块链中参与共识的节点设备中为所述交易请求分配目标节点设备进行处理。由于负载均衡策略考虑了共识算法的负载差异,因此分配的目标节点设备是当前最优的节点设备,基于目标节点设备可以快速响应交易请求,从而可以避免部分节点设备负载过多导致响应缓慢的问题。To sum up, this specification provides a load balancing solution that adapts to the load differences caused by different types of consensus algorithms by setting different load balancing strategies for different types of consensus algorithms supported by the blockchain; thus, For a transaction request related to a blockchain transaction submitted by a user, the transaction request can be processed from the node devices participating in the consensus in the blockchain according to the load balancing strategy corresponding to the consensus algorithm for the transaction request. Assign target node devices for processing. Since the load balancing strategy takes into account the load difference of the consensus algorithm, the allocated target node device is the current optimal node device. Based on the target node device, the transaction request can be quickly responded to, thereby avoiding the problem of slow response caused by excessive load on some node devices. .
与上述方法实施例相对应,本说明书还提供了一种负载均衡装置的实施例。Corresponding to the above method embodiments, this specification also provides an embodiment of a load balancing device.
本说明书的负载均衡装置的实施例可以应用在电子设备上。装置实施例可以通过软件实现,也可以通过硬件或者软硬件结合的方式实现。以软件实现为例,作为一个逻辑意义上的装置,是通过其所在电子设备的处理器将非易失性存储器中对应的计算机程序指令读取到内存中运行形成的。The embodiments of the load balancing device in this specification can be applied to electronic equipment. The device embodiments may be implemented by software, or may be implemented by hardware or a combination of software and hardware. Taking software implementation as an example, as a logical device, it is formed by reading the corresponding computer program instructions in the non-volatile memory into the memory and running them through the processor of the electronic device where it is located.
从硬件层面而言,如图3所示,为本说明书的负载均衡装置所在电子设备的一种硬件结构图,除了图3所示的处理器、内存、网络接口、以及非易失性存储器之外,实施例中装置所在的电子设备通常根据该电子设备的实际功能,还可以包括其他硬件,对此不再赘述。From the hardware level, as shown in Figure 3, it is a hardware structure diagram of the electronic equipment where the load balancing device of this specification is located. In addition to the processor, memory, network interface, and non-volatile memory shown in Figure 3 In addition, the electronic device where the device in the embodiment is located may also include other hardware according to the actual functions of the electronic device, which will not be described again.
图4是本说明书一示例性实施例示出的一种负载均衡装置的框图。所述负载均衡装置可以应用于与区块链对应的接入程序,所述装置包括:FIG. 4 is a block diagram of a load balancing device according to an exemplary embodiment of this specification. The load balancing device can be applied to the access program corresponding to the blockchain, and the device includes:
接收单元410,接收用户提交的交易请求;The receiving unit 410 receives the transaction request submitted by the user;
确定单元420,响应于接收到的用户提交的交易请求,确定所述交易请求的类型;The determining unit 420 determines the type of the transaction request in response to the received transaction request submitted by the user;
均衡单元430,在所述交易请求为与区块链交易相关的交易请求时,基于与所述区块链支持的共识算法对应的负载均衡策略,从所述区块链中参与共识的节点设备中为所述交易请求分配目标节点设备,并将所述交易请求发送至分配的所述目标节点设备进行处理;其中,所述区块链支持的不同类型的共识算法,分别对应不同的负载均衡策略。The balancing unit 430, when the transaction request is a transaction request related to a blockchain transaction, based on the load balancing strategy corresponding to the consensus algorithm supported by the blockchain, node devices participating in the consensus from the blockchain Allocate target node equipment to the transaction request in , and send the transaction request to the allocated target node equipment for processing; wherein, the different types of consensus algorithms supported by the blockchain respectively correspond to different load balancing Strategy.
可选的,所述均衡单元430,还用于在所述交易请求为与区块链交易无关的交易请求时,基于预设的负载均衡策略,从所述区块链中不参与共识的节点设备中为所述交易请求分配负载最优的节点设备,并将所述交易请求发送至该节点设备进行处理。Optionally, the balancing unit 430 is also configured to remove nodes from the blockchain that do not participate in the consensus based on a preset load balancing strategy when the transaction request is a transaction request that is not related to a blockchain transaction. The device allocates the node device with the optimal load for the transaction request, and sends the transaction request to the node device for processing.
可选的,所述区块链支持的共识算法包括异步共识算法;所述与区块链交易相关的交易请求包括区块链交易和针对区块链交易的查询请求;Optionally, the consensus algorithm supported by the blockchain includes an asynchronous consensus algorithm; the transaction requests related to blockchain transactions include blockchain transactions and query requests for blockchain transactions;
所述均衡单元430,还用于在所述交易请求为区块链交易时,基于与所述异步共识算法对应的负载均衡策略,从所述区块链中参与共识的节点设备中为所述区块链交易分配最优负载的目标节点设备,并建立所述区块链交易与所述目标节点设备的绑定关系;以及,在所述交易请求为与区块链交易对应的查询请求,基于与所述异步共识算法对应的负载均衡策略,查询所述绑定关系,将与所述区块链交易绑定的目标节点设备分配给所述查询请求。The balancing unit 430 is also configured to, when the transaction request is a blockchain transaction, based on the load balancing strategy corresponding to the asynchronous consensus algorithm, from the node devices participating in the consensus in the blockchain, for the The blockchain transaction allocates the target node device with the optimal load, and establishes a binding relationship between the blockchain transaction and the target node device; and, when the transaction request is a query request corresponding to the blockchain transaction, Based on the load balancing strategy corresponding to the asynchronous consensus algorithm, the binding relationship is queried, and the target node device bound to the blockchain transaction is assigned to the query request.
可选的,所述区块链支持的共识算法还包括同步共识算法;Optionally, the consensus algorithm supported by the blockchain also includes a synchronous consensus algorithm;
所述均衡单元430,还用于基于与所述同步共识算法对应的负载均衡策略,从所述区块链中参与共识的节点设备中为所述交易请求分配最优负载的目标节点设备。The balancing unit 430 is also configured to allocate the target node device with the optimal load for the transaction request from the node devices participating in the consensus in the blockchain based on the load balancing strategy corresponding to the synchronous consensus algorithm.
可选的,所述最优负载的节点设备包括随机指定的节点设备。Optionally, the optimally loaded node device includes a randomly designated node device.
可选的,所述同步共识算法包括pbft共识算法;所述异步共识算法包括honeybadger共识算法。Optionally, the synchronous consensus algorithm includes the pbft consensus algorithm; the asynchronous consensus algorithm includes the honeybadger consensus algorithm.
可选的,所述接入程序包括用于接入区块链的SDK程序。Optionally, the access program includes an SDK program for accessing the blockchain.
可选的,所述SDK程序包括用户客户端搭载的SDK接入程序;Optionally, the SDK program includes an SDK access program installed on the user client;
所述接收单元410,还用于获取用户在所述用户客户端上发起的交易请求。The receiving unit 410 is also used to obtain the transaction request initiated by the user on the user client.
可选的,所述SDK程序包括区块链服务平台上搭载的与用户客户端对应的SDK接入服务程序;Optionally, the SDK program includes an SDK access service program corresponding to the user client mounted on the blockchain service platform;
所述接收单元410,还用于接收所述用户客户端通过调用所述区块链服务平台上部署的与所述SDK接入服务程序对应服务接口提交的交易请求。The receiving unit 410 is also configured to receive a transaction request submitted by the user client by calling the service interface deployed on the blockchain service platform and corresponding to the SDK access service program.
可选的,所述接入程序维护了基于与所述区块链中参与共识的各个节点设备之间的连接构成的第一连接池;以及,基于与所述区块链中不参与共识的各个节点设备之间的连接构成的第二连接池;Optionally, the access program maintains a first connection pool based on connections with each node device that participates in consensus in the blockchain; and, based on connections with nodes that do not participate in consensus in the blockchain A second connection pool composed of connections between various node devices;
所述均衡单元430中从所述区块链中参与共识的节点设备中为所述交易请求分配目标节点设备,并将所述交易请求发送至分配的所述目标节点设备进行处理,包括:The balancing unit 430 allocates a target node device for the transaction request from the node devices participating in the consensus in the blockchain, and sends the transaction request to the assigned target node device for processing, including:
从所述第一连接池中为所述交易请求分配目标连接,并基于所述目标连接将所述交易请求发送至与所述目标连接对应的目标节点设备进行处理;Allocate a target connection to the transaction request from the first connection pool, and send the transaction request to the target node device corresponding to the target connection for processing based on the target connection;
所述均衡单元430中从所述区块链中不参与共识的节点设备中为所述交易请求分配负载最优的节点 设备,并将所述交易请求发送至该节点设备进行处理,包括:The balancing unit 430 allocates the node device with the optimal load for the transaction request from the node devices that do not participate in the consensus in the blockchain, and sends the transaction request to the node device for processing, including:
从所述第二连接池中为所述交易请求分配目标连接,并基于所述目标连接将所述交易请求发送至与所述目标连接对应的目标节点设备进行处理。Allocate a target connection to the transaction request from the second connection pool, and send the transaction request to a target node device corresponding to the target connection for processing based on the target connection.
可选的,所述装置还包括:Optionally, the device also includes:
检测单元,定时检测确定所述第一连接池和所述第二连接池中的连接是否可用,并基于检测结果对所述第一连接池和所述第二连接池中的连接添加指示所述连接为可用的可用标签;A detection unit that periodically detects and determines whether the connections in the first connection pool and the second connection pool are available, and adds the indication to the connections in the first connection pool and the second connection pool based on the detection results. Connect to available tags available;
所述均衡单元430中从所述第一连接池中为所述交易请求分配目标连接,包括:The balancing unit 430 allocates a target connection for the transaction request from the first connection pool, including:
从所述第一连接池内被添加了可用标签的连接中为所述交易请求分配可用的目标连接;Allocate available target connections for the transaction request from the connections added with available tags in the first connection pool;
所述均衡单元430中从所述第二连接池中为所述交易请求分配目标连接,包括:The balancing unit 430 allocates a target connection for the transaction request from the second connection pool, including:
从所述第二连接池内被添加了可用标签的连接中为所述交易请求分配可用的目标连接。Allocate available target connections for the transaction request from connections added with available tags in the second connection pool.
可选的,所述检测单元,还用于定时向所述第一连接池和所述第二连接池中的连接对应的节点设备发送异步查询请求;如果在预设的时间戳范围内接收到所述节点设备返回的响应数据,则确定该连接可用;如果在预设的时间戳范围内未接收到所述节点设备返回的响应数据,则确定该连接不可用。Optionally, the detection unit is also configured to regularly send an asynchronous query request to the node device corresponding to the connection in the first connection pool and the second connection pool; if the request is received within the preset timestamp range, If the response data returned by the node device is received, it is determined that the connection is available; if the response data returned by the node device is not received within the preset timestamp range, the connection is determined to be unavailable.
可选的,所述预设的时间戳范围包括与所述区块链中指定区块对应的时间戳范围。Optionally, the preset timestamp range includes a timestamp range corresponding to a specified block in the blockchain.
上述实施例阐明的系统、装置、模块或单元,具体可以由计算机芯片或实体实现,或者由具有某种功能的产品来实现。一种典型的实现设备为计算机,计算机的具体形式可以是个人计算机、膝上型计算机、蜂窝电话、相机电话、智能电话、个人数字助理、媒体播放器、导航设备、电子邮件收发设备、游戏控制台、平板计算机、可穿戴设备或者这些设备中的任意几种设备的组合。The systems, devices, modules or units described in the above embodiments may be implemented by computer chips or entities, or by products with certain functions. A typical implementation device is a computer, which may be in the form of a personal computer, a laptop, a cellular phone, a camera phone, a smart phone, a personal digital assistant, a media player, a navigation device, an email transceiver, or a game controller. desktop, tablet, wearable device, or a combination of any of these devices.
在一个典型的配置中,计算机包括一个或多个处理器(CPU)、输入/输出接口、网络接口和内存。In a typical configuration, a computer includes one or more processors (CPUs), input/output interfaces, network interfaces, and memory.
内存可能包括计算机可读介质中的非永久性存储器,随机存取存储器(RAM)和/或非易失性内存等形式,如只读存储器(ROM)或闪存(flash RAM)。内存是计算机可读介质的示例。Memory may include non-permanent storage in computer-readable media, random access memory (RAM) and/or non-volatile memory in the form of read-only memory (ROM) or flash memory (flash RAM). Memory is an example of computer-readable media.
计算机可读介质包括永久性和非永久性、可移动和非可移动媒体可以由任何方法或技术来实现信息存储。信息可以是计算机可读指令、数据结构、程序的模块或其他数据。计算机的存储介质的例子包括,但不限于相变内存(PRAM)、静态随机存取存储器(SRAM)、动态随机存取存储器(DRAM)、其他类型的随机存取存储器(RAM)、只读存储器(ROM)、电可擦除可编程只读存储器(EEPROM)、快闪记忆体或其他内存技术、只读光盘只读存储器(CD-ROM)、数字多功能光盘(DVD)或其他光学存储、磁盒式磁带、磁盘存储、量子存储器、基于石墨烯的存储介质或其他磁性存储设备或任何其他非传输介质,可用于存储可以被计算设备访问的信息。按照本文中的界定,计算机可读介质不包括暂存电脑可读媒体(transitory media),如调制的数据信号和载波。Computer-readable media includes both persistent and non-volatile, removable and non-removable media that can be implemented by any method or technology for storage of information. Information may be computer-readable instructions, data structures, modules of programs, or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), and read-only memory. (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, Magnetic tape cartridges, magnetic disk storage, quantum memory, graphene-based storage media or other magnetic storage devices, or any other non-transmission medium, can be used to store information that can be accessed by computing devices. As defined in this article, computer-readable media does not include transitory media, such as modulated data signals and carrier waves.
还需要说明的是,术语“包括”、“包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程、方法、商品或者设备不仅包括那些要素,而且还包括没有明确列出的其他要素,或者是还包括为这种过程、方法、商品或者设备所固有的要素。在没有更多限制的情况下,由语句“包括一个……”限定的要素,并不排除在包括所述要素的过程、方法、商品或者设备中还存在另外的相同要素。It should also be noted that the terms "comprises," "comprises," or any other variation thereof are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that includes a list of elements not only includes those elements, but also includes Other elements are not expressly listed or are inherent to the process, method, article or equipment. Without further limitation, an element defined by the statement "comprises a..." does not exclude the presence of additional identical elements in a process, method, article, or device that includes the stated element.
上述对本说明书特定实施例进行了描述。其它实施例在所附权利要求书的范围内。在一些情况下,在权利要求书中记载的动作或步骤可以按照不同于实施例中的顺序来执行并且仍然可以实现期望的结果。另外,在附图中描绘的过程不一定要求示出的特定顺序或者连续顺序才能实现期望的结果。在某些实现方式中,多任务处理和并行处理也是可以的或者可能是有利的。The foregoing describes specific embodiments of this specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recited in the claims can be performed in a different order than in the embodiments and still achieve desired results. Additionally, the processes depicted in the figures do not necessarily require the specific order shown, or sequential order, to achieve desirable results. In some implementations, multitasking and parallel processing are also possible or may be advantageous.
在本说明书一个或多个实施例使用的术语是仅仅出于描述特定实施例的目的,而非旨在限制本说明书一个或多个实施例。在本说明书一个或多个实施例和所附权利要求书中所使用的单数形式的“一种”、“所述”和“该”也旨在包括多数形式,除非上下文清楚地表示其他含义。还应当理解,本文中使用的术语“和/或”是指并包含一个或多个相关联的列出项目的任何或所有可能组合。The terminology used in one or more embodiments of this specification is for the purpose of describing particular embodiments only and is not intended to limit the one or more embodiments of this specification. As used in one or more embodiments of this specification and the appended claims, the singular forms "a," "the" and "the" are intended to include the plural forms as well, unless the context clearly dictates otherwise. It will also be understood that the term "and/or" as used herein refers to and includes any and all possible combinations of one or more of the associated listed items.
应当理解,尽管在本说明书一个或多个实施例可能采用术语第一、第二、第三等来描述各种信息, 但这些信息不应限于这些术语。这些术语仅用来将同一类型的信息彼此区分开。例如,在不脱离本说明书一个或多个实施例范围的情况下,第一信息也可以被称为第二信息,类似地,第二信息也可以被称为第一信息。取决于语境,如在此所使用的词语“如果”可以被解释成为“在……时”或“当……时”或“响应于确定”。It should be understood that although one or more embodiments of this specification may use the terms first, second, third, etc. to describe various information, the information should not be limited to these terms. These terms are only used to distinguish information of the same type from each other. For example, without departing from the scope of one or more embodiments of this specification, the first information may also be called second information, and similarly, the second information may also be called first information. Depending on the context, the word "if" as used herein may be interpreted as "when" or "when" or "in response to determining."
以上所述仅为本说明书一个或多个实施例的较佳实施例而已,并不用以限制本说明书一个或多个实施例,凡在本说明书一个或多个实施例的精神和原则之内,所做的任何修改、等同替换、改进等,均应包含在本说明书一个或多个实施例保护的范围之内。The above are only preferred embodiments of one or more embodiments of this specification, and are not intended to limit one or more embodiments of this specification. Within the spirit and principles of one or more embodiments of this specification, Any modifications, equivalent substitutions, improvements, etc. shall be included in the scope of protection of one or more embodiments of this specification.

Claims (14)

  1. 一种负载均衡方法,应用于与区块链对应的接入程序,所述方法包括:A load balancing method, applied to the access program corresponding to the blockchain, the method includes:
    接收用户提交的交易请求;Receive transaction requests submitted by users;
    响应于接收到的用户提交的交易请求,确定所述交易请求的类型;In response to receiving a transaction request submitted by the user, determining the type of the transaction request;
    如果所述交易请求为与区块链交易相关的交易请求,基于与所述区块链支持的共识算法对应的负载均衡策略,从所述区块链中参与共识的节点设备中为所述交易请求分配目标节点设备,并将所述交易请求发送至分配的所述目标节点设备进行处理;其中,所述区块链支持的不同类型的共识算法,分别对应不同的负载均衡策略。If the transaction request is a transaction request related to a blockchain transaction, based on the load balancing strategy corresponding to the consensus algorithm supported by the blockchain, the node device participating in the consensus in the blockchain provides the transaction with Request allocation of target node equipment, and send the transaction request to the allocated target node equipment for processing; wherein, different types of consensus algorithms supported by the blockchain respectively correspond to different load balancing strategies.
  2. 根据权利要求1所述的方法,所述方法还包括:The method of claim 1, further comprising:
    如果所述交易请求为与区块链交易无关的交易请求,基于预设的负载均衡策略,从所述区块链中不参与共识的节点设备中为所述交易请求分配负载最优的节点设备,并将所述交易请求发送至该节点设备进行处理。If the transaction request is a transaction request that is not related to the blockchain transaction, based on the preset load balancing strategy, allocate the node device with the optimal load to the transaction request from the node devices that do not participate in the consensus in the blockchain. , and send the transaction request to the node device for processing.
  3. 根据权利要求1所述的方法,所述区块链支持的共识算法包括异步共识算法;所述与区块链交易相关的交易请求包括区块链交易和针对区块链交易的查询请求;According to the method of claim 1, the consensus algorithm supported by the blockchain includes an asynchronous consensus algorithm; the transaction request related to the blockchain transaction includes a blockchain transaction and a query request for the blockchain transaction;
    所述基于与所述区块链支持的共识算法对应的负载均衡策略,从所述区块链中参与共识的节点设备中为所述交易请求分配目标节点设备,包括:The method of allocating a target node device to the transaction request from the node devices participating in the consensus in the blockchain based on the load balancing strategy corresponding to the consensus algorithm supported by the blockchain includes:
    如果所述交易请求为区块链交易,基于与所述异步共识算法对应的负载均衡策略,从所述区块链中参与共识的节点设备中为所述区块链交易分配最优负载的目标节点设备,并建立所述区块链交易与所述目标节点设备的绑定关系;If the transaction request is a blockchain transaction, based on the load balancing strategy corresponding to the asynchronous consensus algorithm, the target of allocating the optimal load to the blockchain transaction from the node devices participating in the consensus in the blockchain Node equipment, and establish a binding relationship between the blockchain transaction and the target node equipment;
    如果所述交易请求为与区块链交易对应的查询请求,基于与所述异步共识算法对应的负载均衡策略,查询所述绑定关系,将与所述区块链交易绑定的目标节点设备分配给所述查询请求。If the transaction request is a query request corresponding to a blockchain transaction, based on the load balancing strategy corresponding to the asynchronous consensus algorithm, the binding relationship is queried, and the target node device bound to the blockchain transaction is assigned to the query request.
  4. 根据权利要求3所述的方法,所述区块链支持的共识算法还包括同步共识算法;According to the method of claim 3, the consensus algorithm supported by the blockchain further includes a synchronous consensus algorithm;
    所述基于与所述区块链支持的共识算法对应的负载均衡策略,从所述区块链中参与共识的节点设备中为所述交易请求分配目标节点设备,包括:The method of allocating a target node device to the transaction request from the node devices participating in the consensus in the blockchain based on the load balancing strategy corresponding to the consensus algorithm supported by the blockchain includes:
    基于与所述同步共识算法对应的负载均衡策略,从所述区块链中参与共识的节点设备中为所述交易请求分配最优负载的目标节点设备。Based on the load balancing strategy corresponding to the synchronous consensus algorithm, the target node device with the optimal load is allocated to the transaction request from the node devices participating in the consensus in the blockchain.
  5. 根据权利要求2-4中任一所述的方法,所述最优负载的节点设备包括随机指定的节点设备。According to the method of any one of claims 2-4, the optimally loaded node device includes a randomly designated node device.
  6. 根据权利要求4所述的方法,所述同步共识算法包括pbft共识算法;所述异步共识算法包括honeybadger共识算法。According to the method of claim 4, the synchronous consensus algorithm includes the pbft consensus algorithm; the asynchronous consensus algorithm includes the honeybadger consensus algorithm.
  7. 根据权利要求1所述的方法,所述接入程序包括用于接入区块链的SDK程序。According to the method of claim 1, the access program includes an SDK program for accessing the blockchain.
  8. 根据权利要求7所述的方法,所述SDK程序包括用户客户端搭载的SDK接入程序;According to the method of claim 7, the SDK program includes an SDK access program installed on the user client;
    所述接收用户提交的交易请求,包括:The reception of transaction requests submitted by users includes:
    获取用户在所述用户客户端上发起的交易请求。Obtain the transaction request initiated by the user on the user client.
  9. 根据权利要求7所述的方法,所述SDK程序包括区块链服务平台上搭载的与用户客户端对应的SDK接入服务程序;According to the method of claim 7, the SDK program includes an SDK access service program corresponding to the user client mounted on the blockchain service platform;
    所述接收用户提交的交易请求,包括:The reception of transaction requests submitted by users includes:
    接收所述用户客户端通过调用所述区块链服务平台上部署的与所述SDK接入服务程序对应服务接口提交的交易请求。Receive a transaction request submitted by the user client by calling a service interface deployed on the blockchain service platform corresponding to the SDK access service program.
  10. 根据权利要求2所述的方法,所述接入程序维护了基于与所述区块链中参与共识的各个节点设备之间的连接构成的第一连接池;以及,基于与所述区块链中不参与共识的各个节点设备之间的连接构成的第二连接池;所述方法还包括:According to the method of claim 2, the access program maintains a first connection pool based on connections with each node device participating in consensus in the blockchain; and, based on connections with the blockchain A second connection pool composed of connections between node devices that do not participate in the consensus; the method also includes:
    定时检测确定所述第一连接池和所述第二连接池中的连接是否可用,并基于检测结果对所述第一连接池和所述第二连接池中的连接添加指示所述连接为可用的可用标签;Timing detection determines whether the connections in the first connection pool and the second connection pool are available, and based on the detection results, adds an indication that the connection is available to the connections in the first connection pool and the second connection pool. available tags;
    所述从所述第一连接池中为所述交易请求分配目标连接,包括:Allocating a target connection for the transaction request from the first connection pool includes:
    从所述第一连接池内被添加了可用标签的连接中为所述交易请求分配可用的目标连接;Allocate available target connections for the transaction request from the connections added with available tags in the first connection pool;
    所述从所述第二连接池中为所述交易请求分配目标连接,包括:Allocating a target connection for the transaction request from the second connection pool includes:
    从所述第二连接池内被添加了可用标签的连接中为所述交易请求分配可用的目标连接。Allocate available target connections for the transaction request from connections added with available tags in the second connection pool.
  11. 根据权利要求10所述的方法,所述定时确定所述第一连接池和所述第二连接池中的连接是否可用,包括:The method according to claim 10, the timing of determining whether connections in the first connection pool and the second connection pool are available includes:
    定时向所述第一连接池和所述第二连接池中的连接对应的节点设备发送异步查询请求;Regularly sending asynchronous query requests to node devices corresponding to connections in the first connection pool and the second connection pool;
    如果在预设的时间戳范围内接收到所述节点设备返回的响应数据,则确定该连接可用;If the response data returned by the node device is received within the preset timestamp range, it is determined that the connection is available;
    如果在预设的时间戳范围内未接收到所述节点设备返回的响应数据,则确定该连接不可用。If the response data returned by the node device is not received within the preset timestamp range, it is determined that the connection is unavailable.
  12. 根据权利要求11所述的方法,所述预设的时间戳范围包括与所述区块链中指定区块对应的时间戳范围。According to the method of claim 11, the preset timestamp range includes a timestamp range corresponding to a specified block in the blockchain.
  13. 一种负载均衡装置,应用于与区块链对应的接入程序,所述装置包括:A load balancing device, applied to the access program corresponding to the blockchain, the device includes:
    接收单元,接收用户提交的交易请求;The receiving unit receives transaction requests submitted by users;
    确定单元,响应于接收到的用户提交的交易请求,确定所述交易请求的类型;a determining unit that determines the type of the transaction request in response to the received transaction request submitted by the user;
    均衡单元,在所述交易请求为与区块链交易相关的交易请求时,基于与所述区块链支持的共识算法对应的负载均衡策略,从所述区块链中参与共识的节点设备中为所述交易请求分配目标节点设备,并将所述交易请求发送至分配的所述目标节点设备进行处理;其中,所述区块链支持的不同类型的共识算法,分别对应不同的负载均衡策略。A balancing unit, when the transaction request is a transaction request related to a blockchain transaction, based on the load balancing strategy corresponding to the consensus algorithm supported by the blockchain, from the node devices participating in the consensus in the blockchain Allocate a target node device to the transaction request, and send the transaction request to the assigned target node device for processing; wherein, different types of consensus algorithms supported by the blockchain correspond to different load balancing strategies. .
  14. 一种电子设备,包括:An electronic device including:
    处理器;processor;
    用于存储处理器可执行指令的存储器;Memory used to store instructions executable by the processor;
    其中,所述处理器通过运行所述可执行指令以实现如权利要求1-12中任一项所述的方法。Wherein, the processor implements the method according to any one of claims 1-12 by running the executable instructions.
PCT/CN2022/135418 2022-04-29 2022-11-30 Load balance method and apparatus, and electronic device WO2023207082A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202210473991.X 2022-04-29
CN202210473991.XA CN114884962B (en) 2022-04-29 2022-04-29 Load balancing method and device and electronic equipment

Publications (1)

Publication Number Publication Date
WO2023207082A1 true WO2023207082A1 (en) 2023-11-02

Family

ID=82673009

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2022/135418 WO2023207082A1 (en) 2022-04-29 2022-11-30 Load balance method and apparatus, and electronic device

Country Status (2)

Country Link
CN (1) CN114884962B (en)
WO (1) WO2023207082A1 (en)

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114884962B (en) * 2022-04-29 2024-03-26 蚂蚁区块链科技(上海)有限公司 Load balancing method and device and electronic equipment
CN117034361A (en) * 2023-07-31 2023-11-10 广州承启医学检验有限公司 Gene detection and inspection laboratory information management method and system

Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111181715A (en) * 2019-12-30 2020-05-19 杭州云象网络技术有限公司 Multi-party cross-linking method based on consistent Hash consensus protocol
CN111600967A (en) * 2020-07-24 2020-08-28 江苏荣泽信息科技股份有限公司 Access pressure-based load balancing system among block chain nodes
US20200344290A1 (en) * 2019-03-18 2020-10-29 Reliance Jio Infocomm Limited Systems and methods for microservice execution load balancing in virtual distributed ledger networks
CN112087502A (en) * 2020-08-28 2020-12-15 成都质数斯达克科技有限公司 Method, device and equipment for processing request and storage medium
CN112434114A (en) * 2021-01-26 2021-03-02 腾讯科技(深圳)有限公司 Electronic bill processing method, electronic bill processing device, electronic bill processing medium, and electronic apparatus
CN113761068A (en) * 2021-09-15 2021-12-07 虎彩印艺股份有限公司 Method for improving concurrent processing capacity of block chain network
CN114884962A (en) * 2022-04-29 2022-08-09 蚂蚁区块链科技(上海)有限公司 Load balancing method and device and electronic equipment

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US11386405B2 (en) * 2017-12-19 2022-07-12 International Business Machines Corporation Dynamic blockchain transactional policy management
CN111464633B (en) * 2020-03-31 2023-03-21 成都质数斯达克科技有限公司 Consensus method and system for transaction information of block chain
CN111786952B (en) * 2020-05-29 2023-03-17 中国银联股份有限公司 Consensus method, apparatus, device, and medium for block chain system
CN115114009A (en) * 2021-03-17 2022-09-27 中移(上海)信息通信科技有限公司 Data query method, master node and slave nodes

Patent Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20200344290A1 (en) * 2019-03-18 2020-10-29 Reliance Jio Infocomm Limited Systems and methods for microservice execution load balancing in virtual distributed ledger networks
CN111181715A (en) * 2019-12-30 2020-05-19 杭州云象网络技术有限公司 Multi-party cross-linking method based on consistent Hash consensus protocol
CN111600967A (en) * 2020-07-24 2020-08-28 江苏荣泽信息科技股份有限公司 Access pressure-based load balancing system among block chain nodes
CN112087502A (en) * 2020-08-28 2020-12-15 成都质数斯达克科技有限公司 Method, device and equipment for processing request and storage medium
CN112434114A (en) * 2021-01-26 2021-03-02 腾讯科技(深圳)有限公司 Electronic bill processing method, electronic bill processing device, electronic bill processing medium, and electronic apparatus
CN113761068A (en) * 2021-09-15 2021-12-07 虎彩印艺股份有限公司 Method for improving concurrent processing capacity of block chain network
CN114884962A (en) * 2022-04-29 2022-08-09 蚂蚁区块链科技(上海)有限公司 Load balancing method and device and electronic equipment

Also Published As

Publication number Publication date
CN114884962A (en) 2022-08-09
CN114884962B (en) 2024-03-26

Similar Documents

Publication Publication Date Title
WO2023207082A1 (en) Load balance method and apparatus, and electronic device
CN108829350B (en) Data migration method and device based on block chain
US11553034B2 (en) Server computer management system for supporting highly available virtual desktops of multiple different tenants
TWI752939B (en) Method and device for processing user request
RU2649788C1 (en) Method and system for transaction request processing in distributed data processing systems
KR101959153B1 (en) System for efficient processing of transaction requests related to an account in a database
CN111898139B (en) Data reading and writing method and device and electronic equipment
US8117611B2 (en) Method, system, and program product for deploying a platform dependent application in a grid environment
US20080256248A1 (en) Single server access in a multiple tcp/ip instance environment
WO2020024650A1 (en) Data processing method and apparatus, and client
WO2017113962A1 (en) Method of accessing distributed database and device providing distributed data service
TW202025057A (en) Field updating method and device and electronic equipment
US20200052885A1 (en) File storage method and apparatus for blockchain network
WO2017201984A1 (en) Data processing method, associated apparatus, and data storage system
WO2021067156A1 (en) Nested tenancy that permits a hierarchy having a plurality of levels
WO2020024648A1 (en) Data processing method and device, client, and server
WO2023040502A1 (en) User service registration
JP2005503596A5 (en)
WO2023040498A1 (en) User service utilization
US11947534B2 (en) Connection pools for parallel processing applications accessing distributed databases
TW201727517A (en) Data storage and service processing method and device
CN115002228A (en) Service cascade calling method and device, electronic equipment and storage medium
JPH0962635A (en) Customer information control system and method having transaction-serialization control function in loosely-coupled parallel processing environment
CN114036031A (en) Scheduling system and method for resource service application in enterprise digital middleboxes
WO2023207087A1 (en) Optimal-link selection method and apparatus for blockchain, and electronic device

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 22939896

Country of ref document: EP

Kind code of ref document: A1