Balanced Computing Offloading for Selfish IoT Devices in Fog Computing

Fog computing, which provides low-latency computing services at the network edge, is an enabler for the emerging Internet of Things (IoT) systems. Offloading tasks to the fog that is closer to IoT users for processing has become a means to ensure that tasks are completed quickly. Fog computing cannot only reduce the congestion of the backbone network but also ensure that the task is completed within the specified time. Since fog resources are limited, there will be resource competition among IoT devices. How to quickly and efficiently make an optimal computation offloading decision for individual selfish IoT devices is a fundamental research issue. This article regards the process of multiple IoT devices competing for fog devices as a game and proposes a distributed computation offloading algorithm. The goal is to optimize the balance of computation delay, energy consumption, and cost for fog nodes. The competition between IoT nodes eventually reaches an equilibrium point, that is the Nash equilibrium point. We prove the existence of Nash equilibrium by Weighted Potential Game. In addition, if a large number of IoT devices select the same node for offloading, which will cause the fog node to run out of power and make some networks unable to work normally. Further, causing part of the network to be paralyzed. Therefore, the paper considers the fairness of offloading to extend the network life cycle. A calculation rate adjustment algorithm is designed for the fairness of offloading to ensure that fog nodes do not run out of power and fail. This paper not only fully considers the performance of the IoT device, but also considers the fairness of the fog. Numerous experiments proved the effectiveness of the proposed algorithm.


I. INTRODUCTION
International Data Corporation (IDC) predicts that the number of sensors connected to the network will increase to 30 billion, and the number of connected devices will increase from 50 billion to 1 trillion by 2022. All these devices are connected to the network and construct the Internet of Things (IoT) systems [1]. As the increasing number of computation-intensive applications (e.g., augmented reality and face recognition) appears, higher requirements of computing power are placed on IoT devices. The IoT devices with limited memory and computing power cannot handle computation-intensive applications effectively. How to deal with the data generated by a large number of devices has become a problem. It is inefficient to offload tasks to the cloud data center because this will cause network bandwidth overhead, as much of the data can be filtered The associate editor coordinating the review of this manuscript and approving it for publication was Yilun Shang. due to high redundancy. Besides, the long distance between the IoT devices and the cloud data center also lead to unacceptable task processing delay, huge transmission energy consumption, poor support to mobility, and problems of security [2]- [5]. Therefore, fog computing is proposed. Fog servers are a cloud of servers close to the ground or the edge. Cisco proposed the concept of fog computing, which introduced fog as a cloud near the ground or edge [6], [7]. Not only can fog computing handle low-latency tasks but also effectively reduce network congestion [8], [9]. As a supplement to cloud computing, fog computing extends the functions of cloud computing to the edge [10]. Fog computing consists of a large number of geographically distributed fog servers. Compared with the cloud, the computing power and storage capacity of fog nodes are very limited [11], [12]. Therefore, how to effectively distribute fog resources is a very important but problematic issue [13]. There is currently no uniform method. Some researchers adopt a centralized resource allocation method and can get a better allocation method. Nevertheless, selfish IoT users are interested in optimizing their quality of experience (QoE) individually. They may not follow the strategies that aim to optimize the overall system performance. This will inevitably cause competition between IoT devices. So this paper we design a distributed computation offloading method for delaysensitive tasks. This article regards IoT device competition with fog resources as a game. This article regards the competition of IoT devices with fog resources as a game. Each device makes the most beneficial computing offloading decision based on the choices of other devices. And prove that this game will eventually reach a Nash equilibrium point. Task offloading schemes focusing on minimizing the computation delay or total energy consumption in existing literature may lead to extremely heavy burdens on the fog nodes that are close to the fog nodes or have high processing capabilities, which will result in the death of some important fog nodes and even serious network problems. A large number of IoT devices select the same node for offloading, which will cause the fog node to run out of power and make some networks unable to work normally. So we design a computation rate adjustment(CRD) algorithm to reduce the unfairness of offloading. The contributions of this paper can be summarized as follows.
• This paper solves a multi-objective optimization problem which concludes the task processing delay, energy consumption, and the cost of offloading.
• This article regards the competition of IoT devices with fog resources as a game. Each IoT device tries to minimize its objective function. And prove that this game will eventually reach a Nash equilibrium point by Weighted Potential Game [14]. Based on the game, this paper design offloading algorithm(DTO) and ε Distributed task offloading algorithm(ε-DTO). ε Distributed task offloading algorithm convergence speed is fast, but the optimization effect is reduced.
• To prevent the failure of fog nodes and affect the operation of the network. And fairness is important for extending the network lifetime [16], [28]. The computational offloading in this paper takes into account the fairness of offloading. This paper proposed a computation rate adjustment(CRD) algorithm to reduce the unfairness of offloading.

