4

Can I taskset a process inside container/docker? How can I tell which cpu cores are assigned to this container?

I want to taskset a process to some specific cpu cores to get better performance.

Dongfang Qu
  • 341
  • 1
  • 11
  • 1
    In the case of redis server, It'll get better performance if `taskset`ed. However, It gets worse if `taskset` redis to a specific core which is not given to this container or container uses cpu by cpushare. – Dongfang Qu Sep 05 '18 at 10:20

1 Answers1

3

I got a simple solution that just works.

# shell function which gets the last `taskset`able cpu core 
findLastUsableCore() {
    count=`grep -c ^processor /proc/cpuinfo`

    count=$((count - 1))
    while [ "${count}" -ge "0" ] ; do
        taskset -c ${count} echo >/dev/null 2>&1

        if [ "$?" -eq "0" ];then
            return ${count}
        fi

        count=$((count - 1))
    done

    return 0
}
Dongfang Qu
  • 341
  • 1
  • 11