# Garbage Collection and Metastability

DevFeed: [Garbage Collection and Metastability](<https://devfeed.tech/articles/garbage-collection-and-metastability-12561.md>)

Original publisher: [Read original article](<http://brooker.co.za/blog/2024/08/14/gc-metastable.html>)

Author: Marc Brooker

Published: 2024-08-14T00:00:00Z

Content type: article

Language: en

Sources: [Marc Brooker's Blog](<https://devfeed.tech/sources/marc-brooker-s-blog.md>), [Marc Brooker's Blog](<https://devfeed.tech/sources/marc-brooker-s-blog-2.md>)

Topics: [systems](<https://devfeed.tech/topics/systems.md>), [Latency](<https://devfeed.tech/topics/latency.md>), [Concurrency](<https://devfeed.tech/topics/concurrency.md>), [Memory Safety](<https://devfeed.tech/topics/memory-safety.md>), [Go Language](<https://devfeed.tech/topics/go-language.md>), [JavaScript](<https://devfeed.tech/topics/javascript.md>), [Python](<https://devfeed.tech/topics/python.md>), [Rust](<https://devfeed.tech/topics/rust.md>)

Tags: [benchmarks](<https://devfeed.tech/tags/benchmarks.md>), [concurrency](<https://devfeed.tech/tags/concurrency.md>), [garbage-collection](<https://devfeed.tech/tags/garbage-collection.md>), [javascript](<https://devfeed.tech/tags/javascript.md>), [latency](<https://devfeed.tech/tags/latency.md>), [memory](<https://devfeed.tech/tags/memory.md>), [memory-management](<https://devfeed.tech/tags/memory-management.md>), [memory-safety](<https://devfeed.tech/tags/memory-safety.md>), [production](<https://devfeed.tech/tags/production.md>), [python](<https://devfeed.tech/tags/python.md>), [rust](<https://devfeed.tech/tags/rust.md>), [systems](<https://devfeed.tech/tags/systems.md>)

## AI overview

The article explains how garbage collection can contribute to metastability in large-scale systems. Increased memory pressure can raise GC time and request cost, increasing latency and reducing throughput; this can increase in-flight requests and memory pressure further, creating a self-perpetuating cycle that may collapse systems without limited concurrency. It cites production experience and research showing that some garbage collectors can increase work cost by up to 70% under higher memory pressure.

## Source excerpt

Garbage Collection and Metastability Cleaning up is hard to do. I've written a lot about stability and metastability, but haven't touched on one other common cause of metastability in large-scale systems: garbage collection. GC is great. Garbage collected languages like Javascript, Java, Python, and Go power a big chunk of the internet's infrastructure. Until Rust came along, choosing memory safety typically implied choosing garbage collection. For almost all applications, languages with garbage collection are a reasonable choice. The trade-offs between GC and not-GC have been well trodden, so I'm not going to spend time on any of them except one: metastability. As we've discussed in prior posts, metastability comes about when systems have self-perpetuating cycles which permanently degrade goodput. Here's what the cycle for GC might look like: Increasing memory pressure increases the amount of time it takes for the GC to run, and increases the cost of handling any given request, this increases per-request latency and reduces throughput, this increases the number of requests in flight (and their associated per-request memory), which increases memory pressure. In a system that limits concurrency (whether a closed system or an open system with concurrency-limiting throttling) this isn't likely to happen. In a system without limited concurrency (even if it does limit arrival rate), even a short-lived excursion can send the system into a mode where it spins around this loop until it collapses. But do GCs behave that way? The only controversial step in the loop is higher GC overhead, implying that increasing memory pressure increases per-request latency even in the presence of excess CPU (so it's more than just the effect of memory management consuming more CPU, which would happen without GC). I've seen significant in-production evidence for that, and there seems to be some good evidence from the literature. For example, see Figure 2 from The DaCapo Benchmarks by Blackbur