أنماط التحكم في الضغط وتنظيم الحمل
حافظ على استقرار الأنظمة تحت الحمل الزائد باستخدام التحكم في الضغط وتحديد المعدل وإسقاط الحمل، بالاعتماد على بدائيات OTP.
أنماط التحكم في الضغط وتنظيم الحمل درس مجاني في Erlang OTP: Distributed & Fault-Tolerant Systems Programming على CoddyKit. هذا هو الدرس 4 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في 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
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
تعلم Erlang مع معلم ذكاء اصطناعي — مجانًا
اكتب وقم بتشغيل أكوادك الفعلية في المتصفح، واحصل على مساعدة فورية من معلم ذكاء اصطناعي متاح 24/7، واستمر من حيث توقفت على الويب أو في التطبيق.
- الدورات
- 12
- الدروس
- 48
الأسئلة الشائعة
هل درس «أنماط التحكم في الضغط وتنظيم الحمل» مجاني؟
نعم — نص درس «أنماط التحكم في الضغط وتنظيم الحمل» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة 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/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ Erlang OTP: Distributed & Fault-Tolerant Systems Programming؟
لا تُشترط خبرة سابقة. Erlang OTP: Distributed & Fault-Tolerant Systems Programming على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 4 من أصل 4.
كم من الوقت يستغرق درس «أنماط التحكم في الضغط وتنظيم الحمل»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس Erlang OTP: Distributed & Fault-Tolerant Systems Programming هذا؟
نعم. كل درس في Erlang OTP: Distributed & Fault-Tolerant Systems Programming يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- التصميم لتحقيق التوافر العالي
- أنماط الإجماع الموزّع
- دراسات حالة حول Erlang OTP
- أنماط التحكم في الضغط وتنظيم الحمل