II. RELATED WORKS
In this section, we survey the existing literature on computation offloading. Offloading is not a trivial issue in fog computing. A large body of recent research worked on addressing the challenges in offloading. The four offload methods were proposed in [15]. 1) Local Mobile Execution, 2) D2D Offloaded Execution, 3) Direct Fog Offloaded Execution, 4) D2D-Assisted Fog Offloaded Execution. This article mainly considers two offloading methods 1 and 3.
In [16], the tasks are divided into three categories: 1) hard-deadline-based tasks 2) soft-deadline-based tasks and 3) no-deadline-based tasks. In this paper, we mainly focus on hard-deadline-based tasks. Hard-deadline-based tasks mean that if the processing time of tasks exceeds the deadline, it is failed. It is also called a delay-sensitive task. In this paper, we mainly focus on latency-sensitive tasks. From the algorithm point of view, the current articles are divided into two categories. One is the approximate algorithm and the other is the meta-heuristic algorithm.
In [17] The Gale-Shapley (GS) algorithm is applied to reach a stable matching to achieve many-to-many computation offloading. However, this algorithm needs a central node to collect all information from edge nodes to make a decision. Once the central node collapses, the algorithm will collapse. Artificial Neural Networks (ANN) were used to predict the offloading time and find the optimal device to offload in [18]. The fog server sends the trained model to the edge node. This paper does not take into account the size of the ANN model and it mainly optimizes the calculation delay. In [19], The interior point method is used to optimize the task calculation delay and calculation energy consumption at the same time to obtain the optimal offloading power and the appropriate offloading task size. This article only considers a single fog node and does not consider the case of multiple fog nodes.
In addition to the myopia algorithm proposed in the above article, a large number of articles use heuristic algorithms for computational offloading. In [20], two nature-inspired metaheuristic schedulers, namely ant colony optimization (ACO) and particle swarm optimization (PSO) are used to propose two different scheduling algorithms to make an optimal decision. In [21], it transforms the non-convex problem into a convex one to minimize energy consumption under the latency constraint and finite MEC computation capacity. and apply convex optimization to solve it. It assumes that the equipment is non-selfish and will follow the overall goal of minimizing the decision. However, in most cases, the equipment is selfish and only considers the maximization of its interests. In [22], this work first investigates a MEC system consisting of mobile devices and heterogeneous edge servers that support various radio access technologies. An optimal offloading node selection strategy is formulated as a Markov decision process (MDP) and solved by employing the value iteration algorithm (VIA). However, this article only focuses on time. In [23], it formulates the problem into a multiobjective model with two scheduling objectives, involving deployment cost and service latency. multi-replicas Pareto ant colony optimization (MRPACO) is proposed to solve the offloading problem. The weighted total cost combines delay and energy consumption is taken as the optimization goal. First, a reinforcement learning algorithm Q-learning based on the Markov decision process is proposed to solve the problem for minimizing weighted total cost [24].
From a structural point of view, the current computing offloading methods are divided into two types, one is a centralized algorithm, the other is a distributed algorithm. The centralized algorithm can get better optimization results, but the algorithm complexity is high and the number of communications is large. Such as [17], [18], [21] is a centralized algorithm. In [25], [26], [29], they proposed the distributed computation offloading algorithm. And they proved the Nash equilibrium through the potential game or weighted potential game. The goal of optimization is not considered comprehensive. At the same time, the problem of offloading balance is not considered. This article also considers the task processing delay, energy consumption, and the price of the fog node. At the same time, the offloading balance is considered based on the idea of maximizing the network life cycle. In [30], these two articles talked about the fairness of offloading, which can delay the network life cycle. Their focus is on maximizing the network life cycle. In [31]- [33], they apply a drift-plus-penalty based Lyapunov optimization approach to efficient provision of both job assignment and resource allocation. These articles also use distributed algorithms but consider long-term performance.
It can be seen that most of the papers mentioned above only consider time delay, energy consumption, or the cost of using fog nodes. This paper considers the task processing delay, calculation energy consumption, and the calculation cost of the fog node. This article formulate the computation offloading as a distributed game to minimize the combination of latency, or energy consumption and offloading cost. In addition, the fairness of offloading is also considered, which is of great significance for maximizing the network life cycle.
The remainder of this article is organized as follows. In Section III, we introduce the system model. In section VI, we formulate the computation offloading as a distributed game. Distributed task offloading algorithm(DTO) and ε Distributed task offloading are proposed to solve the offloading question. computation rate adjustment(CRD) algorithm is proposed to ensure fairness between fog nodes. In section V, we evaluate the performance of the proposed algorithm. Finally, we conclude in section VI.

