This post discusses CPU affinity and exhibits some examples for its usage.
This post is meant for basic users who wish to understand the concept behind CPU affinity for performance purposes.
- Ram Disk Application for Windows Environment (imdisk, sqlio)
- Processor affinity (Wikipedia)
- Processor Affinity (Linux)
- How To Force Windows Applications to Use a Specific CPU
CPU affinity enables binding a process or multiple processes to a specific CPU core in a way that the process(es) will run from that specific core only. When trying to perform performance testing on a host with many cores, it is wise to run multiple instances of a process, each one on different core. This enables higher CPU utilization.
There are various of options to change the affinity of the process.
Generic example, via the GUI: How To Force Windows Applications to Use a Specific CPU
Specific example for SQLIO command:
--a[R[I]]<cpu mask> cpu mask for (R=roundrobin (I=ideal)) affinity
C:\>sqlio2_15 -BYRT -e200 -b512 -fsequential -T0 -W1 -t100 -aR0xFFFFFF -s100 -LS \\188.8.131.52\S\1
sqlio v2.15. 64bit_SG
100 threads writing for 100 secs to file \\184.108.40.206\S\1
using a 0/100 read/write ratio
using 512KB sequential IOs
enabling a warm up period of 1 seconds
buffering set to use both file and disk caches
buffering will occur on the remote server, not locally
software buffer cache will defer writeback, honoring temporary attribute
In this case, the affinity is 0xFFFFFF (24 bits, one for each core) with round robin on processors 0 ... 23
Another option is to use the start command:
C:\> start /b /affinity <cpu mask> <app path>
The flag /b is not mandatory. It is used for the command to run on current open window.
For example, in case the server has 2 sockets with 12 cores each, and you want to run 12 streams of SQLIO, each on a single core, at NUMA node #1 (cores 12-23), then run:
C:\> start /b /affinity 0xFFF000 sqlio.exe
NOTE: The round robin affinity may be uneven. (for example, 100 threads is not a multiple of 24 cores).
See Ram Disk Application for Windows Environment (imdisk, sqlio) for additional options.