# Timed-SAS: Modeling and Analyzing the Time Behaviors of Self-Adaptive Software under Uncertainty
## 4 Implementation of the Timed-SAS Approach
### Definition on Time Behaviors
#### 4.1.1 Deterministic Time Constraints  
The deterministic time constraints include the Monitoring-Period in the Monitor process and the Triggering-Delay Time in the Analyze process. 1. Definition on Monitoring Period \(M_{\text{Period}}\) for Monitor According to the MAPE-K architecture, the Monitor process is used to periodically detect changes within the self-adaptive software application logic, and the monitoring period is defined as follows. **Definition 1**. : (Monitoring Period \(M_{\text{Period}}\)). _The Monitoring Period refers to the time-interval between two triggers of the Monitor module during the running processes of the SAS systems, represented as \(M_{\text{Period}}\), as shown in Figure 3. \(M_{\text{Period}}\) represents the triggering period of the software module, which is preset by software engineers and is different from the inherent triggering period or triggering frequency of the physical sensors._  
Figure 3: Monitoring Period \(M_{\text{Period}}\) for Monitor. In the SUIS example of Section 2.1, \(M_{\text{Period}}\) represents the sampling period of the CPU utilization, and it was initially set as 5-unit time. It influences the triggering frequency of the whole MAPE-K feedback loops. The excessive triggering frequency would aggravate the computing burden of the SAS systems, while the lower triggering frequency cannot satisfy the user requirements and guarantee the system performance. Therefore, the time constraint of \(M_{\text{Period}}\) is of vital importance. (2) Definition on Triggering-Delay Time \(A_{\text{Delay}}\) for Analyze  
The Analyze process of the MAPE-K architecture is used to analyze exceptions or errors in the application logic and analyze the duration of the exceptions. The duration time was defined as Triggering-Delay Time, as shown below. (Triggering-Delay Time \(A_{\text{Delay}}\)). : _The Triggering-Delay Time refers to the time-interval of the Analyze process between when a monitoring variable is out of limits and when the subsequent Plan process is finally triggered. It is represented as \(A_{\text{Delay}}\), as shown in Figure 4._  
In the SAS systems, when the monitoring variable \(v\) is detected out of limits (i.e., \(v>\)_UpperLimit_ or \(v<\)_LowerLimit_ in Figure 4), the Analyzer module will observe \(v\) continuously for a period of time, i.e., \(A_{\text{Delay}}\). If \(v\) still remains in the out-of-limit state (i.e., \(v>\)_UpperLimit_ or \(v<\)_LowerLimit_), the subsequent Plan process would be triggered. Taking the adaptation scenario in Section 2.1 for example, as shown in Figure 5, the CPU utilization (i.e., the variable of _Utilization_) rises above its upper limit (i.e., 85%) at \(t_{1}\) and returns to its normal range at \(t_{2}\). As the out-of-limit time is less than \(A_{\text{Delay}}\) (i.e., \(\Delta t_{1}=t_{2}-t_{1}<A_{\text{Delay}}\)), there is no need to trigger further self-adaptation actions. However, this variable rises above its upper limit again at \(t_{3}\), and the out-of-limit time is longer than \(A_{\text{Delay}}\) (i.e., \(\Delta t_{2}=t_{4}-t_{3}>A_{\text{Delay}}\)). As a result, the subsequent processes would be triggered. The time constraint of _Triggering-Delay Time_ is defined to specify such kind of delay-triggering self-adaptation strategies as, \"if _Utilization_ > _UpperLimit_ for \(N\) seconds, then add \(P\) more VMs\". According to repeated experiments, \(A_{\text{Delay}}\) takes the value of 3-unit time in the above example. The time constraint of _Triggering-Delay Time_\(A_{\text{Delay}}\) can effectively avoid system misalignment and unnecessary self-adaptation actions. The value of \(A_{\text{Delay}}\) should be set  
Figure 4: Triggering-Delay Time \(A_{\text{Delay}}\) for Analyze. Figure 5: Analysis of Triggering-Delay Time \(A_{\text{Delay}}\). according to the concrete scenario, as the too large value would reduce the sensitivity and effectiveness of the self-adaptation logic, and the too-small value would result in over-frequent self-adaptation actions and aggravate the computing burden of the system.