III. SYSTEM MODEL
We consider an IoT system with a hierarchical computing structure and a set of IoT devices. This article divides the tasks of IoT devices into two types: delay-sensitive and delayinsensitive. This article focuses more on delay-sensitive tasks. The system model consists of three layers, the IoT layer, the fog layer, and the cloud layer, as shown in FIGURE 1. For convenience, the main notations used are summarized in Table 1. IoT devices can process tasks locally or offload to the secondtier fog node and the third-tier cloud data center. If the task is delay-insensitive, we can offload it to a cloud data center. Tasks are processed in the cloud data center higher than the fog nodes. Cloud data centers cannot meet the needs of delaysensitive tasks. So we offload the delay-sensitive tasks to fog nodes. We use two items to describe the computation task of  IoT device n (n ∈ N ), T n = {L n , C n }, where L n represents the length of T n and C n represents the processing density (in CPU cycles/bit) of T n . Define the association vector of IoT device n as a n = {a n,0 , a n,1 , . . . . . . , a n,M }, where a n,x ∈ {0, 1}, x ∈ {0} M , with x∈{0} M a n,x = 1. a n denotes offloading decision. If a n,x is 1, the task is processed in device x. a n,0 means the task is processed locally. We further A includes the decision of all IoT devices. Since fog nodes are heterogeneous, not all fog nodes can be used to process tasks. Define another vector b n = {b n,1 , bn, 2 . . . . . . , bn, M }. b n represents the connectivity between IoT device n and fog nodes. If b n,i is 1, IoT device n can offload tasks to fog i.

B. TASK PROCESSED LOCALLY
if a n,0 = 1, we processed the task locally. Let f L n denotes the processing capability (i.e., the amount of CPU frequency in CPU cycles/s) at IoT device n. The power consumption for IoT device n is expressed as follows [26]- [28]: where k L is a coefficient related to the power of IoT device n.
The time for local processing in IoT device n as follows: Accordingly, the energy consumption of IoT device n for local processing is expressed as: (3)

C. TASK OFFLOADED TO FOG
As shown in Figure 2, the IoT device can offload tasks to the fog nodes in the area. There is more than one such fog node, how should we choose. When x∈M a n,x = 1, the task is offloaded to fog. We assume the task is offloaded to fog m. The offloaded time of the task includes two-part, one is the transmission time and another is processing time.
In this article, we do not consider the time of data return, the processing result is generally very small. Accordingly, when transmitting task T n , the transmission time is expressed as: where R m n represents the transmission rate between IoT user n and fog m [24], [25]. Let p n denotes the transmission power. And the energy consumption for transmitting task is expressed as: Let f m denotes the processing capability of fog node m. The fog node will evenly allocate CPU resources for each task. The execution time of t m n is expressed as: Offloading tasks to the fog node can save energy, but because the operation and calculation of the fog node require costs, the fog node will charge a certain amount of waste from the IoT device. To motivate more IoT devices to offload tasks, we define the cost of processing a bit in fog node m is expressed as: α m and β m is set by fog node m. α m represents the cost for processing one bit. β m is the discount coefficient.

