将GoRoutines绑定到cpu内核[重复]

This question already has an answer here:

I need to run a number of go routines and bind them to separate CPU cores for a benchmark test.

I've tried with runtime.LockOSThread() but this degrades performance significantly. I do not want to lock go rountines to specific threads and in my understanding LockOSThread does just that.

Ex: If I have n goroutines where n>1 they should be bound to n cores where GOMAXPROCS >= n. That is each goroutine is always scheduled on the same core.

</div>
  • Use reuseport listener.
  • Run a separate server instance per CPU core with GOMAXPROCS=1.
  • Pin each server instance to a separate CPU core using taskset.
  • Ensure the interrupts of multiqueue network card are evenly distributed between CPU cores. See this article for details.

Full details can be found here