Backpressure- und Lastregulierungsmuster
Halten Sie Systeme bei Überlast mit Backpressure, Rate Limiting und Load-Shedding-Mustern stabil, die auf OTP-Primitiven aufbauen.
Backpressure- und Lastregulierungsmuster ist eine kostenlose Erlang OTP: Distributed & Fault-Tolerant Systems Programming-Lektion auf CoddyKit. Dies ist Lektion 4 von 4. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des Erlang OTP: Distributed & Fault-Tolerant Systems Programming-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der Erlang OTP: Distributed & Fault-Tolerant Systems Programming-Kurs umfasst insgesamt 4 Lektionen.
Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.
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
callthrottles 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
Häufig gestellte Fragen
Ist die Lektion „Backpressure- und Lastregulierungsmuster“ kostenlos?
Ja — der vollständige Text von „Backpressure- und Lastregulierungsmuster“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des Erlang OTP: Distributed & Fault-Tolerant Systems Programming-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der Erlang OTP: Distributed & Fault-Tolerant Systems Programming-Kurs umfasst insgesamt 4 Lektionen.
Was lerne ich in „Backpressure- und Lastregulierungsmuster“?
Halten Sie Systeme bei Überlast mit Backpressure, Rate Limiting und Load-Shedding-Mustern stabil, die auf OTP-Primitiven aufbauen. Du übst Erlang OTP: Distributed & Fault-Tolerant Systems Programming mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.
Brauche ich Erfahrung, um Erlang OTP: Distributed & Fault-Tolerant Systems Programming zu starten?
Keine Vorkenntnisse erforderlich. Erlang OTP: Distributed & Fault-Tolerant Systems Programming auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 4 von 4.
Wie lange dauert die Lektion „Backpressure- und Lastregulierungsmuster“?
Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.
Kann ich in dieser Erlang OTP: Distributed & Fault-Tolerant Systems Programming-Lektion Code schreiben und ausführen?
Ja. Jede Erlang OTP: Distributed & Fault-Tolerant Systems Programming-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.
Alle Lektionen in diesem Kurs
- Entwurf für hohe Verfügbarkeit
- Muster für verteilten Konsens
- Fallstudien zu Erlang OTP
- Backpressure- und Lastregulierungsmuster