تحليل الذاكرة وضبط جمع البيانات المهملة
شخّص نمو الذاكرة، وافحص أكوام الذاكرة لكل عملية، واضبط جمع البيانات المهملة في Erlang للحفاظ على سلامة العُقد طويلة التشغيل.
تحليل الذاكرة وضبط جمع البيانات المهملة درس مجاني في 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 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
Why Memory Matters
Erlang nodes can run for months. A small per-process leak or unbounded mailbox grows silently until the node is killed by the OS. Observability into memory is essential.
System-Wide Memory
erlang:memory/0 returns a breakdown: total, processes, atom, binary, ETS and more. Watch the categories that grow over time.
erlang:memory().Per-Process Inspection
process_info/2 reveals a single process heap, message queue length and more — key for finding the culprit.
process_info(Pid, [memory, message_queue_len, heap_size]).The Mailbox Trap
If a process receives faster than it handles, its mailbox grows without bound. A large message_queue_len is the classic sign of an overloaded consumer.
Binaries and Refc Leaks
Large binaries are reference-counted and shared off-heap. A process holding a tiny sub-binary can pin a huge parent binary. Watch the binary memory category closely.
Finding the Worst Offenders
Sort all processes by memory to find leaks fast.
lists:sort(fun({_,A},{_,B}) -> A > B end,
[{P, element(2, process_info(P, memory))} || P <- processes()]).How Erlang GC Works
Each process has its own private heap and is garbage-collected independently — there is no global stop-the-world pause. Collection runs when a process heap fills.
Triggering GC Manually
For a process you suspect is holding garbage, force a collection and re-measure.
erlang:garbage_collect(Pid),
process_info(Pid, memory).Tuning the Heap
Spawn options like min_heap_size and fullsweep_after tune GC for hot processes, trading memory for fewer collections.
spawn_opt(fun work/0, [{min_heap_size, 1000}, {fullsweep_after, 10}]).Hibernation
Idle processes can call hibernate to compact their heap to the minimum, freeing memory until the next message arrives — great for many mostly-idle connections.
proc_lib:hibernate(?MODULE, loop, [State]).Watching ETS Tables
ETS tables live outside process heaps and do not shrink automatically. A growing ets memory category often means stale rows; periodically prune or use tables with a bounded size.
ets:info(my_table, memory).Quick Check
Test your memory tuning knowledge.
Recap
You learned to analyze and tune memory:
erlang:memory/0gives a system-wide breakdownprocess_info/2inspects per-process heap and mailbox- Growing mailboxes and pinned binaries are common leak sources
- Each process is GC-ed independently; no global pause
- Tune with spawn options and use
hibernatefor idle processes
الأسئلة الشائعة
هل درس «تحليل الذاكرة وضبط جمع البيانات المهملة» مجاني؟
نعم — نص درس «تحليل الذاكرة وضبط جمع البيانات المهملة» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Erlang OTP: Distributed & Fault-Tolerant Systems Programming، انتقل إلى CoddyKit PRO. تتضمن دورة Erlang OTP: Distributed & Fault-Tolerant Systems Programming 4 دروس في المجموع.
ماذا ستتعلم في «تحليل الذاكرة وضبط جمع البيانات المهملة»؟
شخّص نمو الذاكرة، وافحص أكوام الذاكرة لكل عملية، واضبط جمع البيانات المهملة في Erlang للحفاظ على سلامة العُقد طويلة التشغيل. تتمرن على 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
- تتبّع الأنظمة الموزعة وتصحيح أخطائها
- تكامل المقاييس والمراقبة
- تحليل الذاكرة وضبط جمع البيانات المهملة