Hey guys !
I've been quite reluctant to operate my srcds server on a RT patched kernel - running GRSEC because the server isn't strictly dedicated to TF2 for one, and it has public facing services (HTTP mirror, SSH).
Features
So I've been playing with what I had under my hands. The following is the script I use, and basically it :
Script
Install
Now either your server has autorestart or it hasn't. If it has, you want to schedule this script every 10 minutes using cron, so that in the event of a restart, the new server will get boosted soon enough. Here's a cron line for the lazy :
Otherwise, you can just manually call it after starting the server.
One could extend this script to use a mix of PS and sudo to launch the server using the appropriate user. If you guys really want such a feature I could demo it, but anyone is welcome to show off their shell-fu and share the relevant bits
Last notes
So far so good, so .. just sharing
In any case, CC welcome (or rep ?).
Changelog
I've been quite reluctant to operate my srcds server on a RT patched kernel - running GRSEC because the server isn't strictly dedicated to TF2 for one, and it has public facing services (HTTP mirror, SSH).
Features
So I've been playing with what I had under my hands. The following is the script I use, and basically it :
- gives a high priority (nice) to srcds
- gives a RT priority (FIFO) to srcds, with high priority
- uses CFQ IO-scheduler to ensure TF2 has first hand in disk access
- sets task affinity of SRCDS on CPU2, mysql on CPU1 and nginx on CPU3. tweak depending on what you use. I advise leaving CPU0 for other tasks like crons and the like, and for IRQ servicing. Also, don't use irqbalance, or set its CPU mask to keep off your srcds processor.
- sets the clock source to HPET
Script
Code:
#!/bin/sh
### srcds_boost.sh, r2
### options
SRCDS_USER="sorciers"
TFDATA_BLOCK_DEVICE="sda"
### options ends here, beware if you customize anything below
# this script uses schedtool where taskset could be used
# at the cost of a three additional loops.
# ensure system clocksource is HPET if available
CLOCKPATH=/sys/devices/system/clocksource/clocksource0/
grep hpet $CLOCKPATH/available_clocksource 2>&1 >/dev/null
if [ $? == 0 ]; then
if [ `cat $CLOCKPATH/current_clocksource` != "hpet" ]; then
echo "hpet" > $CLOCKPATH/current_clocksource
fi
fi
# ensure sda IO scheduler is CFQ if available
IOQPATH=/sys/block/$TFDATA_BLOCK_DEVICE/queue/scheduler
grep cfq $IOQPATH 2>&1 >/dev/null
if [ $? == 0 ]; then
grep '\[cfq\]' $IOQPATH 2>&1 >/dev/null
[ $? != 0 ] && echo "cfq" > $IOQPATH
export CFQ="1"
else
export CFQ=""
fi
# put SRCDS server on CPU2
# - FIFO scheduling, high prio
# - not nice
# - IO scheduling to realtime, high prio (if CFQ available)
pids=`ps -u $SRCDS_USER -L | grep srcds | grep -Eo '^ ?[0-9]+ +([0-9]+)' | grep -Eo '([0-9]+)$' `
chrt -p -a -f 30 $pids
schedtool -a 2 -n -10 $pids
renice -n -10 -p $pids >/dev/null
[ $CFQ == "1" ] && ionice -c 1 -n 2 -t -p $pids
# put MYSQL on CPU1
pids=`ps ax | grep mysqld | grep -v grep | cut -f 1 -d ' '`
schedtool -a 1 $pids
# put NGINX on CPU3
pids=`ps ax | grep nginx | grep -v grep | cut -f 1 -d ' '`
schedtool -a 3 $pids
# other CPU intensive daemons should be
# using CPU0,1,3
# CPU0 should be busy serving interrupts and most
# kernel madness
Install
- This script requires root access and the schedtool program.
- This script requires manual tweaks. Read it, and make sure you understand what it does. Look up google. Stuff to look for :
- Nginx/Mysql are just a demo of what you could have running aside of your srcds. Use htop/top on your box to see what is hitting on your resources, and patch script accordingly.
- Check
- IOQPATH variable might need to be changed for your system (hda, vda, sdb, dm0, ...). If your game accesses multiple disks, you need to duplicate the block as often as needed. Otherwise you can also change TFDATA_BLOCK_DEVICE
- Copy/paste this in a file such as /root/boost_srcds.sh
- chmod u+x boost_srcds.sh
Now either your server has autorestart or it hasn't. If it has, you want to schedule this script every 10 minutes using cron, so that in the event of a restart, the new server will get boosted soon enough. Here's a cron line for the lazy :
Code:
*/10 * * * * /root/boost_srcds.sh >/dev/null
Otherwise, you can just manually call it after starting the server.
One could extend this script to use a mix of PS and sudo to launch the server using the appropriate user. If you guys really want such a feature I could demo it, but anyone is welcome to show off their shell-fu and share the relevant bits
Last notes
So far so good, so .. just sharing
In any case, CC welcome (or rep ?).
Changelog
- 2011-10-05 : R1
- 2011-10-14 : R2. Improved process finding, and an additional option.