# Smart Hospitals and IoT Sensors: Why Is QoS Essential Here?
## 3 Materials and Methods
A Data Gateway component extracts its data and sends them to the Core for each sensor. The Gateway instances have individual dynamic service stacks that contain QoS services employed to the sensor data. In turn, the Core is the main component responsible for providing data to applications, monitoring applications and Gateway instances’ performance, and orchestrating the QoS service stacks. the Gateways send to the Core contains a sensor timestamp. Therefore, on receiving a new packet, the Core computes the current delay of that Gateway using the current times and the packet timestamp. Finally, the Core also computes the jitter for each Gateway based on the interval between packet arrivals. With all metrics collected, the Core packs them in a metric vector \(M=\{C,M,N,D,J,A\}\) for each Gateway, which it will use in the decision-making process. After computing M for each Gateway, the Core checks for QoS violations (2) to verify whether it needs to deliver services or not. When an application connects to the Core, it provides a QoS limit value for delay or jitter. When checking for QoS violations, the Core compares the current delay/jitter (\(M[3]\) and \(M[4]\) collected in phase (1) the system is performing for each application with their respective limits. If this value is higher than the application limit, then the QoS strategy must take place to deliver QoS services. However, more than one application can have its current QoS violated. As a QoS service can only be exclusively delivered (e.g., Data Prioritization), the Core should select one application from all applications that have their QoS violated. In such a case, it analyzes the metrics (3) for each application by combining them in a weighted sum to compute their Potential of Adaptation (PA). Equation (1) represents the PA computation where it receives two vectors of size \(m\): a parameterized weight vector \(W\) and the computed metric vector \(M\) for that particular Gateway. In the current version, \(m=5\) since the Core collects five metrics; however, future versions can consider more or fewer metrics. When configuring the middleware, the administrator can provide five weight parameters in the interval \([0,1]\) to be applied by the \(PA\) computation. Each weight is applied to its corresponding metric as follows: \(W=\{cpu_{w},memory_{w},network_{w},delay_{w},jitter_{w},applications_{w}\}\) This particular metric is essential to define the criticality of each Gateway. Some QoS services, such as the Data Prioritization, can be active for only a single Gateway at the same time. Therefore, when two Gateways need QoS services, PA defines which one receives this type of service. Before the analysis, the Core first normalizes the values from \(M\) that do not represent a consumption level by dividing them by the highest metric measurement from all Gateways. For instance, with two Gateways with a delay of 50 ms and 100 ms, the values are converted to 0.5 and 1, respectively. Following, the Core stacks a single QoS service for each application (4), using the PA to decide which application will receive an exclusive QoS service if it is the case. The Core sends a control message to the particular Gateways activating or deactivating QoS services on them. Finally, Figure 3 also covers the Core workflow if any violations occur in phase 2. In that case, the Core checks if it is still active (5) to decide if it keeps running or finishes. If true, it then waits for a time interval (6) until it starts the workflow again. Figure 3: QoS Service Elasticity decision loop depicting the steps the Core performs to deliver QoS services. \[PA(W,M)=\sum_{i=0}^{m}W[i]\times M[i] \tag{1}\]  
To illustrate an actual deployment of the model, Figure 4 depicts an actual operating room with the middleware installed. The figure shows three Data Gateway instances, each on a dedicated computer. In each computer, a Microsoft Kinect v2 [33] camera device produces image frames. Additionally, several location tags are attached to people in the operating room.