負荷制限リファレンスガイド
experimental|
この技術は、experimentalと考えられています。 experimental モードでは、アイデアを成熟させるために早期のフィードバックが求められます。ソリューションが成熟するまでの間、プラットフォームの安定性や長期的な存在を保証するものではありません。フィードバックは メーリングリスト や GitHubの課題管理 で受け付けています。 とりうるステータスの完全なリストについては、 FAQの項目 を参照してください。 |
Load shedding is the practice of detecting service overload and rejecting requests. By rejecting requests when overloaded, load shedding keeps the application alive. With priority load shedding, the application even keeps working, albeit in a degraded state: only a fraction of requests is handled, others are rejected early. You should consider using it if your application runs in a dynamic environment with a real risk of getting overloaded and is not fronted by another service that sheds load already.
Quarkus では、 quarkus-load-shedding エクステンションによって負荷制限メカニズムが提供されます。
1. 負荷制限エクステンションの使用
負荷制限エクステンションを使用するには、プロジェクトに io.quarkus:quarkus-load-shedding エクステンションを追加する必要があります。
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-load-shedding</artifactId>
</dependency>
implementation("io.quarkus:quarkus-load-shedding")
When added, load shedding is enabled.
It can be disabled by setting quarkus.load-shedding.enabled to false.
There are 2 variants of load shedding: pure and priority-based.
Pure load shedding rejects all requests when overload is detected.
Priority load shedding only rejects a fraction of requests even if overload is detected, based on application-defined criteria.
By default, priority load shedding is enabled.
It can be disabled by setting quarkus.load-shedding.priority.enabled to false.
There are 2 ways of customizing priority load shedding:
-
By implementing
io.quarkus.load.shedding.RequestPrioritizer, the application can decide which requests can be rejected early on and which requests can only be rejected when there’s no other choice. -
By implementing
io.quarkus.load.shedding.RequestClassifier, the application can classify requests into cohorts which are rejected independently.
Other configuration options are described below, although they should typically be left untouched.
2. 負荷制限アルゴリズム
負荷制限アルゴリズムには 2 つの部分があります。
-
過負荷検出
-
優先負荷制限 (オプション)
2.1. 過負荷検出
現在のサービスが過負荷かどうかを検出するために、TCP Vegas を応用しています。
This algorithm starts with a configurable limit of in-flight requests, by default 100. If the current number of concurrent in-flight requests reaches the limit, overload situation is signalled.
That is not very interesting, but the algorithm dynamically adjusts the limit based on the size of the request queue. If the queue is short, more requests can be handled and the limit increases; if the queue is long, fewer requests can be handled and the limit decreases. The limit cannot be increased indefinitely; there’s a configurable maximum, by default 1000.
There’s no actual queue of requests that we could monitor, though, so the algorithm estimates the current length of a request queue based on previously seen response times. The longer recent requests take, compared to the recent lowest response time, the longer the queue is supposed to be.
2.2. 優先負荷制限
過負荷状況が通知されると、優先負荷制限が呼び出されます。
If priority load shedding is disabled, there’s nothing to do and all requests are rejected immediately. However, by default, priority load shedding is enabled, which means a request is only rejected if the current CPU load is high enough.
| Priority load shedding is currently always based on CPU load. Other mechanisms are possible (such as network utilization), but currently not implemented. |
To determine whether a request should be rejected, 2 attributes are considered:
-
リクエストの優先度
-
リクエストコホート
静的に定義された優先度が 5 つ、コホートが 128 あり、合計で 640 のリクエストグループになります。
After both priority and cohort are assigned to a request, a request group number is computed. The group number is smaller for higher priority requests and higher for lower priority requests. If the group number is higher that the current CPU load, the request is rejected, otherwise it is allowed even in an overload situation.
The group number is actually not compared to the CPU load directly; instead, it is compared to a function of CPU load.
The function is (1 - load^3) * 640, where load is the CPU load as a number between 0.0 and 1.0, and 640 is a number of requests group as mentioned above.
|
2.2.1. リクエストの優先度のカスタマイズ
優先度は io.quarkus.load.shedding.RequestPrioritizer によって割り当てられます。
io.quarkus.load.shedding.RequestPriority 列挙には、 CRITICAL、 IMPORTANT、 NORMAL、 BACKGROUND、 DEGRADED の 5 つの静的に定義された優先度があります。
デフォルトでは、リクエスト prioritizer が適用されない場合、優先度は NORMAL であると見なされます。
デフォルトの prioritizer が 1 つあり、非アプリケーションエンドポイントへのリクエストには優先度 CRITICAL が割り当てられます。
@Priority は宣言されていません。
RequestPrioritizer インターフェイスのカスタム実装を定義することが可能です。
実装は CDI Bean である必要があり、そうでない場合は無視されます。
typesafe な解決の CDI ルールに従う必要があります。
つまり、異なる @Priority 値を持つ複数の実装が存在し、そのうちのいくつかが @Alternative である場合、最も高い優先度値を持つ代替実装のみが保持されます。
代替実装となる実装がない場合、すべての実装が保持され、 @Priority の降順で並べ替えられます (最も高い優先度の値が最初になります)。
2.2.2. リクエストコホートのカスタマイズ
コホートは io.quarkus.load.shedding.RequestClassifier によって割り当てられます。
静的に定義されたコホートは 128 あり、最小番号は 1、最大番号は 128 です。
分類子はこの範囲内の番号を返す必要があります。返さない場合、番号が自動的に調整されます。
リモート IP アドレスと現在の時刻のハッシュに基づいてコホートを割り当てるデフォルトの分類子が 1 つあり、IP アドレスのコホートはおよそ 1 時間ごとに変更されます。
@Priority は宣言されていません。
RequestClassifier インターフェイスのカスタム実装を定義することが可能です。
実装は CDI Bean である必要があり、そうでない場合は無視されます。
typesafe な解決の CDI ルールに従う必要があります。
つまり、異なる @Priority 値を持つ複数の実装が存在し、そのうちのいくつかが @Alternative である場合、最も高い優先度値を持つ代替実装のみが保持されます。
代替実装となる実装がない場合、すべての実装が保持され、 @Priority の降順で並べ替えられます (最も高い優先度の値が最初になります)。
3. 制限
負荷制限エクステンションは現在、HTTP リクエストにのみ適用され、リクエスト/レスポンスのネットワークインタラクションに大きく偏っています。 そのため、gRPC、WebSocket、その他の HTTP 経由のストリーミングはサポートされていません。 メッセージングなどの Quarkus アプリケーションへの他の「エントリーポイント」もサポートされていません。
さらに、負荷制限の実装は現時点ではかなり基本的なものであり、実稼働環境で十分にテストされていません。 改善が必要になる可能性があります。
4. 設定リファレンス
ビルド時に固定された設定プロパティー。その他の設定プロパティーはすべて実行時にオーバーライド可能です。
Configuration property |
タイプ |
デフォルト |
|---|---|---|
Whether load shedding should be enabled. Currently, this only applies to incoming HTTP requests. Environment variable: Show more |
ブーリアン |
|
The maximum number of concurrent requests allowed. Environment variable: Show more |
int |
|
The Environment variable: Show more |
int |
|
The Environment variable: Show more |
int |
|
The probe factor of the Vegas overload detection algorithm. Environment variable: Show more |
double |
|
The initial limit of concurrent requests allowed. Environment variable: Show more |
int |
|
Whether priority load shedding should be enabled. Environment variable: Show more |
ブーリアン |
|
5. さらに詳しく
Netflix Technology ブログ:
Uber Engineering ブログ:
Amazon Builders' Library:
Google Cloud ブログ:
CodeReliant ブログ:
TCP Vegas:
-
TCP Congestion Control: A Systems Approach, Chapter 5: Avoidance-Based Algorithms