  Fog/Edge computing model allows harnessing of resources in the proximity of
the Internet of Things (IoT) devices to support various types of real-time IoT
applications. However, due to the mobility of users and a wide range of IoT
applications with different requirements, it is a challenging issue to satisfy
these applications' requirements. The execution of IoT applications exclusively
on one fog/edge server may not be always feasible due to limited resources,
while execution of IoT applications on different servers needs further
collaboration among servers. Also, considering user mobility, some modules of
each IoT application may require migration to other servers for execution,
leading to service interruption and extra execution costs. In this article, we
propose a new weighted cost model for hierarchical fog computing environments,
in terms of the response time of IoT applications and energy consumption of IoT
devices, to minimize the cost of running IoT applications and potential
migrations. Besides, a distributed clustering technique is proposed to enable
the collaborative execution of tasks, emitted from application modules, among
servers. Also, we propose an application placement technique to minimize the
overall cost of executing IoT applications on multiple servers in a distributed
manner. Furthermore, a distributed migration management technique is proposed
for the potential migration of applications' modules to other remote servers as
the users move along their path. Besides, failure recovery methods are embedded
in the clustering, application placement, and migration management techniques
to recover from unpredicted failures. The performance results show that our
technique significantly improves its counterparts in terms of placement
deployment time, average execution cost of tasks, total number of migrations,
total number of interrupted tasks, and cumulative migration cost.
