Skip to content

Go 13 posts

Concepts

Go goroutine leaks and pprofchannels, mutexes, and exit paths

Starting a goroutine is easy. The hard part was deciding who changes the data, who finishes the work, and when a function may return.

Concepts

Go sync.Pool and buffer reuseafter Put, Bytes() isn't yours

In the previous post, total allocations stayed at 256MiB however I set GOGC and GOMEMLIMIT. Reusing short-lived buffers with sync.Pool is one way to shrink it.

Concepts

Go GOMEMLIMIT and GOGCOOMKilled with an 800MB heap

The container limit was 1GB, yet the process was OOMKilled with an 800MB heap. Go has a garbage collector, so how did memory run out?

Concepts

Go GMP and GOMAXPROCScontainer CPU limits and goroutines

Put go in front of a call and it runs concurrently. So do 100,000 goroutines mean 100,000 threads? Does GOMAXPROCS=1 mean one task at a time?

Concepts

Copying structs in Gowhy a shallow copy changes the map too

Interfaces, slices, defer, embedding, context: looking back after five posts, most of the pitfalls came from two axes. One is "everything is copied"; the other is "object orientation without classes."

Troubleshooting

Go ResponseHeaderTimeoutwhy a one-hour timeout died at 30 seconds

I thought putting a one-hour context.WithTimeout on a request meant it would wait up to an hour. It died at 30 seconds. The context made it all the way through; it just wasn't the only timer. And once I fixed the timer, the real problem turned out to be somewhere else.

Concepts

Go context, fully explainedcancellation, time budgets, and four pitfalls

I was already taking ctx as the first argument and passing it along. What I had never checked was whether canceling actually stops the goroutine. After stalling on that question in an interview, I went back to context from the start.

Troubleshooting

From 300 calls to 1how I learned that optimization changes failure modes

Validation was dying on timeouts. Within 30 minutes I had an answer, "it's N+1, batch it," and it was only half right. Reaching the final design took two changes of direction, and since the process taught me more than the code, I'm writing it down.

Concepts

Why Go has no inheritancerebuilding OOP with embedding and interfaces

Go has no classes and no inheritance, yet it's hard to call it non-object-oriented. The official FAQ answers "Is Go an object-oriented language?" with "Yes and no." This post explains why by following what Go put where inheritance used to be.

esc

Recent posts

↑↓ move↵ openOpen search page ›