Trending

World technology news

→
Go 1.5: separating garbage collection pauses from request latency
Software Engineering · 2015
Software Engineering2015

Go 1.5: separating garbage collection pauses from request latency

Compare Go 1.5’s concurrent collector under a fixed workload and measure allocation volume, live memory, and p95 latency independently.

Archive retrospective · Topic year 2015

Developer's JournalPublished: Nov 27, 20266 min read
Reading progress0%
In this article
  1. A collector change is different from a service guarantee
  2. Separate cycle time, pause time, and p95
  3. Prepare a small fixed allocation load
  4. Pin runtime and CPU settings before comparing
  5. Compare collection traces with application observations
  6. Tie the result to a decision a service can verify

A collector change is different from a service guarantee

A telemetry gateway parses messages and forwards them to an operator panel. Processing is usually quick, yet an occasional pause appears in the graph. The question is how much memory management contributes. Go 1.5 in 2015 moved more garbage collection work into concurrent execution with the application. Its release notes expected shorter pauses. This does not specify a real gateway's network response time. Scheduling, allocation work, other CPU activity, and the data path also affect latency. Start with a separate synthetic process that allocates the same number and size of buffers in each sample. The fixture reproduces one pattern while offering several ways to measure it. It does not represent performance numbers from a deployed service.

Separate cycle time, pause time, and p95

While collecting, the runtime identifies reachable objects and can reclaim space from others. Concurrent work may happen alongside application code. Short stop-the-world phases do not account for the complete cycle. The 95th percentile of measured batches describes an important part of their distribution, while the slowest cases still need separate inspection. Averaging p95 values from runs does not produce a combined percentile across every sample. Two processes can allocate the same total bytes while retaining different objects and completing different numbers of collections. Record allocated bytes, observed heap, number of collections, and the relevant latency separately. Write down where measurements start and stop before using one runtime counter to explain a visible delay in the service.

Software delivery pipelineConceptual sketch · summary of the article's technical flow

Prepare a small fixed allocation load

The program times four hundred batches, each allocating 128 buffers of 4096 bytes. A fixed ring retains only the last handful of buffers. This supplies a predictable retention pattern across batches. TotalAlloc delta tracks allocation bytes, NumGC delta counts completed collections, and HeapAlloc is a snapshot of heap allocations. It can include objects that are no longer wanted by the application but have not been collected. Each batch's microsecond elapsed time enters a list, and the p95 estimate is read from sorted samples. Reading runtime memory statistics outside the timed loop avoids charging that operation to every batch. Hold these parameters constant across runtime comparisons. This fixture measures buffer workloads and excludes HTTP, downstream I/O, and client wait time.

package main

import (
    "fmt"
    "runtime"
    "sort"
    "time"
)

var live [64][]byte

func main() {
    times := make([]int, 400)
    var before, after runtime.MemStats
    runtime.ReadMemStats(&before)
    for i := range times {
        started := time.Now()
        for j := 0; j < 128; j++ {
            b := make([]byte, 4096)
            b[0] = byte(j)
            b[len(b)-1] = byte(i)
            live[(i*128+j)%len(live)] = b
        }
        times[i] = int(time.Since(started) / time.Microsecond)
    }
    runtime.ReadMemStats(&after)
    sort.Ints(times)
    fmt.Printf("p95=%d us samples=%d allocated=%d bytes gc=%d heap=%d bytes\n",
        times[(95*len(times)+99)/100-1], len(times),
        after.TotalAlloc-before.TotalAlloc, after.NumGC-before.NumGC,
        after.HeapAlloc)
}

Pin runtime and CPU settings before comparing

Go 1.5 also changed the default GOMAXPROCS to depend on the available cores. Running on the same machine does not automatically control that change. Specify the same GOMAXPROCS and GOGC values in both experiments. Build identical source separately with each exact toolchain and keep build times away from execution times. Alternate the order of trials to make external load or thermal effects easier to identify. Synthetic allocations are independent of network traffic. Any later HTTP test should control arrival rate, connection count, and downstream behavior. Keep individual results and avoid selecting the fastest run alone. A service capacity target requires representative traffic as well as representative runtime settings. Report the settings that make your result reproducible.

Compare collection traces with application observations

A separate GODEBUG gctrace run can show when collection work occurred. Keep those results distinct from untraced timing runs because instrumentation can change the observations. A higher application p95 can coexist with the same completed collection count. Live data, competing CPU work, or application synchronization may differ. A queue that grows during a pause can stretch user-visible waits beyond that pause itself. Add request throughput and timeout or loss counts to a follow-on service exercise. Coinciding times are a clue rather than a general causal proof. For the next experiment, change one suspected allocation path while holding input and correct output constant. Compare peak memory, latency, and service completion together before retaining that change.

Tie the result to a decision a service can verify

An experiment can show shorter pauses with unchanged throughput. A different retention profile can increase live memory and collection work. Interpret results for the workload you ran. Test a smaller buffer ring only if its changed behavior still meets the service contract. Avoid introducing costly abstractions to solve a small measured issue. Keep the evidence for the suspect cause with the output correctness checks, response distribution, and memory budget. The lasting engineering lesson from the 2015 feature is that concurrent collection shifts the time relationship between the runtime and the application. Measurements with clear boundaries help relate a runtime upgrade to experience. An energy-constrained system may also need to measure the same work across its expected device duty cycle.

Further reading / Referencehttps://go.dev/doc/go1.5 ↗
Be the first reader ✎ Write a comment

Reader discussion

Discussion prompt

Which data would you verify before applying this development in your field?

No comments yet. Be the first to contribute.

Write a comment

Comments are real visitor contributions. Repeated, link-heavy or abusive submissions may be limited.