## 4 Experiments and Results
### Results
#### 4.2.1 Image Classification as Batch Processing  
In this experiment, the processing time in the MNIST training classification problem using the multilayer perceptron was measured. The experimental results are shown in Figure 3. The reported results are the average of ten application runs, and as there was no other application workload in the system, we did not find significant variability between runs. The experimental results show that the speed increased when we set the the number of cluster nodes from one to four, and throughout our experiments, we did not note any changes in accuracy when deploying Spark in different computing layers or any changes in the number of nodes when parallelizing and spreading the training tasks across the nodes. The fog layer is superior to the edge layer in terms of performance, primarily due to the greater resource limitations associated with edge devices. As expected, \begin{table}
\begin{tabular}{c c c c} \hline \hline
**Data Processing Paradigm** & **Edge** & **Fog** & **Cloud** \\ \hline \multirow{4}{*}{Batch Processing} & Raspberry Pi (four-node & Ubuntu VM (four-node & Amazon EMR (four-node \\  & cluster; CPU: four cores/node; & cluster; CPU: four cores/node; & cluster; c5a.xlarge type; \\  & Mem: & Mem: & Mem: & CPU: four cores/node; Mem: \\  & 8 GB/node; Spark 3.3.1) & 8 GB/node; Spark 3.3.1) & 7.5 GB/node; Spark 3.3.2) \\ \hline \multirow{4}{*}{Stream Processing} & Raspberry Pi (four-node & Ubuntu VM (four-node & Amazon EMR (four-node \\  & cluster; CPU: four cores/node; & cluster; CPU: four cores/node; & cluster; c3.2 xlarge type; CPU: \\  & Mem: & Mem: & 8 cores/node; Mem: \\  & 8 GB/node; Flink 1.16.0) & 8 GB/node; Flink 1.16.0) & 15 GB/node; Flink 1.17.0) \\ \hline \multirow{4}{*}{Function Processing} & Raspberry Pi 4 (standalone; & Ubuntu VM (standalone; & \\  & CPU: four cores; Mem: 8 GB; & CPU: four cores; Mem: 8 GB; & AWS Lambda \\  & Lean OpenWhisk [72]) & OpenWhisk 1.0.0) & \\ \hline \hline \end{tabular}
\end{table} 
Table 1: Experimental environment. edge computing, constrained by the capabilities of individual devices, faces challenges in efficiently handling resource-intensive tasks. The cloud layer demonstrates a steady improvement as the number of nodes increases. This scalability advantage of the cloud allows it to harness the collaborative power of multiple nodes in the cluster, resulting in enhanced overall performance. In an EMR (elastic MapReduce) cluster within the cloud layer, the computational resources are insufficient to handle the image classification task with only one node. The error indicating \"not enough resources to process the task\" suggests that the specific image classification task may have higher resource requirements than the available capacity of a single node within the EMR cluster. A two-fold speedup in the edge layer was observed when we performed processing in two nodes rather than one node. By distributing the image classification tasks across the nodes, we leveraged the parallel processing capabilities, allowing for the simultaneous execution of computations. This parallelization significantly reduces the overall processing time compared to a single-node configuration. The use of more nodes allows for more efficient resource scaling. In cases of increased demand or larger datasets, the system can dynamically allocate resources across nodes, providing scalability and further enhancing the overall speed of image classification. However, the parallelization of an application involves several factors, such as the communication overhead, the size of the data, and the uneven distribution of data across the nodes, as the data have to be distributed and shared between nodes over the network. Thus, Apache Spark does not show a consistent speedup due to several factors inherent in distributed computing and the characteristics of the Spark framework.