# Fog vs. Cloud Computing: Should I Stay or Should I Go? +
## Modeling Platforms
### General Equations  
First, we look at the cost of performing the task on the device itself, which we call fog computing cost (\(C_{f}\)). We model this cost with regard to the steps that must be executed to complete the computation. We start by reading the sensor value (cost \(r\)). Then, we perform a custom code operation (cost \(t\)). We are particularly interested in filtering procedures, as these can be simple enough to run on resource-constrained devices [23] and have the potential to decrease the amount of data sent to the cloud drastically, a situation that is posed to become a problem with the large-scale adoption of technologies such as the Internet of Things. For that reason, in this investigation, we consider that our custom operations are filters, that is, operations that decide whether or not each stream value should be sent to the cloud. In this case, we must also consider the cost of sending the data to the cloud (s) and the probability that the value will pass the filter in question (\(f\)). After completing the operation, the device is then idle until a new reading comes along (cost \(i\)). If we are working with a data stream of size \(z\), Equation (1) shows the fog computing cost. We are only dealing with cases where there is no overlap between processing and transferring the data, and accounting for this approach will be a future extension of our model.  
\[C_{f}=(r+t+s\cdot f+i)\cdot z \tag{1}\]  
Next, we look at the cost of performing the task in the cloud. As some of the resources used by the cloud are not under the user's control, from the point of view of the device that is collecting the data, the cloud computing cost (\(C_{c}\)) only includes, for each of the \(z\) values in the data stream, reading (\(r\)), sending (\(s\)), and being idle (\(i\)), as shown by Equation (2).  
\[C_{c}=(r+s+i)\cdot z \tag{2}\]  
Given that these are generic models, it is possible to plug in values to calculate different types of costs (e.g., number of instructions, execution time, energy consumed). We will use this approach in Section 4 to analyze a few test cases. We note that we are considering that all of the values are positive, with the exception of \(f\), which is a probability and, as a result, a number between zero and one. Table 11 in Appendix A has a summary of the notation introduced in this subsection.  
In order to answer our question, we would like to choose situations where the fog computing cost is less than or equal to the cloud computing cost (we use the fact that processing data locally decreases network traffic congestion as a tiebreaker in favor of fog computing when fog and cloud costs are the same). Thus, in the cases where \(C_{f}\leq C_{c}\), we have:  
\[(r+t+s\cdot f+i)\cdot z\leq(r+s+i)\cdot z\] \[1-f\geq\frac{t}{s} \tag{3}\]  
Since \(f\) is the probability of a value passing the filter, \(1-f\) is the probability of a value being filtered out. Therefore, from Equation (3), we have that the probability that a value will be filtered must be greater than or equal to \(t/s\) for us to choose fog computing in this cost model.