0Pricing
Erlang OTP: Distributed & Fault-Tolerant Systems Programming · Lekcja

Analiza pamięci i dostrajanie garbage collection

Diagnozuj wzrost zużycia pamięci, analizuj sterty poszczególnych procesów i dostrajaj garbage collection Erlanga, aby utrzymać zdrowie długo działających węzłów.

Analiza pamięci i dostrajanie garbage collection to bezpłatna lekcja Erlang OTP: Distributed & Fault-Tolerant Systems Programming na CoddyKit. To lekcja 4 z 4. Możesz przeczytać całą lekcję poniżej za darmo — a potem ćwiczyć ją interaktywnie w przeglądarce z wbudowanym edytorem kodu i tutorem AI dostępnym 24/7. To część ścieżki edukacyjnej Erlang OTP: Distributed & Fault-Tolerant Systems Programming, a Twój postęp synchronizuje się między webem a aplikacją CoddyKit. Kurs Erlang OTP: Distributed & Fault-Tolerant Systems Programming zawiera 4 lekcji w sumie.

Części tej lekcji nie zostały jeszcze przetłumaczone i są wyświetlane po angielsku.

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/0 gives a system-wide breakdown
  • process_info/2 inspects 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 hibernate for idle processes

Często zadawane pytania

Czy lekcja „Analiza pamięci i dostrajanie garbage collection” jest bezpłatna?

Tak — pełny tekst „Analiza pamięci i dostrajanie garbage collection” jest dostępny za darmo tutaj w sieci. Aby ćwiczyć ją interaktywnie (wbudowany edytor kodu i tutor AI dostępny 24/7) i odblokować resztę kursu Erlang OTP: Distributed & Fault-Tolerant Systems Programming, przejdź na CoddyKit PRO. Kurs Erlang OTP: Distributed & Fault-Tolerant Systems Programming zawiera 4 lekcji w sumie.

Co nauczysz się w „Analiza pamięci i dostrajanie garbage collection”?

Diagnozuj wzrost zużycia pamięci, analizuj sterty poszczególnych procesów i dostrajaj garbage collection Erlanga, aby utrzymać zdrowie długo działających węzłów. Ćwiczysz Erlang OTP: Distributed & Fault-Tolerant Systems Programming z praktycznym kodem, który uruchamiasz bezpośrednio w przeglądarce, a tutor AI dostępny 24/7 odpowiada na Twoje pytania podczas pracy nad lekcją.

Czy potrzebuję doświadczenia, aby zacząć Erlang OTP: Distributed & Fault-Tolerant Systems Programming?

Nie wymagamy żadnego doświadczenia. Erlang OTP: Distributed & Fault-Tolerant Systems Programming w CoddyKit jest strukturyzowany dla początkujących i zaawansowanych użytkowników, więc możesz zacząć tutaj lub od początku i uczyć się w swoim tempie. To lekcja 4 z 4.

Ile czasu zajmuje lekcja „Analiza pamięci i dostrajanie garbage collection”?

Większość lekcji CoddyKit trwa około 5–10 minut. Każda lekcja to mały, interaktywny krok, dzięki czemu robisz systematyczne postępy i zawsze wracasz dokładnie do tego samego miejsca — na webie i w aplikacji.

Czy mogę pisać i uruchamiać kod w tej lekcji Erlang OTP: Distributed & Fault-Tolerant Systems Programming?

Tak. Każda lekcja Erlang OTP: Distributed & Fault-Tolerant Systems Programming zawiera wbudowany edytor kodu, więc piszesz i uruchamiasz prawdziwy kod bezpośrednio w przeglądarce i od razu otrzymujesz sprzężenie zwrotne od AI — bez konfiguracji na komputerze.

Wszystkie lekcje w tym kursie

  1. Techniki profilowania Erlanga
  2. Śledzenie i debugowanie systemów rozproszonych
  3. Integracja zbierania metryk i monitorowania
  4. Analiza pamięci i dostrajanie garbage collection
← Powrót do Erlang OTP: Distributed & Fault-Tolerant Systems Programming