Live data from Hacker News

CPU cache-friendly data structures in Go

skoredin.pro

1–10 of 88 posts

Re: CPU cache-friendly data structures in Go

#7
Overall great article, applicable to other languages too.

I'm curious about the Goroutine pinning though:

    // Pin goroutine to specific CPU
    func PinToCPU(cpuID int) {
        runtime.LockOSThread()
        // ...
        tid := unix.Gettid()
        unix.SchedSetaffinity(tid, &cpuSet)
    }
The way I read this snippet is it pins the go runtime thread that happens to run this goroutine to a cpu, not the goroutine itself. Afaik a goroutine can move from one thread to another, decided by the go scheduler. This obviously has some merits, however without pinning the actual goroutine...

Re: CPU cache-friendly data structures in Go

#8
> False sharing occurs when multiple cores update different variables in the same cache line.

I got hit by this. In a trading algorithm backtest, I shared a struct pointer between threads that changed different members of the same struct.

Once I split this struct in 2, one per core, I got almost 10x speedup.

Re: CPU cache-friendly data structures in Go

#10
post #8

> False sharing occurs when multiple cores update different variables in the same cache line. I got hit by this. In a trading algorithm backtest, I shared a struct pointer between threads that changed different members of the same struct. Once I split this struct in 2, one per core, I got almost 10x speedup.

Interesting! Did you find out a way to bench this with the built in benchmarking suite?
Post reply on HN