Massive amounts of heterogeneous data are produced by Internet of Things (IoT) devices utilized in daily life and numerous fields, and these data streams need to be stored, processed, analyzed, and transmitted to the cloud. It usually suffers from missing values and anomalies; system services also suffer from congestion due to slow processors, resulting in low throughput, a high response time, slow decision-making, and data loss, resulting in low quality of service and the deterioration of the system's performance. In this study, propose to integrate the smart controller (SC) with the Message Queuing Telemetry Transport (MQTT) broker and services in the fog node to make decisions automatically to prevent congestion in the system's services and speed up the processing. The IoT stream is inspected in the services for anomalies using one-class support vector machines (OCSVM). Then, using the integrating technique of principal component analysis (PCA) and the k-nearest neighbors (KNN) algorithm in the SC, obtain the best prediction of the efficient number of services that must be deployed in the system. The operating model proposed showed significantly stable system performance in terms of throughput, latency, response time, the amount of data loss, and preventing congestion.