The Real Fullstack

The Starved Thread Pool

CPU at 3 %, downstream healthy, database idle. Why does every report request time out?

مهندس أول9 دقيقةمختبر تصحيح الأخطاءمحاكي الخط الزمني
javacompletablefutureexecutorservicecsharp

لم يُترجم هذا التحدي إلى العربية بعد. أنت تقرأ النسخة الإنجليزية.

المهمة:Predict what happens with 8 simultaneous reports, identify why the pool stops making progress, and remove the cause instead of buying time.السياق · أهداف التعلّم ▾

Larkspur's reporting endpoint builds a report from three sources in parallel. The parent task and its three sub-tasks share one fixed pool of 8 threads. It worked in testing; at 8 concurrent reports in production it froze completely and stayed frozen.

المهمة: Predict what happens with 8 simultaneous reports, identify why the pool stops making progress, and remove the cause instead of buying time.

أهداف التعلّم

  • Recognise thread-pool starvation (pool-induced deadlock).
  • Never block a pool thread waiting for work queued in the same pool.
  • Compose asynchronous results instead of calling get()/Result.
المحاكاةمحاكاة
/reports"work" pool (8 threads)data services
تشغيل المحاكاة
CompletableFuture<Report> build(long id) {  var c = CompletableFuture.supplyAsync(() -> customers.load(id), io);  var o = CompletableFuture.supplyAsync(() -> orders.load(id), io);  var i = CompletableFuture.supplyAsync(() -> invoices.load(id), io);  // no thread waits: the report is assembled when all three complete  return CompletableFuture.allOf(c, o, i).thenApply(v -> new Report(c.join(), o.join(), i.join()));}

تبسيط

The freeze is shown as two symptoms with deterministic fixes. In reality the threshold depends on pool size and request timing. نموذج تعليمي — الأرقام توضّح سلوكًا وليست قياسات أداء.

المفاهيم

مفيد قبل هذا التحدي

تحديات ذات صلة

المراجع