liveBook · Manning

Stop-the-world event

As explained in 100 Go Mistakes and How to Avoid Them

A stop-the-world period is an interval during which application execution is paused while runtime work such as garbage collection is performed.

Mistake: assuming concurrent garbage collection eliminates application pauses. Go’s collector still performs stop-the-world phases that suspend application code while runtime work uses the available CPU time. section 12.9.1

Go’s concurrent mark-and-sweep collector limits, rather than removes, these pauses. Each GC performs two stop-the-world periods before resuming application execution alongside a concurrent phase. section 12.9.1

Diagnose and reduce stop-the-world impact according to the workload:

  • For sudden heap growth, consider increasing GOGC to reduce GC frequency, but validate under production load because larger heaps take longer to clean. section 12.9.2
  • For an extreme, known allocation peak, preallocate a large global buffer so the heap reaches the next GC threshold less frequently. section 12.9.2
  • Use GC tracing during investigation with GODEBUG=gctrace=1 go test -bench=. -v. section 12.9.1

A sudden connection spike

If nearly one million users connect within an hour, rapid heap growth can trigger frequent GC cycles and significant stop-the-world periods, increasing average latency. Increasing GOGC may reduce the pressure; if the spike occurs within seconds, a planned 1 GB allocation can defer collection by raising the heap threshold. section 12.9.2

Figure 12.47 During one hour, we observe a high frequency of GCs.

Use the GC-frequency figure to relate a one-hour user surge to the concentration of collection cycles that produces pause impact. section 12.9.2

How 100 Go Mistakes and How to Avoid Them covers it

How deep it goes
Explains the two GC stop-the-world phases and tuning consequences, but stops short of runtime implementation internals.
Examples
Uses sudden million-user surges, GC-frequency figures, GOGC changes, and a one-gigabyte allocation.
What you can do after
Diagnose GC pause pressure with gctrace and evaluate GOGC or preallocation changes against workload-driven latency.
How it connects
Connects stop-the-world events to garbage collection, mark-and-sweep, GOGC, heap growth, and application latency.

Also explained in

Compare how 2 books explain stop-the-world event →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of 100 Go Mistakes and How to Avoid Them. The section links point to the parts of the book it draws on.