# Efficient Load Balancing for Blockchain-Based Healthcare System in Smart Cities
## 4 Proposed Scheme
### Proposed Algorithm for Load Balancing Node  
In smart cities, multiple fog nodes act as mining computing nodes to find a valid hash value of a patient's health data block. Some of these mining nodes have more data blocks for execution, whereas some have no data to compute. In this work, we introduced the concept of a load balancer for mining nodes in a smart city healthcare system. The primary goal of load balancing is to ensure that no one mining node is overloaded or under-loaded. Figure 2: Load balancing in a mining node. The purpose of load balancing is to reduce the computation time. IoMT continuously sends patients' vital signs data to the mining nodes. The mining nodes have a limited processing capability. Different mining nodes are placed in different locations in the smart city. It may be possible that one mining node may be overloaded, and the other mining nodes may have lesser computational nonces of data blocks. Therefore, there is a need to have a load balancer to equally distribute the requesting data to each mining node. In this work, we proposed an algorithm for efficient load balancing in multiple mining computing nodes by applying a modified greedy algorithm. In this section, an algorithm for the load-balancing node to fairly distribute the patients' data blocks to the mining nodes is proposed. In this algorithm, a traditional greedy algorithm is modified to distribute the data blocks to multiple mining machines to minimize the computational time. The salient features of the proposed algorithm are as follows:  
* Rearrange the entire data blocks according to their computing time relating to data block size in descending order. * Assign the longest data block to the mining node with the lowest computing load. Suppose we have \(X\) indistinguishable fog mining nodes, each having a data caching limit \((D_{lim})\) and \(N\) data blocks with varying block sizes. The size of a data block \(D\), which is required to be cached on a fog mining node is \(D_{j}\). Our main goal is to assign the data blocks to the mining node so that no fog mining node is under or overloaded. The maximum load on a fog mining node at any time instant \(T\) is calculated in two ways:  
1. Calculate the total data block sizes and divide them by the number of fog mining machines to get an average of the data load that needs to be assigned on any machine. The optimum data capacity \((D_{Opt}^{1})\) in this case is determined as: \[D_{Opt}^{1}\geq 1/X\times\sum_{j=1}^{N}D_{j}\] (5)  
The maximum caching load on any of the machines cannot be less than this average load. For example, if there are three data blocks D1, D2, D4, and D5 with data sizes of 2, 3, 1, 2, and 2, respectively, and they are required to be allocated on two machines, then each machine will be assigned a load of 5, which is the average of the load by allocating 3 and 2 data blocks each. 2. When there is a single large-size data block and the rest are smaller, then the large block is assigned to one fog mining machine and all the rest to other fog mining machines. In this case, the optimal load assignment on a machine \((D_{Opt}^{2})\) is calculated as \[D_{Opt}^{2}\geq maxD_{j}\quad 1\leq j\leq N\] (6) In this case, the maximum caching load on a single machine will be equal to the size of the biggest data block. For example, there are three data blocks D1, D2, and D3 with data sizes of 2, 1, and 6, respectively, that are required to be assigned on two machines, then one machine will be allocated D3, where D1 and D2 are allocated on other machines, resulting in a maximum caching load of 6. In light of the above two scenarios, the optimal allocation of data \((D_{Opt})\) is formulated as \[D_{lim}\geq D_{Opt}\geq max(1/X\times\sum_{j=1}^{N}D_{j},maxD_{j})\] (7)  
The goal of load balancing is to assign the data blocks on fog mining nodes in such a way that \(D_{Opt}\) should be minimized.