Disclosure of Invention
The invention aims to provide a load balancing system among block chain nodes based on access pressure, aiming at solving the problem that when the access pressure of a single block chain node in the existing block chain is high, the single block chain node is punctured, so that an avalanche condition can occur in a block chain node cluster due to too high pressure; the transaction request is executed by the selected node, and the transaction request is reasonably distributed by the load balancing module, so that the node resources in the whole block chain are efficiently used.
The purpose of the invention can be realized by the following technical scheme: a load balancing system among block chain nodes based on access pressure comprises a data acquisition module, a server, a data analysis module and a load balancing module;
the data acquisition module is used for acquiring the consumed resource information of the transaction request and sending the consumed resource information to the server; the data analysis module is used for acquiring consumption resource information stored in the server and analyzing the consumption resource information, and the specific analysis steps are as follows:
the method comprises the following steps: setting a transaction request as Pi, i =1, … …, n; setting the memory occupation value consumed by executing transaction request as NjPi(ii) a The CPU occupation value consumed by the execution of the transaction request is DjPi(ii) a j =1, … …, n; j represents the number of executions of the transaction request;
step two: carrying out dequantization processing on the memory occupation value and the CPU occupation value and taking the numerical values of the memory occupation value and the CPU occupation value;
using formulas
Obtaining the average consumption value Z of the transaction request
Pi(ii) a Wherein, b1 and b2 are both preset proportionality coefficients;
step three: the data analysis module sends the average consumption value of the transaction request to a server for storage;
the load balancing module is used for carrying out load balancing adjustment on the transaction request, and the specific adjustment steps are as follows:
s1: the user sends a transaction request to the load balancing module through the client, and after receiving the transaction request, the load balancing module matches the transaction request with all transaction requests stored in the server to obtain an average consumption value Z of the corresponding transaction requestPa(ii) a a belongs to i, and simultaneously the load balancing module generates a node analysis instruction;
s2: the load balancing module sends the node analysis instruction to the node analysis module, and the node analysis module sends the node execution value of the block chain node to the load balancing module after analyzing;
s3: the load balancing module enables the node execution value to be larger than the average consumption value ZPaMarking the block chain link points as initial selection nodes; setting the initially selected node as Jk, wherein k is a positive integer;
s4: the load balancing module generates an access instruction corresponding to the initially selected node and sends the access instruction to the node counting module, and the node counting module receives and processes the access instruction corresponding to the initially selected node to obtain a block value of the initially selected node and sends the block value to the load balancing module;
s5: marking the node execution value of the primary selection node as ZJk(ii) a Marking the block value of the primary selection node as QJk(ii) a Carrying out dequantization processing on the node execution value and the block value and taking the numerical value of the node execution value and the block value;
s6: using the formula FJk=ZJk×b3+QJkObtaining x b 4-mu to obtain the node kiss value F of the primary selected nodeJk(ii) a Wherein b3 and b4 are both preset proportionality coefficients, mu is an error correction factor, and the value is 2.3863;
s7: and selecting the initial selection node with the maximum node kiss value as the selected node of the transaction request, and executing the transaction request through the selected node.
Preferably, the system further comprises a node acquisition module and a node analysis module, wherein the node acquisition module is used for acquiring node information of the block chain node and sending the node information to the node analysis module; the node information comprises the residual memory value of the block chain node and the real-time residual utilization rate of the CPU; the node analysis module is used for receiving node information and analyzing the node information, and the specific analysis steps are as follows:
SS 1: after receiving the node analysis instruction, the node analysis module analyzes the node information and sets the residual memory value of the block chain node to be D1;
SS 2: counting the real-time residual utilization rate of the CPU, and setting the residual utilization rate to be Lm, wherein m =0 and … … 99; and the value range of Lm is (0, 1)]The number of occurrences of remaining usage is counted and labeled as ELm;
SS 3: selecting the residual utilization rate with the largest occurrence frequency, and marking the residual utilization rate as Lb, wherein b belongs to m;
SS 4: summing the times of other residual utilization rates to obtain a total occurrence time EZ;
SS 5: dequantizing the residual memory value, the residual utilization rate and the residual utilization rate, and taking the values of the dequantization residual memory value, the residual utilization rate and the residual utilization rate, and obtaining a node execution value Z of the block chain node by using a formula Z = D1 × b5+ Lb × b6-EZ × b7+ lambda; b5, b6 and b7 are all preset proportionality coefficients, and lambda is a correction constant and takes the value of 1.32;
SS 6: and the node analysis module sends the node execution value to the load balancing module.
Preferably, the consumed resource information is a resource consumed when the transaction request is executed, and the resource includes a memory occupation value and a CPU occupation value.
Preferably, the specific processing steps of the node statistics module in step S4 to obtain the block value of the initially selected node include:
s41: acquiring equipment information of the primary selection node, setting all CPU models to be preset values, matching the CPU models in the equipment information with all the CPU models to obtain corresponding preset values, and marking as Y1Jk;
S42: calculating the time difference between the purchase time in the equipment information and the current time of the system to obtain the purchase duration of the equipment and marking the purchase duration as T1JkThe unit is day;
s43: set the rated memory of the device to Y2Jk(ii) a The number of times of maintenance of the apparatus was Y3Jk(ii) a Carrying out dequantization processing on a preset value, purchase duration, rated memory and maintenance times and taking the numerical values of the dequantization processing;
s44: using formulas
Obtaining a block value Q of the primary selection node
Jk(ii) a Wherein, b8, b9, b10 and b11 are all preset proportionality coefficients.
Preferably, the system further comprises a registration login module, wherein the registration login module is used for submitting the equipment information for registration by the user and sending the equipment information which is successfully registered to the server for storage, and the server marks the equipment as the block link node after receiving the equipment information and marks the time when the equipment information is received as the registration time of the equipment; the equipment information comprises the position, the CPU model, the purchase time, the rated memory and the maintenance frequency of the equipment, and the equipment is a desktop computer or a notebook computer; the rated memory includes a rated capacity of the operating memory and a rated capacity of the hard disk memory.
Preferably, the system further comprises a storage allocation module, wherein the storage allocation module is used for allocating and storing the compacted data, and the specific allocation steps are as follows:
v1: the user sends the stored data to the server through the client, and the server receives the stored data, compresses and encrypts the data to obtain the compressed data and sends the compressed data to the storage distribution module;
v2: setting the hard disk memory of the block chain node as G1: the remaining memory of the hard disk is marked as G4; carrying out distance calculation on the positions of the block chain nodes and the positions of the storage distribution modules to obtain a distance value, and marking the distance value as G2; calculating the time difference between the registration time of the block chain node and the current time of the system to obtain registration time length which is marked as G3;
v3: dequantizing the hard disk memory, the residual memory, the distance value and the registration duration, and taking the values of the dequantization processing, and obtaining a numerical distribution value GF of a block chain node by using a formula GF = G1 × c1+ G4 × c2+ G3 × c3+ (1/G2) × c 4; wherein c1, c2, c3 and c4 are all preset proportionality coefficients;
v4: and selecting the block chain node with the maximum matching value as a storage node of the compacted data, and sending the compacted data to the block chain node for storage by the storage allocation module.
Compared with the prior art, the invention has the beneficial effects that: the data acquisition module acquires the consumed resource information of the transaction request and sends the consumed resource information to the server; the data analysis module acquires consumption resource information stored in the server, analyzes the consumption resource information, and dequantizes and takes numerical values of the memory occupation value and the CPU occupation value; obtaining an average consumption value of the transaction request by using a formula; the data analysis module sends the average consumption value of the transaction request to a server for storage; the load balancing module carries out load balancing adjustment on the transaction request, selects the initial selection node with the maximum node kiss value as the selected node of the transaction request, and executes the transaction request through the selected node; the method comprises the steps of carrying out dequantization processing on a memory occupation value and a CPU occupation value of a transaction request and analyzing to obtain an average consumption value, selecting a block chain node according to the average consumption value, then carrying out dequantization processing on the selected block chain node according to a node execution value and a block value to obtain a node kiss value of the block chain node, selecting a primary selected node with the largest node kiss value as a selected node of the transaction request, executing the transaction request through the selected node, and reasonably distributing the transaction request through a load balancing module, so that node resources in the whole block chain are efficiently used, breakdown of the single block chain node is avoided when the access pressure of the single block chain node is large, and meanwhile, the situation that avalanche occurs due to too large pressure in a block chain node cluster is also ensured.
Detailed Description
The technical solutions of the present invention will be described clearly and completely with reference to the following embodiments, and it should be understood that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
Referring to fig. 1, a system for balancing load among nodes of a block chain based on access pressure includes a data acquisition module, a server, a data analysis module, a load balancing module, a node acquisition module, a node analysis module, a node statistics module, a registration and login module, and a storage and allocation module;
the data acquisition module is used for acquiring the consumed resource information of the transaction request and sending the consumed resource information to the server; the resource consumption information is the resource consumed when the transaction request is executed, and the resource comprises a memory occupation value and a CPU occupation value;
the data analysis module is used for acquiring consumption resource information stored in the server and analyzing the consumption resource information, and the specific analysis steps are as follows:
the method comprises the following steps: setting a transaction request as Pi, i =1, … …, n; setting the memory occupation value consumed by executing transaction request as NjPi(ii) a The CPU occupation value consumed by the execution of the transaction request is DjPi(ii) a j =1, … …, n; j represents the number of executions of the transaction request;
step two: carrying out dequantization processing on the memory occupation value and the CPU occupation value and taking the numerical values of the memory occupation value and the CPU occupation value;
using formulas
Obtaining the average consumption value Z of the transaction request
Pi(ii) a Wherein, b1 and b2 are both preset proportionality coefficients;
step three: the data analysis module sends the average consumption value of the transaction request to a server for storage;
the load balancing module is used for carrying out load balancing adjustment on the transaction request, and the specific adjustment steps are as follows:
s1: the user sends a transaction request to the load balancing module through the client, and after receiving the transaction request, the load balancing module matches the transaction request with all transaction requests stored in the server to obtain an average consumption value Z of the corresponding transaction requestPa(ii) a a belongs to i, and simultaneously the load balancing module generates a node analysis instruction;
s2: the load balancing module sends the node analysis instruction to the node analysis module, and the node analysis module sends the node execution value of the block chain node to the load balancing module after analyzing;
s3: the load balancing module enables the node execution value to be larger than the average consumption value ZPaMarking the block chain link points as initial selection nodes; setting the initially selected node as Jk, wherein k is a positive integer;
s4: the load balancing module generates an access instruction corresponding to the initially selected node and sends the access instruction to the node counting module, and the node counting module receives and processes the access instruction corresponding to the initially selected node to obtain a block value of the initially selected node and sends the block value to the load balancing module; the specific treatment steps are as follows:
s41: acquiring equipment information of the primary selection node, setting all CPU models to be preset values, matching the CPU models in the equipment information with all the CPU models to obtain corresponding preset values, and marking as Y1Jk;
S42: calculating the time difference between the purchase time in the equipment information and the current time of the system to obtain the purchase duration of the equipment and marking the purchase duration as T1JkThe unit is day;
s43: set the rated memory of the device to Y2Jk(ii) a The number of times of maintenance of the apparatus was Y3Jk(ii) a Carrying out dequantization processing on a preset value, purchase duration, rated memory and maintenance times and taking the numerical values of the dequantization processing;
s44: using formulas
Obtaining a block value Q of the primary selection node
Jk; wherein b8, b9, b10 and b11 are all preset proportionality coefficients;
s5: marking the node execution value of the primary selection node as ZJk(ii) a Marking the block value of the primary selection node as QJk(ii) a Carrying out dequantization processing on the node execution value and the block value and taking the numerical value of the node execution value and the block value;
s6: using the formula FJk=ZJk×b3+QJkObtaining x b 4-mu to obtain the node kiss value F of the primary selected nodeJk(ii) a Wherein b3 and b4 are both preset proportionality coefficients, mu is an error correction factor, and the value is 2.3863; the larger the node kiss value is, the higher the probability that the transaction request is executed by the primary selection node is;
s7: selecting the initial selection node with the maximum node kiss value as the selected node of the transaction request, and executing the transaction request through the selected node;
the node acquisition module is used for acquiring node information of the block chain nodes and sending the node information to the node analysis module; the node information comprises the residual memory value of the block chain node and the real-time residual utilization rate of the CPU; the node analysis module is used for receiving node information and analyzing the node information, and the specific analysis steps are as follows:
SS 1: after receiving the node analysis instruction, the node analysis module analyzes the node information and sets the residual memory value of the block chain node to be D1;
SS 2: counting the real-time residual utilization rate of the CPU, and setting the residual utilization rate to be Lm, wherein m =0 and … … 99; and the value range of Lm is (0, 1)]The number of occurrences of remaining usage is counted and labeled as ELm;
SS 3: selecting the residual utilization rate with the largest occurrence frequency, and marking the residual utilization rate as Lb, wherein b belongs to m;
SS 4: summing the times of other residual utilization rates to obtain a total occurrence time EZ;
SS 5: dequantizing the residual memory value, the residual utilization rate and the residual utilization rate, and taking the values of the dequantization residual memory value, the residual utilization rate and the residual utilization rate, and obtaining a node execution value Z of the block chain node by using a formula Z = D1 × b5+ Lb × b6-EZ × b7+ lambda; b5, b6 and b7 are all preset proportionality coefficients, and lambda is a correction constant and takes the value of 1.32;
SS 6: the node analysis module sends the node execution value to the load balancing module;
the registration login module is used for submitting equipment information for registration by a user and sending the equipment information which is successfully registered to the server for storage, and the server marks the equipment as a block chain node after receiving the equipment information and marks the time when the equipment information is received as the registration time of the equipment; the equipment information comprises the position, the CPU model, the purchase time, the rated memory and the maintenance frequency of the equipment, and the equipment is a desktop computer or a notebook computer; the rated memory comprises the rated capacity of the operating memory and the rated capacity of the hard disk memory;
the storage allocation module is used for allocating and storing the compacted data, and the specific allocation steps are as follows:
v1: the user sends the stored data to the server through the client, and the server receives the stored data, compresses and encrypts the data to obtain the compressed data and sends the compressed data to the storage distribution module;
v2: setting the hard disk memory of the block chain node as G1: the remaining memory of the hard disk is marked as G4; carrying out distance calculation on the positions of the block chain nodes and the positions of the storage distribution modules to obtain a distance value, and marking the distance value as G2; calculating the time difference between the registration time of the block chain node and the current time of the system to obtain registration time length which is marked as G3;
v3: dequantizing the hard disk memory, the residual memory, the distance value and the registration duration, and taking the values of the dequantization processing, and obtaining a numerical distribution value GF of a block chain node by using a formula GF = G1 × c1+ G4 × c2+ G3 × c3+ (1/G2) × c 4; wherein c1, c2, c3 and c4 are all preset proportionality coefficients;
v4: selecting the block chain node with the maximum numerical distribution value as a storage node of the compacted data, and sending the compacted data to the block chain node for storage by a storage distribution module;
the formulas are obtained by acquiring a large amount of data and performing software simulation, and the coefficients in the formulas are set by the technicians in the field according to actual conditions;
the load balancing module can also adjust the load by: the method comprises the following specific steps:
VV 1: calculating the resources consumed by each transaction in the execution process, including memory occupation, CPU occupation and data used by a hard disk;
VV 2: calculating all resources of the current node, including the residual memory, the CPU core number and Hz when the current node is empty, and the residual available space of the hard disk;
VV 3: dividing all resources by average consumed resources to obtain the maximum concurrent transaction execution number of the node;
VV 4: adding a configurable threshold value, and storing in percentage form;
VV 5: broadcasting the current pressure percentage of the node to other nodes in the blockchain cluster through the P2P network, wherein the current node also receives the state information of other nodes;
VV 6: adding Token into a bucket at a constant 1/QPS time interval (if QPS =100, the interval is 10ms) by using a current limiter of a Token bucket algorithm when receiving a transaction, temporarily not adding a new request if the bucket is full, respectively taking away one Token, and forwarding the request to other nodes if no Token can be taken;
VV 7: when in forwarding, a smooth polling load balancing algorithm taking the load state percentage as the weight is used, and the load balancing algorithm is as follows:
VV 71: finding out a server maxWeightServer with the maximum current weight value;
VV 72: calculating the sum weightSum of { W0, W1, W2, … and Wn };
VV 73: transmitting maxweight Server. CW = maxweight Server. CW-weight Sum;
VV 74: recalculating the current weight CW of { S0, S1, S2, …, Sn } with the formula Sn.CW = Sn.CW + Sn.Wn
VV75, return maxWeightServer;
the default weight represents the original weight of the server, the current weight represents the weight recalculated after each access, the initial value of the current weight is the default weight, the server with the maximum current weight is maxweightServer, the sum of all the default weights is weightSum, and the server list is serverList;
when the transaction system is used, the data acquisition module is used for acquiring the consumed resource information of the transaction request and sending the consumed resource information to the server; the data analysis module acquires consumption resource information stored in the server, analyzes the consumption resource information, and dequantizes and takes numerical values of the memory occupation value and the CPU occupation value; obtaining an average consumption value of the transaction request by using a formula; the data analysis module sends the average consumption value of the transaction request to a server for storage; the load balancing module carries out load balancing adjustment on the transaction requests, a user sends the transaction requests to the load balancing module through a client, and the load balancing module matches the transaction requests with all transaction requests stored in the server after receiving the transaction requests to obtain an average consumption value of the corresponding transaction requests; the load balancing module sends the node analysis instruction to the node analysis module, and the node analysis module sends the node execution value of the block chain node to the load balancing module after analyzing; the load balancing module marks the block chain link points with the node execution values larger than the average consumption value as the primary selection nodes; the load balancing module generates an access instruction corresponding to the initially selected node and sends the access instruction to the node counting module, and the node counting module receives and processes the access instruction corresponding to the initially selected node to obtain a block value of the initially selected node and sends the block value to the load balancing module; carrying out dequantization processing on the node execution value and the block value and taking the numerical value of the node execution value and the block value; acquiring a node kiss value of the obtained primary selected node by using a formula, selecting the primary selected node with the maximum node kiss value as a selected node of the transaction request, and executing the transaction request through the selected node; the method comprises the steps of carrying out dequantization processing on a memory occupation value and a CPU occupation value of a transaction request and analyzing to obtain an average consumption value, selecting a block chain node according to the average consumption value, then carrying out dequantization processing on the selected block chain node according to a node execution value and a block value to obtain a node kiss value of the block chain node, selecting a primary selected node with the largest node kiss value as a selected node of the transaction request, executing the transaction request through the selected node, and reasonably distributing the transaction request through a load balancing module, so that node resources in the whole block chain are efficiently used, breakdown of the single block chain node is avoided when the access pressure of the single block chain node is large, and meanwhile, the situation that avalanche occurs due to too large pressure in a block chain node cluster is also ensured.
The preferred embodiments of the invention disclosed above are intended to be illustrative only. The preferred embodiments are not intended to be exhaustive or to limit the invention to the precise forms disclosed. Obviously, many modifications and variations are possible in light of the above teaching. The embodiments were chosen and described in order to best explain the principles of the invention and the practical application, to thereby enable others skilled in the art to best utilize the invention. The invention is limited only by the claims and their full scope and equivalents.