# パフォーマンス {#performance}

Takumi Runner はデフォルトの GitHub ホステッドランナーと比較し、ほとんどの条件では同等かそれ以上のパフォーマンスを発揮します。Takumi Runner をご利用になることによって実行時間が基本的には長くならないよう検証及び最適化されています。

## ベンチマーク結果 {#benchmark-results}

次の表には、いくつかの CI ワークフローにおける実行時間の結果が記載されています。

| ワークフロー | GitHub ホステッドランナー | Takumi Runner | 差分     |
| ------------ | ------------------------- | ------------- | -------- |
| Frontend CI  | 13m 26s                   | 12m 58s       | -28s     |
| Rust CI      | 39m 37s                   | 29m 16s       | -10m 21s |
| Proto CI     | 51s                       | 1m 56s        | +1m 5s   |

上記のワークフローはlint、ビルド、テスト実行など複数のジョブにより構成された典型的な CI ワークフローです。ジョブの規模が大きいほど実行時間が短縮される傾向があり、特に CPU の使用率が高いジョブに関してはパフォーマンスの向上がより確認しやすいです。その一方で数分以内の小さなジョブだとわずかに遅くなることもあります。

Takumi Runner は、ジョブのキューの待ち時間が GitHub ホステッドランナーと比較して 5~10 秒長くなります。これにより、直列で 3 つのジョブがあるワークフローだと、合計 15〜30 秒長くなることがあります。ただし、Takumi Runner ではジョブの処理自体が速いため、多くのジョブの実行時間は GitHub ホステッドランナーより短くなります。

<details>
<summary>Frontend CI の内容</summary>

Frontend CI は、フォーマット、TypeScript の型チェック、Jest によるテストを並列に実行します。

```
jobs:
    check-formatting:
        name: Check formatting
        runs-on: <ubuntu-latest | takumi-runner>
        steps: <checkout repo, install neccesary packages, check lint for js, markdown, css, etc>

    check-typing:
        name: Check typing
        runs-on: <ubuntu-latest | takumi-runner>
        steps: <checkout repo, install neccesary packages, run pnpm typescript checks>

    jest:
        runs-on: <ubuntu-latest | takumi-runner>
        name: Jest test (${{ matrix.segment }} - ${{ matrix.chunk }})

        strategy:
            fail-fast: false
            matrix:
                segment: ['FOSS', 'EE']
                chunk: [1, 2, 3]

        steps: <checkout repo, install neccesary packages, test with jest>

    all-checks-pass:
        needs: [jest, check-formatting, check-typing]
        name: All checks pass
        runs-on: <ubuntu-latest | takumi-runner>
        steps: <check if all other jobs passed>
```

</details>

<details>
<summary>Rust CI の内容</summary>

Rust CI は、アプリケーションのビルド、lint、テストを行います。

```
jobs:
    check-changes:
        runs-on: <ubuntu-latest | takumi-runner>
        name: Check for changes
        steps: <checkout repo, check for changes>

    build:
        name: Build services
        needs: check-changes
        runs-on: <ubuntu-latest | takumi-runner>
        steps: <checkout repo, install rust, build rust services>

    check-linting:
        name: Run linting
        needs: check-changes
        runs-on: <ubuntu-latest | takumi-runner>
        steps: <checkout repo, install neccesary packages, run linting>

    test:
        name: Run tests
        needs: check-changes
        runs-on: <ubuntu-latest | takumi-runner>
        steps: <checkout repo, install dependencies and packages, run tests>

    all-checks-pass:
        needs: [build, test, check-linting]
        name: All checks pass
        runs-on: <ubuntu-latest | takumi-runner>
        steps: <check if all other jobs passed>
```

</details>

<details>
<summary>Proto CI の内容</summary>

Proto CI は、Protocol Buffers の lint と破壊的変更の有無を確認します。

```
jobs:
    check-changes:
        runs-on: <ubuntu-latest | takumi-runner>
        name: Check for changes
        outputs:
            proto: ${{ steps.filter.outputs.proto || 'true' }}
        steps: <checkout repo, check for changes>

    check-linting:
        name: Check linting
        needs: check-changes
        runs-on: <ubuntu-latest | takumi-runner>

        steps: <checkout repo, install buf, lint proto files>

    check-breaking-changes:
        name: Check for breaking changes
        needs: check-changes
        runs-on: <ubuntu-latest | takumi-runner>

        steps: <checkout repo, install buf, check for breaking changes>

    all-checks-pass:
        needs: [check-changes, check-linting, check-breaking-changes]
        name: All checks pass
        runs-on: <ubuntu-latest | takumi-runner>
        steps: <check if all other jobs passed>
```

</details>

## ハードウェアベンチマーク {#hardware-benchmarks}

以下のベンチマークは、Takumi Runner と GitHub ホステッドランナーにおける CPU、メモリ、ディスク I/O の性能を比較したものです。Takumi Runner は GitHub ホステッドランナーに合わせて 2 vCPU および 7.8 GiB の RAM を使用しております。これらの測定には `sysbench` と `fio` を使用しています。

| 指標             | GitHub ホステッドランナー | Takumi Runner  |
| ---------------- | ------------------------- | -------------- |
| CPU スループット | 4,098 events/s            | 5,457 events/s |
| メモリ帯域       | 8,493 MiB/s               | 3,433 MiB/s    |
| ディスク書き込み | 1,559 MiB/s               | 416 MiB/s      |
| ディスク読み込み | 117 MiB/s                 | 1,588 MiB/s    |

lint、ビルド、ユニットテスト等多くの CI/CD の処理は CPU バウンドであるため、Takumi Runner の CPU 性能が GitHub ホストランナーの CPU 性能を下回らないことが非常に重要です。
