# Dynamic Task Scheduling Scheme for Processing Real-Time Stream Data in Storm Environments
## 3 The Proposed Dynamic Task Scheduling Scheme
### Dynamic Task Scheduling
#### 3.3.3 CPU and Memory Load-Based Scheduling  
A delay in tasks or loss may occur when a CPU and memory load occurs on one worker node. In this case, a node with a CPU and memory load and a free node are distinguished, and a task is selected to be migrated from the loaded node based on the CPU usage and the deadline and is redistributed to a free node. In this study, a memory and CPU load are defined as when a user uses the resources beyond the threshold value.  
Equation (4) is used for selecting a task in a loaded node for redistribution of tasks. \(T_{n,dead}\) is calculated using Equation (1). Specifically, the task with the highest CPU usage and deadline value in a loaded node is migrated. The selected task (\(ST_{i}\)) is migrated to a free node with a relatively smaller load to balance the loads.  
\[ST_{n}=argmax(T_{n,dead}), \tag{4}\]  
Similar to memory load-based scheduling, a task to be migrated from a loaded node is selected using Equation (4). It must be examined whether a delay occurs from the loads on a free node when the selected task that is migrated to a free node is being processed. Equation (5) is utilized for calculating the cost of migrating the task selected using Equation (4), where \(ST_{n,network}\) is the network load of task \(ST\) selected in worker node \(n\), whereas \(ST_{n,size}\) is the tuple size of task \(ST\) selected in worker node \(n\). The transmission cost of the task is calculated using the network load and the tuple size.  
\[ST_{n,lat}=ST_{n,network}*ST_{n,size} \tag{5}\]  
Equation (6) is used for calculating the expected processing costs, where \(n\), \(m\), and \(ST\) are loaded worker node \(n\), worker node m selected by migrating the task, and task \(ST\)selected in Equation (4). \(CPU_{m,avg-th}\) is the average CPU throughput of worker node \(m\). Specifically, the sum of the expected throughput of task \(ST\) migrated from worker node \(n\) and the network transfer cost is the total cost of processing in worker node \(m\). The task is migrated if this processing cost is lower than the cost of processing in worker node \(n\), and the free memory of worker node \(m\) can allow task \(ST\).  
\[\text{Cost}_{n,m,ST}=\frac{ST_{n,size}}{CPU_{m,avg-th}}+ST_{n,lat} \tag{6}\]  
Figure 6 shows an example of CPU and memory load-based scheduling. In Nimbus, the CPU and memory of worker node 1 exceeded the threshold, and therefore, a load has occurred. The proposed scheme selected a task to be migrated using Equation (4). If the current time (_now_) is assumed to be 2, the deadline of _Task\({}_{3}\)_ is closer at 33.33 (CPU usage 50 \(\times\) task deadline 0.66), whereas the deadline of _Task\({}_{4}\)_ is 30 (CPU usage 90 \(\times\) task deadline 0.33) because the deadline is reasonably far from now even when the CPU usage is high. For the task \(ST\) (_Task\({}_{3}\)_) selected accordingly, the processing cost is calculated for each worker node using Equation (6). The calculation result shows that the average CPU throughput of worker node 3 is high, and thus, task \(ST\) is migrated to worker node 3. NMonitor value of each worker node is updated after the migration in which the migrated _Task\({}_{3}\)_ has decreased the CPU usage owing to the CPU performance of worker node 3; ultimately, the average CPU usage in the load table of Nimbus decreases from 91% to 78%.  
Figure 5: CPU load-based scheduling.