9 ms·
Golang’s Real-Time GC in Theory and Practice
- tomcam 10y agoGood writeup, with a surprise about OCaml. The authors welcome PRs for other languages. I look forward to seeing the results, and wonder if they will end up in a Techempower-style global brouhaha (which the Techempower folks have, I hasten to say, apparently handled with grace and integrity).
- jamesfisher 10y agoThanks! If you're interested in OCaml's low-latency GC, there's a nice writeup about it by Jane Street: https://blogs.janestreet.com/building-a-lower-latency-gc/ https://blogs.janestreet.com/building-a-lower-latency-gc/
- willsewell 10y agoThere are already versions in: * C - https://gitlab.com/gasche/gc-latency-experiment/merge_requests/5 https://gitlab.com/gasche/gc-latency-experiment/merge_reques... * C# - https://gitlab.com/gasche/gc-latency-experiment/merge_requests/4 https://gitlab.com/gasche/gc-latency-experiment/merge_reques... * Nim - http://forum.nim-lang.org/t/2646 http://forum.nim-lang.org/t/2646
- mathw 10y agoA great writeup and I feel it's a welcome reminder of some important points: - your programming language and runtime aren't equally good at everything and never will be - you have to choose your environment based on your anticipated workload - you have to understand what your anticipated workload actually is - you can't just treat the garbage collector as a magic box that does the memory thing for you Unless, of course, you're writing software which is nowhere near the performance boundaries of the system and never will be. Can't say I share the author's surprise about the JVM's performance, but I never did like Java anyway.
- jamesfisher 10y agoWe were surprised by Java's poor performance because the HotSpot JVM also uses a concurrent mark-and-sweep collector, and is famed for the amount of engineering effort that has gone into it. We suspect our benchmark could be improved by someone with more high-performance JVM experience. [Edit] jcipar on Reddit made some promising progress by tuning the JVM GC parameters for our benchmark: https://www.reddit.com/r/programming/comments/5fyhjb/golangs_realtime_gc_in_theory_and_practice_pusher/daof47v/ https://www.reddit.com/r/programming/comments/5fyhjb/golangs...
- fnord123 10y agoIsn't GC parameter tuning equivalent tuning model parameters and hence susceptible to over fitting? As soon a you patch your service, the parameters may need to change.
- Someone 10y agoNot only GC parameter tuning, _all_ parameter tuning. In many cases, technologies have matured enough so that you can build a mental model of them that fits reality both now and in a couple of years time, but that is never guaranteed. For example, in the small: - the performance of a bit shift used to be dependent on the number of bits shifted (https://wiki.neogeodev.org/index.php?title=68k_instructions_timings#Shift_and_rotate_instructions https://wiki.neogeodev.org/index.php?title=68k_instructions_...). Timing of integer and floating point multiplication was dependent on argument values. - on PowerPC, for at least some CPUs, it could be worthwhile to use floating point variables to iterate over an integer range because that kept the integer pipeline free for use doing the actual work. Change the CPU, and you have to change the type of your loop variable. In the large: - the optimal code for lots of data-crunching code is hugely dependent on cache size, sizes and relative speeds of caches, main memory, and disk. - if you swap in another C library, performance (for example of scanf or transcendental functions) can be hugely different. - upgrading the OS may significantly change the relative timings of thread and process creation, changing the best way to solve your problem from multi-process to multi-threaded or vice versa. So yes, GC parameter tuning is a black art that, ideally, eventually should go away, but the difference with other technologies is only gradually, and, at least, you can tune it without recompiling your code. I also think GC is getting mature enough for fairly reliable mental models to form. The throughput/latency tradeoff that this article mentions is an important aspect; minimizing total memory usage may be another.
- bjourne 10y agoThe weak generational hypothesis states that most objects are short-lived. Therefore concentrating on collecting the youngest objects yields the most garbage/cpu cycle spent. In the benchmark, all objects survive the same amount of time and it is the oldest objects that become garbage first. It is the opposite of the behavior the weak generational hypothesis presumes. So collectors optimized for that scenario is at a disadvantage. :) For example, I ported the benchmark to Python 3 and got a max pause time of 0.05 ms. That's 40 times faster than OCaml but it doesn't mean Python is faster in general. It just "got lucky" because ref counting is an almost optimal fit for the benchmark. There is no strategy that fits all when it comes to memory management. :)
- iainmerrick 10y agoReference counting is great. I used to be skeptical but I'm a complete convert after using Objective-C. The old myth about GC was that it was slow. Nowadays that's usually false, but what is true that it wastes a lot of memory, or has long pauses, or both. The old myth about reference counting, on the other hand, is that uncollected cycles are a problem, but in practice they're usually not that hard to find and fix. Reference counting is a bit slower, but it doesn't waste memory and doesn't pause. So it's great for throughput. And throughput is very often more important than overall performance! For anything with a UI, you want maximum throughput. For anything on the server side that's realtime, or even indirectly user-facing, you want maximum throughput. The only time you want performance over throughput is batch jobs, which I reckon crop up less often than you expect. (Edit to add: on memory-constrained devices, you might not want the memory overhead of GC even for batch jobs.)
- chadaustin 10y agoYou probably mean minimal latency, not maximum throughput. GC generally has higher throughput at the cost of latency and higher peak memory usage. :)
- z92 10y agoParallel GC's throughput is limited by how hard the parallel thread is working as described in the article and which was the point.
- brian-armstrong 10y agoIf you have a long-lived functionality in your Go program that needs buffers, it may just be best to allocate a pool of buffers and reuse them. Go does offer a basic primitive for this with sync.Pool I once wrote a high throughput UDP listener that maxed out all the cores to deal with receiving some bursty UDP traffic. I realized that interacting with the memory allocater was my bottleneck, so I just moved to a pool of UDP buffers. My ability to deal with load spikes improved substantially. There's no reason not to use Pools in general if you're building a service with a predictable and repeatable object lifetime
- wfleming 10y agoI'm a little surprised it didn't seem that they considered a GC-less language like Rust. If your latency requirements are that strict & you're already considering a total rewrite, I would personally have been looking into a solution that would avoid GC entirely.
- jakevn 10y agoRust has a semantic overhead and isn't quite as mature as Go. Their requirements don't necessitate a lack of GC pause.
- echelon 10y agoI disagree with your first point, at least from a personal perspective. I find Rust more expressive than Go, and slightly more productive. You're right about maturity though. Hopefully the Rust library ecosystem continues to make strides.
- wfleming 10y agoI agree: I personally find Rust more expressive than Go. I don't think it has any more "semantic overhead" than any other language with a highly featured type system. To tie it back to the article a bit, Rust also seems like a relatively natural choice for a team considering switching from Haskell if their reason for switching is performance. The niche Rust fills for me personally is that it has a very robust type system (putting it in a similar camp as Haskell) with an explicit focus on fast, performant code (which Haskell does not have).
- willsewell 10y agoThis is something we get asked a lot. The short version is that we had other requirements as well as a low latency. I described some of these here: https://www.reddit.com/r/programming/comments/5fyhjb/golangs_realtime_gc_in_theory_and_practice_pusher/daowdag/ https://www.reddit.com/r/programming/comments/5fyhjb/golangs...