0Pricing
Erlang OTP: Distributed & Fault-Tolerant Systems Programming · レッスン

バックプレッシャーと負荷制御のパターン

OTPのプリミティブを基盤とするバックプレッシャー、レート制限、ロードシェディングのパターンを使い、過負荷時もシステムを安定させます。

「バックプレッシャーと負荷制御のパターン」はCoddyKit上の無料Erlang OTP: Distributed & Fault-Tolerant Systems Programmingレッスンです。 これはレッスン4/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはErlang OTP: Distributed & Fault-Tolerant Systems Programming学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Erlang OTP: Distributed & Fault-Tolerant Systems Programmingコースには全4レッスンが含まれています。

このレッスンの一部はまだ翻訳されておらず、英語で表示されています。

What Is Backpressure?

When work arrives faster than a system can process it, queues grow and latency explodes. Backpressure is the practice of signalling producers to slow down so the system stays stable instead of melting down.

The Unbounded Queue Problem

An async gen_server:cast never blocks the caller, so its mailbox can grow without limit under load — the system runs out of memory before it ever rejects work.

Synchronous Calls as Backpressure

Using gen_server:call instead of cast makes the caller wait until the server is ready, naturally throttling producers to the server speed.

Reply = gen_server:call(worker, {process, Job}, 5000).

Bounded Queues

Maintain an explicit counter of in-flight work and reject or block new requests once a limit is reached, rather than letting the mailbox grow.

handle_call({job, J}, _From, #{n := N} = S) when N < 100 ->
    {reply, ok, S#{n := N + 1}};
handle_call({job, _}, _From, S) ->
    {reply, {error, overloaded}, S}.

Load Shedding

Under extreme load, the best move can be to shed low-priority work fast — returning an error immediately — to protect the system for high-priority requests.

Rate Limiting with Tokens

A token-bucket limiter grants a fixed number of permits per interval; requests beyond that wait or fail. This caps throughput predictably.

case take_token(Bucket) of
    ok -> do_work();
    empty -> {error, rate_limited}
end.

Measuring Pressure

The mailbox length of a bottleneck process is a live pressure gauge. Monitor it and trigger shedding before it grows dangerous.

process_info(Worker, message_queue_len).

Pooling for Throughput

A pool of worker processes (e.g. via poolboy) bounds concurrency: requests queue for a free worker, giving natural backpressure with controlled parallelism.

Circuit Breakers

When a downstream dependency is failing, a circuit breaker opens to stop sending requests for a cooldown period, preventing pileups and giving the dependency time to recover.

Timeouts as Protection

Always give gen_server:call a finite timeout. An unbounded wait lets a stuck server block callers indefinitely; a timeout converts a hang into a fast, recoverable error.

case catch gen_server:call(srv, req, 2000) of
    {ok, R} -> R;
    _ -> {error, busy}
end.

Choosing a Strategy

Combine patterns: synchronous calls for natural throttling, bounded queues to cap memory, rate limiting for fairness, and load shedding plus circuit breakers as last-resort protection.

Quick Check

Test your load regulation knowledge.

Recap

You learned to keep systems stable under overload:

  • Backpressure signals producers to slow down
  • Synchronous call throttles naturally; bounded queues cap memory
  • Rate limiting enforces fairness; load shedding protects priority work
  • Worker pools bound concurrency; circuit breakers stop downstream pileups
  • Monitor mailbox length as a live pressure gauge

よくある質問

「バックプレッシャーと負荷制御のパターン」レッスンは無料ですか?

はい。「バックプレッシャーと負荷制御のパターン」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Erlang OTP: Distributed & Fault-Tolerant Systems Programmingコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Erlang OTP: Distributed & Fault-Tolerant Systems Programmingコースには全4レッスンが含まれています。

「バックプレッシャーと負荷制御のパターン」で何を学びますか?

OTPのプリミティブを基盤とするバックプレッシャー、レート制限、ロードシェディングのパターンを使い、過負荷時もシステムを安定させます。 ブラウザで直接実行するハンズオンコードでErlang OTP: Distributed & Fault-Tolerant Systems Programmingを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

Erlang OTP: Distributed & Fault-Tolerant Systems Programmingを始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのErlang OTP: Distributed & Fault-Tolerant Systems Programmingは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン4/4です。

「バックプレッシャーと負荷制御のパターン」レッスンにはどのくらい時間がかかりますか?

ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。

このErlang OTP: Distributed & Fault-Tolerant Systems Programmingレッスンでコードを書いて実行できますか?

はい。すべてのErlang OTP: Distributed & Fault-Tolerant Systems Programmingレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。

このコースのすべてのレッスン

  1. 高可用性の設計
  2. 分散合意パターン
  3. Erlang OTPのケーススタディ
  4. バックプレッシャーと負荷制御のパターン
← Erlang OTP: Distributed & Fault-Tolerant Systems Programmingに戻る