Setting TID Affinity

Ask questions about dedicated servers here and we and other users will do our best to answer them. Please also refer to the self-help section for tutorials and answers to the most commonly asked questions.
Post Reply
stickz
https://www.youtube.com/channel/UC40BgXanDqOYoVCYFDSTfHA

Setting TID Affinity

Post by stickz »

I'm running a game-server on my Gentoo VDS, but it's not scheduling the thread ids properly. This appears to be causing a bottleneck on the main core which leads to performance issues. Attached bellow is the process and all the thread ids which belong to it. I would like to place the thread id which matches the process id on core 0 and all the other threads on core 1. Any help as to how to go about doing this would be appreciated. I don't want to upgrade to more threads just for one server.

rna1 ~ # top
top - 14:08:47 up 4 days, 21:34, 1 user, load average: 1.02, 1.00, 0.96
Tasks: 78 total, 2 running, 76 sleeping, 0 stopped, 0 zombie
%Cpu(s): 46.2 us, 2.2 sy, 0.0 ni, 43.2 id, 0.3 wa, 0.0 hi, 8.1 si, 0.0 st
KiB Mem: 2051032 total, 2032372 used, 18660 free, 316300 buffers
KiB Swap: 4194300 total, 2068 used, 4192232 free. 1116472 cached Mem

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
4840 stickz 20 0 502392 303760 27272 R 95.5 14.8 1607:32 srcds_linux

rna1 ~ # ps -p 4840 -L -o pid,tid,psr,pcpu
PID TID PSR %CPU
4840 4840 1 67.1
4840 4842 0 0.0
4840 4844 0 0.0
4840 4847 1 0.0
4840 4850 0 0.0
4840 4852 1 0.4
4840 4855 1 0.0
4840 4861 1 0.0
4840 4862 1 0.0
4840 5192 1 0.0
User avatar
Edge100x
Founder
Founder
Posts: 13154
Joined: Thu Apr 18, 2002 11:04 pm
Location: Seattle
Contact:

Re: Setting TID Affinity

Post by Edge100x »

Manually assigning threads to specific cores usually is not a good idea, but you can do it with "taskset".

To see the CPU usage for each thread in "top", press "H" while it is running.
stickz

Re: Setting TID Affinity

Post by stickz »

Taskset worked and all my performance issues just went away after scheduling the two gameplay threads on separate cores. I find it quite odd how the CPU usage is dramatically lower now as-well, with higher players count.

The stall time went from 0.0 to 0.3 which means one of my physical cores is being shared with someone else.
stickz

Re: Setting TID Affinity

Post by stickz »

Wait a minute, could this have given myself full control over a physical core, by activating both threads? The CPU usage is too low to use more than one physical core.
stickz

Re: Setting TID Affinity

Post by stickz »

Or was the issue having hyperthreading disabled with approximately six query threads? Everything would essentially be dumped on a single physical core massively increasing the CPU usage. That explains the zero stall time beforehand and having 0.3 afterwards. http://forums.nfoservers.com/viewtopic.php?f=47&t=5099
Post Reply