انتقل إلى المحتوى
أمين أبوزيد
MID-002

إدارة الذاكرة

  • 7 درس
  • 4 ساعة تدريب (تقدير)
في هذه الصفحة 8 موضوعات

نص الدروس والتمارين باللغة الإنجليزية، بينما تبقى واجهة الموقع وعناوين الدروس بالعربية.

نظرة عامة

الموضوعات

  • أجيال الـ Heap
  • تخصيص الذاكرة (Allocation)
  • جذور GC (GC roots)
  • جامعو القمامة (Garbage collectors)
  • تسجيل GC

تعلّم أولًا

4 ساعة تدريب (تقدير)

مخرجات التعلم

  1. Explain generational collection, allocation, promotion, and GC roots.
  2. Compare G1, ZGC, and Parallel GC and choose one for a latency- or throughput-focused service.
  3. Enable and read GC logs, and identify allocation pressure and long pauses.
  4. Size heap and container memory limits so the JVM respects the container.
  5. Diagnose a memory leak by comparing heap dumps.

الدروس

  1. 01كيف تخصص JVM الذاكرة للكائنات
  2. 02الأجيال وجذور GC وقابلية الوصول
  3. 03الجامعات: G1 وZGC وParallel
  4. 04قراءة سجلات GC
  5. 05JVM داخل حاوية
  6. 06تسرّب الذاكرة في اللغات المُدارة
  7. 07عرض عملي: اكتشاف تسرّب بلقطتين للـ Heap

المختبر والتمارين

Lab

MID-002-LAB1 · Leaky cache

Outcomes: 1, 3, 5 (and 4) · Time: ~4 h A planted unbounded cache in Shop leaks under load. Enable GC logging, run load, find the rising floor, take two heap dumps, identify the retaining path, fix it (bounded cache), and prove the fix with a second run. Set heap with MaxRAMPercentage for a 1 GiB container. Acceptance: before/after heap charts.

Exercises (assessment: diagnose a provided GC log)

IDOutcomeTask
MID-002-EX011Explain allocation, promotion, and GC roots using a Shop checkout request as the example.
MID-002-EX022Pick a collector for: nightly price import; checkout API p99 under 50 ms on a 16 GB heap; typical 2 GB web API. Justify each.
MID-002-EX033Enable GC logging on Shop; report allocation rate and average young pause over 5 minutes.
MID-002-EX043Given a provided GC log, state whether it shows a leak, allocation pressure, or neither, citing lines.
MID-002-EX054A pod has a 2 GiB limit and -Xmx2g. Explain the risk and give a corrected setting.
MID-002-EX065List the steps to compare two heap dumps and name three leak sources to check first.
أظهر الحلول
  • EX01 Order objects are allocated in Eden by pointer bump; request-scoped objects die in the next young GC; objects still referenced from static or long-lived structures survive and are promoted. Roots: stacks, statics.
  • EX02 Import: Parallel (throughput). 16 GB strict latency: ZGC. Typical API: G1 (default), tune only after measuring.
  • EX03 Use -Xlog:gc*; allocation rate is roughly the sum of (before minus previous after) divided by time; average the young pause durations.
  • EX04 A leak shows the post-collection used size climbing across mixed/full GCs; pressure shows frequent young GCs with a flat floor; "neither" shows flat floor and short pauses.
  • EX05 Heap alone fills the limit; metaspace, stacks and buffers push it over, so the container is OOM-killed. Use -XX:MaxRAMPercentage=70 or -Xmx1400m.
  • EX06 Take dump A and later dump B; compare class histograms; inspect the dominator tree and path to GC roots. Check static collections, caches, and ThreadLocal/listeners.
  • Outcome 1 is also covered by Q01-Q03 and outcome 5 by the lab.

الاختبار

Outcomes: O1 generations and roots · O2 collectors · O3 GC logs · O4 containers · O5 leaks.

اختبار ذاتي لك: لا توجد درجات، ولا يُحفظ أو يُرسل أي شيء. اختر إجابة ثم تحقق منها، ويمكنك المحاولة مرة أخرى كما تشاء.

  1. 1Which is a GC root?O1
  2. 2The generational hypothesis says:O1
  3. 3An unreachable object cycle is:O1
  4. 4Best fit for a nightly batch import:O2
  5. 5Which collector offers very short concurrent pauses on large heaps?O2
  6. 6612M->140M(1024M) in a GC line shows:O3
  7. 7A rising post-GC heap floor suggests:O3
  8. 8A pod is OOM-killed (exit 137) with heap below -Xmx. Likely cause:O4
  9. 9The better way to size heap in containers is:O4
  10. 10Fixing a leak by raising -Xmx will:O5

الجزء العملي

Six exercises MID-002-EX01 to EX06 including the provided GC-log diagnosis, plus the lab with before/after charts. Pass: at least five exercises correct and the leak located and proven fixed.

أخطاء شائعة

Raising -Xmx to "fix" a leak; ignoring container memory limits; tuning flags without measurement.

التقييم

Diagnose a provided GC log.

الصلة بالمسار الوظيفي

Production troubleshooting (SRC-015) and capacity planning (SRC-004).

اكتب للبحث في المستويات والمراحل والوحدات والدروس.