# PECSA: Practical Edge Computing Service Architecture Applicable to Adaptive IoT-Based Applications
## 4 Materials and Methods
### Three Basic Service Types and the Associated Cost Evaluation Schemes
#### 4.2.1 The Evaluation of the Minimum Service Time  
The total service time \(S_{T}\) in the edge network can be generally captured by the following formula:  
\[S_{T}=T_{security}+T_{transmission}+T_{calculation} \tag{8}\]  
In fact, \(T_{transmission}\), \(T_{security}\), and \(T_{calculation}\) can overlap for some services; thus, the formula above is a loose estimate of \(S_{T}\). A loose estimate gives service provider a loose amount of time to complete tasks, contributing to a smaller probability to exceed the user's time limit than a tight estimate. The security measures' execution efficiency is decided by the equipment capability. Considering a widely used encryption algorithm; advanced encryption standard (AES); and a mainstream digital signature algorithm, SHA-256, their performing times can be seen, approximately, as a positive proportion of the data volumes of plain texts [37; 38], respectively. The performing time of security measures is calculated using the following formula:  
\[T_{security}=t_{s}\cdot cp_{i}\cdot da_{i} \tag{9}\]  
where \(t_{s}\) is the complexity coefficient of the security algorithms, such as encryption algorithm and signature algorithm. We denote the CPU computing capability of the \(i\)th edge node as \(\text{cp}_{i}\), (\(i=1,2,\cdots,m\).). \(da_{i}\) denotes the data volume of \(i\)th subtask. To reduce service time and improve resource utilization of the IoT-Cloud, a task can be divided into multiple subtasks and assigned to several devices. Furthermore,subtasks require different execution times for their calculation. Thus, one must establish a resource allocation scheme prior to evaluating the value of \(T_{transmission}+T_{calculation}\). One of the most important goals of a resource allocation scheme is to obtain a minimum value of \(T_{transmission}+T_{calculation}\).  
Let us assume that there are \(N\) edge computing nodes available and \(m\) edge nodes are involved in a service, that is to say, one task of the service is broken down into \(m\) small subtasks. For simplicity, let us assume that the \(i\)th subtask is processed by the \(i\)th edge node. The total data volume of a task demand to be transmitted from the user end to the edge networks is denoted by \(tv_{i}\). We denote the calculation amount of the \(i\)th subtask as \(ca_{i}\). Thus, the time for computing the \(i\)th subtask by edge node \(i\) is:  
\[t_{i}^{E}=\frac{ca_{i}}{cp_{i}} \tag{10}\]  
According to circuit theories [24], the CPU power consumption of the \(i\)th edge node is calculated as  
\[p_{i}^{E}=\rho_{i}ca_{i} \tag{11}\]  
where \(\rho_{i}\) is the power coefficient of energy consumed per CPU cycle.  
Similar to [24], our primary concern is upload time, while downlink delay is ignored since the data size after task processing is generally much smaller than before processing. Let \(v_{i}\) denote the uplink data rate. Then, we can obtain that the time to transmit the \(i\)thsubtask is \(t_{i}=da_{i}/v_{i}\). Formally, the task offloading problem based on minimum service time can be formulated as follows:  
\[\text{min}S_{T}=\sum_{i=1}^{m}(t_{s}\cdot cp_{i}\cdot da_{i}+da_{i}/v_{i}+ca_{i}/ cp_{i}) \tag{12}\]  
subject to  
\[\begin{cases}\sum_{i=1}^{m}da_{i}=tv_{t},\\ \rho_{i}ca_{i}\leq E_{i}^{max}\quad(1\leq i\leq m),\\ da_{i}\geq 0\end{cases} \tag{13}\]  
Note that the objective function \(S_{T}\) is linear and the constraints are all linear. As a result, \(\text{min}S_{T}\) can be optimally solved by any solver for linear programming problems.