-
Notifications
You must be signed in to change notification settings - Fork 7
Open
Milestone
Description
An optimization we could make is to tune the TWAMP sender/reflector to have higher kernel scheduling priority.
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"
"time"
"unsafe"
"golang.org/x/sys/unix"
)
func main() {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
if err := elevateThreadPriority(); err != nil {
panic(fmt.Sprintf("failed to elevate thread priority: %v", err))
}
fmt.Println("Running high-priority work on a locked thread...")
for i := 0; i < 5; i++ {
fmt.Println("tick", i)
time.Sleep(500 * time.Millisecond)
}
}
func elevateThreadPriority() error {
param := &unix.SchedParam{SchedPriority: 10} // range: 1–99 for SCHED_FIFO/RR
tid := unix.Gettid()
_, _, errno := unix.RawSyscall(
unix.SYS_SCHED_SETSCHEDULER,
uintptr(tid),
uintptr(unix.SCHED_FIFO),
uintptr(unsafe.Pointer(param)),
)
if errno != 0 {
return errno
}
return nil
}Reactions are currently unavailable