# Optimizing a sample Linux system

In this study, Akamas is tasked with the optimization of Linux1, a Linux-based system (Ubuntu). The study's goal is to maximize the throughput of the computations of the [Sysbench](https://github.com/akopytov/sysbench) CPU benchmark.

Sysbench is a suite of benchmarks for CPU, file system, memory, threads, etc… typically used for testing the performance of databases.

System1 comes with a [Node Exporter](https://github.com/prometheus/node_exporter) that collects system metrics that Akamas consumes through a [Prometheus provider](https://docs.akamas.io/akamas-docs/3.1.3/integrating-akamas/integrating-telemetry-providers/prometheus-provider). Concerning Sysbench metrics, The study uses the [CSV provider](https://docs.akamas.io/akamas-docs/3.1.3/integrating-akamas/integrating-telemetry-providers/csv-provider) to make them available to Akamas.

The study uses Sysbench to execute a performance test against System1.

#### Telemetry <a href="#telemetry" id="telemetry"></a>

1. Setup a Prometheus and a Node Exporter to monitor the System
2. Install the Prometheus provider
3. Create a provider instance:

{% code lineNumbers="true" %}

```yaml
provider: "Prometheus"
config:
  address: "linux1" # address of the Prometheus of system1
  port: 9090 # port of the Prometheus of system1
  component: "linux1-linux"
```

{% endcode %}

4\. Install the CSV File provider.

5\. Create a provider instance:

{% code lineNumbers="true" %}

```yaml
provider: "CSV"
config:
 address: "linux1"
 authType: "password"
 username: "ubuntu"
 auth: "[INSERT PASSWORD HERE]"
 protocol: scp
 remoteFilePattern: "/home/ubuntu/benchmark_log.csv" # the remote path of the csv with the metrics of the benchmark
 componentColumn: "component" # which column of the csv should contain the name of the component
 csvFormat: "horizontal"
metrics:
- metric: "throughput"
  datasourceMetric: "events_per_second"
```

{% endcode %}

#### Workflow <a href="#workflow" id="workflow"></a>

The study uses a four-task workflow to test System1 with a new configuration:

1. Task **Configure OS**, which leverages the [LinuxConfigurator](https://docs.akamas.io/akamas-docs/3.1.3/akamas-reference/workflow-operators/linuxconfigurator-operator) operator to apply a new set of Linux configuration parameters
2. Task **Start benchmark,** which leverages the [Executor operator](https://docs.akamas.io/akamas-docs/3.1.3/akamas-reference/workflow-operators/executor-operator) to launch the benchmark

The following YAML file represents the complete workflow definition:

{% code lineNumbers="true" %}

```yaml
name: "workflow for linux 1"
tasks
- name: "Configure OS"
  operator: "LinuxConfigurator"
  arguments:
    component: linux1-linux

- name: "Start benchmark"
  operator: "Executor"
  arguments:
    command: "bash /home/ubuntu/benchmark.sh"
    host:
      hostname: "linux1"
      username: "ubuntu"
      password: "[INSERT_HERE_PASSWORD]"
```

{% endcode %}

#### System <a href="#system" id="system"></a>

Within Akamas, System1 is modeled by a system of two components:

* **system1-linux**, which represents the actual Linux system with its metrics and parameters and is of type **Ubuntu 16.04**
* **system1-bench**, which represents the Sysbench with its metrics and is of type **Sysbench**

The following YAML file represents the definition of the Sysbench component type:

{% code lineNumbers="true" %}

```yaml
name: "Sysbench"
description: "A component-type for Sysbench"
metrics:
- "throughput" # only one metric
```

{% endcode %}

#### Study <a href="#study" id="study"></a>

* Goal: minimize the throughput of the benchmark
* Windowing: take the default (compute the score for the entire duration of a trial)
* Parameters selection: select only CPU scheduling parameters
* Metrics selection: select only the throughput of the benchmark
* Trials: 3
* Steps: one baseline and one optimize

The following YAML file represents the definition of the study:

{% code lineNumbers="true" %}

```yaml
system: "system for linux1"
workflow: "workflow ofr linux1"
name: "linux optimization with sysbench"
description: "Optimizing an Ubuntu instance with a CPU intensive benchmark: sysbench"
goal:
  objective: minimize
  function:
    formula: "linux1-benchmark.throughput"
metricsSelection:
  - "linux1-benchmark.throughput"
parametersSelection:
  - name: "linux1-linux.os_cpuSchedMinGranularity"
  - name: "linux1-linux.os_cpuSchedWakeupGranularity"
  - name: "linux1-linux.os_CPUSchedMigrationCost"
  - name: "linux1-linux.os_CPUSchedChildRunsFirst"
  - name: "linux1-linux.os_CPUSchedLatency"
  - name: "linux1-linux.os_CPUSchedAutogroupEnabled"
  - name: "linux1-linux.os_CPUSchedNrMigrate"
numberOfTrials: 3
steps:
  - name: "baseline"
    type: "baseline"
    values:
      linux1-linux.os_cpuSchedMinGranularity: 2250000
      linux1-linux.os_cpuSchedWakeupGranularity: 3000000
      linux1-linux.os_CPUSchedMigrationCost: 500000
      linux1-linux.os_CPUSchedChildRunsFirst: 0
      linux1-linux.os_CPUSchedLatency: 18000000
      linux1-linux.os_CPUSchedAutogroupEnabled: 1
      linux1-linux.os_CPUSchedNrMigrate: 32
  - name: "optimization"
    type: "optimize"
    numberOfExperiments: 99
    maxFailedExperiments: 25
```

{% endcode %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.akamas.io/akamas-docs/3.1.3/knowledge-base/optimizing-a-sample-linux-system.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
