The IoT has generated an amount of data that puts enormous pressure on the internet infrastructure. Therefore, companies are scrambling to find ways to alleviate this pressure and solve the data problem. Cloud Computing plays a major role in this, in particular by making all connected devices work together. Virtual machine (VM) migration concept and the architecture of datacenters for cloud computing have a significant impact on latency and energy cost. In order to lower latency and energy usage while maintaining SLA restrictions, this work focuses on how to employ VM migration to achieve steady physical machine use. Using the novel MVMM scheduler method for virtual machine migration, we suggest modeling and statistical analysis of a Dynamic Bayesian Network for cloud and cloudlet environments within IoT technologies. It use a Dynamic Bayesian Network study to decide where and when a particular VM migrates. Indeed, to improve latency and energy consumption by limiting the number of upcoming migrations, the statistical study computes a score for each VM candidate for migration using datacenter metrics as input. In addition, this paper focuses to set solution of network latency problem for communicating objects in IoT technologies by the use of Cloudlets environment by proposing a conception of a local datacenter that allows users to connect to their data from any point and through any devices. The performance demonstration results for resource utilization rate, average execution time, and lost packets show that cloudlet applications have a significant advantage over local and remote connections.