-
Notifications
You must be signed in to change notification settings - Fork 8
Open
Milestone
Description
An optimization we could make is to configure CPU affinity/pinning for the TWAMP sender/receiver.
This would require the TWAMP sender/reflector code in Go to be locked to the OS thread, which has some caveats/footguns, but it can work if careful. Alternatively, it could be in a separate process entirely.
Example
package main
import (
"fmt"
"runtime"
"golang.org/x/sys/unix"
)
func pinToCPU(cpu int) error {
runtime.LockOSThread()
var mask unix.CPUSet
mask.Zero()
mask.Set(cpu)
err := unix.SchedSetaffinity(0, &mask) // 0 = current thread
if err != nil {
return fmt.Errorf("failed to set CPU affinity: %w", err)
}
return nil
}
func main() {
go func() {
if err := pinToCPU(2); err != nil {
panic(err)
}
// Do work pinned to CPU 2
select {}
}()
select {}
}Reactions are currently unavailable