# Modeling systems

The very first preparatory step is to model the [system](../../akamas-reference/glossary/system) representing an application or a service that needs to be optimized (also known as the _optimization target_).

<figure><img src="https://1840531935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC1d2wNp5yTa9gnHgSILG%2Fuploads%2Fgit-blob-be92d3c3fc1cc94a8392d9e2f8cded9ffb46692d%2FScreenshot%202023-01-19%20at%2009.58.48.png?alt=media" alt=""><figcaption><p>Preparing an optimization: model the system</p></figcaption></figure>

Modeling a system translates into identifying the [components](../../akamas-reference/glossary/components) representing the key technology elements to be included in the optimization. Each component is associated with a set of tunable [parameters](../../akamas-reference/glossary/parameter), i.e. configurable properties that impact the performance, efficiency, or reliability of the system, and with a set of [metrics](../../akamas-reference/glossary/metric), i.e. measurable properties that are used to evaluate the performance, efficiency, or reliability of the system. Typically, key system components are identified by considering which elements and their parameters need to be tuned.

The following figure shows a system corresponding to a Java-based application, where the Java Virtual Machine (JVM) and Kubernetes containers have been identified as key components.

<figure><img src="https://1840531935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC1d2wNp5yTa9gnHgSILG%2Fuploads%2Fgit-blob-f7b4e2e8d2884ce42abee25624c030753fcb5bfb%2FScreenshot%202023-01-17%20at%2014.23.18.png?alt=media" alt=""><figcaption><p>Figure: Example of a modeled system and its components</p></figcaption></figure>

As shown in this figure, a supported component is the "web application", representing the end user perspective of the modeled system (e.g. response time). As expected, this component type only provides measured metrics and no tunable parameters.

Akamas provides several out-of-the-box [component types](../../akamas-reference/glossary/component-type) to support system and component modeling. Moreover, it is also possible to define new component types to model other components (see [Modeling components](modeling-components)).

The [System template](../../akamas-reference/construct-templates/system-template) section of the reference guide describes the template required to define a system, while the commands for creating a system are listed on the [Resource Management command](../../akamas-reference/cli-reference/cli-reference-2) page.

### Best Practices

Properly modeling the application or service to be optimized by identifying the components and their parameters to tune is the first important step in the optimization process. Some best practices are described here below.

**Modeling only relevant components**

When defining the system and its components, it is convenient to focus only on those components that are either providing tunable parameters or key metrics (or KPIs).

Key metrics are those used to:

* define the optimization [goal and constraints](../../akamas-reference/glossary/goals-and-constraints), either as metrics that are expected to be improved by the optimization or as metrics representing constraints. For example, a typical goal is to optimize the application throughput. In this case, a Web Application component should include service metrics such as transaction throughput or transaction response time.
* support the analysis of the optimization results, as metrics that are useful to measure the impact of parameter tuning on the performance, efficiency, or reliability of the system. For example, a Linux OS component could be used to assess the impact of the optimization on the system-level metrics such as CPU utilization.

Please note that the metrics used to define the optimization goal and constraints are mandatory as they are used by the Akamas AI engine to validate and score each tested configuration against the goal. Other metrics that are not related to the optimization goal and constraints can be considered optional from a pure optimization implementation perspective.

When defining the optimization study, it is always possible to select which parameters and metrics to consider, thus which components are modeled in the system. Therefore, a system could be modeled by all components that at some point are going to be optimized, even if not used in the current optimization study. However, the recommended approach is to model the system only with components whose parameters (and relevant metrics) are to be tuned by the current study.

**Reusing systems whenever possible**

Whenever possible, it is recommended to model systems and their components by considering how these could be reused for multiple optimization studies in different contexts.

For example, it might be useful to create a simple system containing only one component (e.g. the JVM) for a first optimization study. A new system might then be created to include other components (e.g. the application server) for more advanced optimization studies.

Please, also notice that systems (and other Akamas artifacts) can be shared with different teams thanks to the definition of Akamas [workspace](../../akamas-reference/glossary/workspaces).

**Modeling systems with horizontal scalability**

A typical optimization target is a cluster, i.e. a system made of multiple instances that provide horizontal scalability (e.g. a Kubernetes deployment with several replicas). In this scenario, all the instances are supposed to be identical both from a code and configuration perspective. In this scenario, the recommended approach is to create only one component that represents a generic instance of the cluster. This way, all the instances will be tuned in exactly the same way.

In this scenario, the associated automation [workflow](../../akamas-reference/glossary/workflows) needs to be configured to ensure that each configuration is applied to the whole cluster, by propagating the parameter configuration to all of the cluster instances, not just to a single instance represented by the modeled component whose metrics are collected and used to evaluate the overall cluster behavior under that configuration.

Notice that in order for this approach to work correctly, it is also important to verify that the cluster is correctly monitored by the telemetry providers. Depending on the telemetry technology in use, the clustered system may be presented as either a single entity, with aggregated metrics (e.g. a Kubernetes deployment with the total CPU usage of all the replica pods), or as multiple entities, each corresponding to the different instances in the cluster:

* in case aggregated metrics are provided by the telemetry provider for the cluster, these metrics can be simply assigned to the component modeling the whole cluster;
* in case only instance-level metrics are made available by the telemetry provider, telemetry instances need to be configured in Akamas so as to aggregate the metrics of the cluster instances (e.g. averaging CPU utilization, summing memory usage, etc.), depending on how each specific metric is expected to be used in the goal and constraints or in the study results.