D. PROBLEM STATEMENT
Due to the selfish nature of the device, each device maximizes its interests as much as possible. We define the utility function of IoT device n as: U n (a n , A −n ) = a n,0 * (λ E E L n + λ T t L n ) where A −n is decision of all IoT devices except n. The goal of the target IoT device is expressed as: min a n U n (a n , m∈{0} M a n,m = 1 (9b) a n,m ≤ b n,m ∀m ∈ M (9c) a n,m ∈ {0, 1} ∀m ∈ M (9d) (9a) ensures that the task can only be offloaded to at most one fog node. (9b) indicates that the selected fog node should be connected to the IoT device.

IV. COMPUTATION OFFLOADING
We formally define game G = {N , A, U }. which consists of three parts: • N is the set of players and N represents IoT devices in this article • A is the set of decision space of all IoT devices.
• U is the set of the utility of all players, U n is the utility of IoT device n. Each IoT device will maximize its interests according to (9), which will eventually reach a Nash Equilibrium. A −n denotes the offloading decisions for all IoT devices except n.
Definition 1 (Nash Equilibrium): For game G, we call A * = a * 1 , a * 2 , . . . . . . , a * n Nash Equilibrium if and only if no IoT devices can further improve its utility by changing its decision at the equilibrium point A * . u n (a * n , A * −n ) ≤ u n (a n , A * −n ) ∀a n ∈ A ∀n ∈ N (10)

A. NASH EQUILIBRIUM EXISTENCE
Definition 2 (Weighted Potential Game): Define a W = (w 1 , w 2 , . . . . . . , wn) denotes a vector of positive numbers. A game is called a weighted potential game if it admits a wpotential function P such that for every player n ∈ N and offloading vectors a n , a n ∈ A U n (a n , A −n ) − U n (a n , A −n ) = w n (P(a n , A −n ) − P(a n , A −n )) (11) VOLUME 10, 2022 The user scheduling game G possesses at least one NE when game G is a weighted potential game. Since the weighted potential game has the finite improvement property (FIP) that any better response updating process must be finite and lead to a Nash Equilibrium. So we first prove G is a potential game.
U n (a n , A −n ) = a n,0 * (λ E E L n + λ T t L n ) + M m=1 a n,m (λ E E tr n + λ T (t tr n + t m n ) + λ C c) = a n,0 * (λ E k L L n C n f L U n (a n , A −n ) − U n (a n , A −n ) = (a n,0 − a n,0 )(λ E k L L n C n We first define the function Q(A) as the weighted aggregate utility of all users Q(a n , A −n ) = N n=1 1 λ T U n (a n , A −n ) We further define the function Q(A) as the weighted aggregate utility of all users if each user is alone in the game Q(a n , A −n ) = N n=1 1 λ T U n (a n , 0) 0 represents no other players. We define a function P (A).
P(a n , A −n ) = Q(a n , A −n ) + Q(a n , A −n ) 2 (16) We use the function defined in (16) and w n = 1 λ T , the proof process is expressed as follows.
P(a n , A −n ) − P(a n , A −n ) = Q(a n , A −n ) − Q(a n , A −n ) 2 + Q(a n , A −n ) − Q(a n , A −n ) 2 = N n=1 1 2λ T (U n (a n , A −n ) −U n (a n , A −n )) + N n=1 1 2λ T (U n (a n , 0) − U n (a n , 0)) = 1 λ T (a n,0 − a n,0 )(λ E k L L n C n f L n 2 + λ T L n C n f L n ) + M m=1 1 λ T (a n,m − a n,m )(λ T ( λ T (U n (a n , A −n )) − U n (a n , A −n )) In conclusion, the user scheduling game G is a weighted potential game with the potential function as given in (16). There exists at least one NE point. At the Nash Equilibrium point, no IoT user would change its decision thus no update message would be broadcasted.

B. DISTRIBUTED ALGORITHM FOR TASK OFFLOADING
The centralized algorithms are generally time-complex and require a management center to supervise them. Once the central server crashes, the entire program will not run. So this article uses a distributed task offloading method. So this article uses a distributed task offloading method. Algorithm pseudo-code shows in Algorithm 1. From algorithm 1, we can get the time complexity of the algorithm is proportional to the number of competing IoT devices. And we prove the offloading game G is a weighted potential game. FIP is a feature of the potential function. FIP shows that the algorithm can reach a Nash equilibrium in a finite number of steps [25], [26], [29]. Therefore, our algorithm has a time complexity of O(SN ). S represents the number of steps the IoT device takes to reach the Nash equilibrium.
If we know a better decision A at the beginning of the algorithm, the convergence speed of the algorithm will increase a lot. We can use UCB, Thompson sampling, and other methods to determine the initial decision. In some cases,

Algorithm 1: Distributed Task Offloading Algorithm
Input: Information about fog nodes(ie:f n ) Output: Offloading decisions of all IoT devices Initialize a n = (1, 0, . . . . . . , 0) for all IoT devices; A = (a 1 , a 2 , . . . . . . , a n ); while A is not changed do All IoT device parallel compute the best decision according(9); a * n = arg min a n U n (a n , A −n ); Compete for the decision updating opportunity; if win the competition opportunity then a n = a * n ; broadcast update message; else a n keeps unchanged; we can appropriately reduce the performance in exchange for the algorithm to converge quickly. So we can use Algorithm 2. ε means acceptable utility loss. ε is customized by the user. Algorithm 1 may get better Utility, but Algorithm 2 can get faster convergence speed. We can choose an algorithm according to the actual situation.

Algorithm 2: ε Distributed Task Offloading Algorithm
Input: Information about fog nodes(ie:f n ) Output: Offloading decisions of all IoT devices Initialize a n for all IoT devices according to Thompson sampling; A = (a 1 , a 2 , . . . . . . , a n ); while A is not changed do All IoT device will parallel compute the best decision according(9); a * n = arg min a n U n (a n , A −n ); if U n (a n , A −n ) − U n (a n , A −n ) > ε then Compete for the decision updating opportunity; if win the competition opportunity then a n = a * n ; broadcast update message; else a n keeps unchanged;

C. FAIRNESS BETWEEN FOG NODES
If most IoT devices in the network select the same fog node for computing offloading, the energy of the fog node will be exhausted quickly. And node failure can sometimes cause partial paralysis of the network, so based on this, we consider the balance of offloading. We will offload tasks to nodes with sufficient power as much as possible. But it is more complicated for IoT devices to monitor the power of fog devices. So we let the fog nodes check their battery periodically and adjust the processing rate. See Algorithm 3 for a specific method. The cycle time can be set by the fog if Electricity is less than 50 percent then f n = b a f n else f n keeps unchanged; providers. The degree of imbalance shows the imbalance among the fog nodes and is expressed as follows [20]: Formula (18) can only reflect the difference between the node with the largest processing capacity and the node with the smallest processing capacity, but it cannot reflect the status of all nodes. So we define the standard deviation of the load imbalance.
The larger the DI and V, the more unfair of offloading. Otherwise, the offloading algorithm has good fairness. In some scenarios, some nodes will be more important. So that we can adjust the 50 percent in Algorithm 3.

V. PERFORMANCE EVALUATION
We set up 3 fog nodes and 20 IoT devices in the experiment. The processing density of the fog node is evenly distributed in [100000,200000], and the processing density of the IoT device is evenly distributed in [10000,20000]. Length of tasks generated by IoT devices l n and c n are distributed in [1000,2000][24]- [26]. Set λ T , λ E ,and λ C to 0.4, 0.2, 0.2 respectively. λ T , λ E ,and λ C can be set according to the actual situation. If we pay more attention to processing time, we can set λ T larger. But we have to make sure that λ T + λ E + λ C = 1. The transmission power of the IoT device is set to 0.02. Assume that the transmission rate between all nodes is the same, which is 100. ε is evenly distributed in [0, 1]. ε can be adjusted according to your needs. ε is usually not very large and a large value will result in low utility. The software environment we utilize is Python 3.7 on windows. See from FIGURE 3, We compare the proposed algorithm with LCO(Local computation Only) and RCO(Random computation offload) algorithms, and the DTO algorithm can achieve the smallest cost. Followed by the ε-DTO algorithm. Although the ε-DTO algorithm does not achieve the smallest utility, its convergence speed is faster than the DTO algorithm. The LRO algorithm, because it chooses to process locally every time, so the processing speed remains  unchanged. The randomness of the RCO algorithm is too large, and occasionally it can achieve good results, but it is unstable. FIGURE 4 shows the processing time of different iterations. We can see that the average task processing time is the same as the overall utility trend in FIGURE 3. Because the RCO algorithm selects the node to offload randomly, the effect is very unstable. The two algorithms we proposed can achieve an almost similar effect. In terms of processing time alone, our proposed algorithm is also superior to other algorithms. FIGURE 5 shows the average energy consumption in different iterations. We can see from FIGURE 5 that our proposed algorithm is superior to other algorithms. ε-DTO converges faster but doesn't get better energy consumption. DTO converges slower but the effect is better. In different situations, we can choose different algorithms. FIGURE 6 shows the average utility value under different numbers of IoT devices. Run 1000 rounds for each number of nodes to average the utility value. As the number of IoT increases, the utility will increase due to the heavier load of the fog node. Overall showing an upward trend. When the number of IoT is small, RCO can achieve better results. However, once the number of IoT devices increases, the RCO   algorithm may cause multiple IoT devices to compete for the same fog node, increasing the utility function. And our proposed algorithm is more stable and will not lead to a high failure rate. DI reflects the difference between the node with the largest processing capacity and the node with the smallest processing capacity. FIGURE 7 shows DI in different IoT numbers. Since the LCO algorithm always chooses local processing, the value of DI is always 0. It can be seen that the DI with a large DTO is higher than the LCO and RCO. This shows that although the DTO algorithm reduces utility, it makes the network unfair, which leads to premature failure of some nodes. To solve this problem, we propose the CRD algorithm, the combination of DTO and CRD algorithm, which effectively reduces the DI and improves the fairness of the algorithm.
V reflect the status of all node. It can be seen from FIGURE 8 that the V of RCO is the smallest. This is because when there are enough tasks, the RCO algorithm selects each node more averagely. The RCO algorithm is fair in the long run, but does not achieve good performance. Compared with the other algorithm, the algorithm combining DTO and CRD greatly increases fairness while ensuring the consistency of utility.

VI. CONCLUSION
This article takes the process of IoT device competition for fog nodes as a game. And uses the finite improvement property of the Weighted Potential Game to prove the Nash equilibrium. And this article considers offloading fairness, which can delay the life cycle of the network, and will not allow a single fog node to process too many tasks and run out of energy. Based on the game, this paper design Distributed task offloading algorithm(DTO) and ε Distributed task offloading algorithm(ε-DTO). The computation rate adjustment(CRD) algorithm further improves the balance of offloading. The experiment proves that the proposed Distributed task offloading algorithm can get the best utility. ε Distributed task offloading can get a good utility and better convergence speed. And DTO combines with CRD greatly improves the fairness of the original algorithm.
We can consider more detailed information(channel selection, power control, etc) to minimize utility in future work. We can use methods such as deep learning [34], [35] to determine a better initial offload decision. We can also offload tasks to multiple fog nodes for parallel processing. This involves the issue of offloading orders. And we can study how to put services in the right place to minimize the objective function [23], [36], [37]. SUN  ZHANG CHENG-XIANG received the bachelor's degree in software engineering from Zhejiang Normal University, in 2016. He is currently a Graduate Student majoring in electronic information engineering with Zhejiang Normal University. He is engaged in the research of the Internet of Things. He is studying the research project of fog and edge computing. His research interests include operating systems, cloud computing, and fog computing.