Speicheranalyse und Tuning der Garbage Collection
Diagnostizieren Sie Speicherwachstum, untersuchen Sie Heaps einzelner Prozesse und optimieren Sie Erlangs Garbage Collection, damit langlebige Knoten stabil bleiben.
Speicheranalyse und Tuning der Garbage Collection 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.
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
Häufig gestellte Fragen
Ist die Lektion „Speicheranalyse und Tuning der Garbage Collection“ kostenlos?
Ja — der vollständige Text von „Speicheranalyse und Tuning der Garbage Collection“ 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 „Speicheranalyse und Tuning der Garbage Collection“?
Diagnostizieren Sie Speicherwachstum, untersuchen Sie Heaps einzelner Prozesse und optimieren Sie Erlangs Garbage Collection, damit langlebige Knoten stabil bleiben. 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 „Speicheranalyse und Tuning der Garbage Collection“?
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
- Erlang-Profiling-Techniken
- Verteilte Systeme überwachen und debuggen
- Metriken und Monitoring integrieren
- Speicheranalyse und Tuning der Garbage Collection