# A Cost-Aware Framework for QoS-Based and Energy-Efficient Scheduling in Cloud-Fog Computing
## 6 Service Management Framework
### Cost Analytical Model  
The scheduling optimality problem is formalized for a given bag of fog jobs waiting to receive services from the cloud computing environment. The design of the cloud system employs a set of identical computing resources \(\mathbf{R}\), namely, virtual machines, available to service fog demands:  
\[\mathbf{R}=\{R_{1},R_{2},R_{3},\ldots,R_{n}\},\quad\forall m\in[\mathbb{1}n] \tag{2}\]  
Each resource \(R_{m}\) in the cloud environment entails a queue \(Q_{m}\) that holds incoming fog jobs waiting to receive service, which formulates a queuing system \(\mathbf{Q}\) that reflects resources \(\mathbf{R}\) in the cloud environment as follows:  
\[\mathbf{Q}=\{Q_{1},Q_{2},Q_{3},\ldots,Q_{n}\},\quad\forall m\in[\mathbb{1}n] \tag{3}\]  
A set of \(\ell\) atomic, independent fog jobs \(\mathbf{J}\) are delivered from fog nodes and received by the dispatcher \(cd\) of the cloud environment as follows:  
\[\mathbf{J}=\{J_{1},J_{2},J_{3},\ldots,J_{\ell}\},\quad\forall i\in[\mathbb{1}\ell] \tag{4}\]  
Fog jobs \(\mathbf{J}\) arrive in a random manner to the cloud dispatcher \(cd\). The index \(i\) of each fog job \(J_{i}\) indicates and signifies its arrival ordering to the dispatcher \(cd\). For instance, \(J_{1}\) is the first job to arrive, \(J_{2}\) is the second job, and so on. Jobs allocated by the dispatcher \(cd\) are queued in cloud resources \(\mathbf{R}\) for execution based on a scheduling order \(\beta\) described as follows:  
\[\beta=\bigcup_{m=1}^{n}\mathrm{I}(Q_{m}) \tag{5}\]  
where \(\mathrm{I}(Q_{m})\) represents indices of fog jobs in the resource-queue \(Q_{m}\). For instance, \(\mathrm{I}(Q_{2})=\{4,1,3,6\}\) signifies that fog jobs \(J_{4}\), \(J_{1}\), \(J_{3}\), and \(J_{6}\) are queued in \(Q_{2}\) such that fog job \(J_{4}\) precedes \(J_{1}\), which in turn precedes \(J_{3}\), and so on. It is assumed that \(z_{i,m}\) represents an allocation of a fog job \(J_{i}\) to either a queue \(Q_{m}\) or a cloud resource \(R_{m}\) associated with that queue \(Q_{m}\) as follows:  
Figure 2: System architecture. \[z_{i,m}= \begin{cases}1,&\text{Fog job }J_{i}\text{ is allocated to the schedule of a cloud resource }R_{m}\\ 0,&\text{No allocation for job }J_{i}\text{ to a cloud resource }R_{m}\end{cases}  \tag{6}\]  
Since fog jobs \(\mathbf{J}\) are submitted by different fog nodes, they come to the cloud dispatcher \(cd\) with diverse computational demands and QoS obligations. Each fog job \(J_{i}\) is thus stamped with a prescribed execution time \(\mathcal{E}_{i}\) and an arrival time \(a_{i}\), where \(\mathcal{E}_{i}\) denotes the service time required by a cloud resource \(R_{m}\) to execute the demand of the fog job \(J_{i}\), whereas \(a_{i}\) denotes the arrival time of fog job \(J_{i}\) to the cloud dispatcher \(cd\). Each fog job \(J_{i}\) waits in the cloud tier to receive service from a cloud resource \(R_{m}\). The time spent by a fog job \(J_{i}\) in the dispatcher's queue is ignored, modeled by \(c\omega_{i|cd}^{\beta}\):  
\[c\omega_{i|cd}^{\beta}=0 \tag{7}\]  
However, the time spent by a fog job \(J_{i}\) in resource queues \(\mathbf{Q}\) is modeled by \(c\omega_{i}^{\beta}\), which is formalized according to a scheduling order \(\beta\) in the cloud tier. Once a fog job \(J_{i}\) receives a service and leaves the cloud tier, the time of departure is modeled by \(d_{i}\), which in turn models a response time \(rt_{i}^{\beta}\) that is a function of the execution time \(\mathcal{E}_{i}\) of fog job \(J_{i}\) in a cloud resource \(R_{m}\), and the total waiting time \(t\omega_{i}^{\beta}\) of a fog job \(J_{i}\) governed by a scheduling order \(\beta\) in the cloud-fog environment so far, as follows:  
\[t\omega_{i}^{\beta}=f\omega_{i}^{\beta}+c\omega_{i}^{\beta} \tag{8}\]  
\[rt_{i}^{\beta}=\mathcal{E}_{i}+t\omega_{i}^{\beta} \tag{9}\]  
where \(f\omega_{i}^{\beta}\) models the waiting time of a fog job \(J_{i}\) in the fog environment, and \(c\omega_{i}^{\beta}\) models the waiting time of fog job \(J_{i}\) in the cloud computing environment.