I’ve been reading about Receive Packet Steering on Linux. I have heard anecdotal evidence that this can greatly improve performance. It made me wonder if you could improve performance even more by telling the kernel that you want the thread the processes the IO for a particular interface to run on the same CPU that is handling the interrupts for the interface.

Java doesn’t provide support for CPU/Thread affinity out of the box. Linux has the sched_setaffinity(2) that does this.  So, I wrote some JNI code to allow me to set a thread’s affinity mask for a particular CPU.  I’ve pushed this code out to GitHub.  I also implemented a CpuLocal class that is similar to ThreadLocal.  The build is targeted for 64-bit platforms and may require some tweaking to get it to run on yoru environment.

Unfortunately, I haven’t had much time (or proper resources) to benchmark my theories about combining CPU/thread affinity with receive packet steering but I thought I would push the code out anyway so that others can start playing with it.