Intro: I’ve been meaning to write about and (completely fair scheduler) for a long time , but I’ve been busy with work etc. docker CFS I’m gonna use Docker to limit process’s usage, and we gonna explore what kind of metrics do we have to maybe troubleshoot an under-provisioned application , we’re going to be playing with and cpu fceux mario CFS (Scheduler): has been the default scheduler of the kernel for a while , this isn’t an attempt to explain it in depth , but there’s a lot of interesting data about this , especially something about the main developer coming from the medical area or something like that. CFS linux Scheduling periods are expressed in , and they are really a unit of time expressed in microseconds , you can call it the length of a c , but the important thing is that cpu.cfs_period_us pu cycle it can be made longer or shorter. Periods are nothing without as in , whats the point of accounting for time if we’re not gonna be throttling or doing anything with that time. cpu.cfs_quota_us , In the following example a given has configured a: process A , cpu.cfs_period_us = 100 cpu.cfs_quota_us = 200 That might seem confusing but the accounts per (core, as seen by the OS) , meaning that that configuration will allow process A to “burst” and run for 2 periods (1 in each ) without being throttled. perdiod cpu cpu yellow indicates your allowance Docker limits: So all the above is the theory , in practice you can achieve the same by using some flags , for example: docker run -ti alpine sh --cpu-period=50000 --cpu-quota=1000 And that will create a new leaf , this is how you can find it: cgroup Having the container ID we will to the specific leaf: cgroup There’s a lot of really interesting stuff here , but we’re gonna focus on it looks like this: cpu.stat, nr_periods nr_throttled throttled_time 2313838319 51 45 Basically this means that we’ve ran for periods we got throttled of them and the throttling time was us. 51 45 2313838319 This is very useful when profiling apps that you want to for example, adjusting limits metrics should get you to a level where your process isn’t throttled that much. dockerize And Mario?? We’ll i wanted to pick a process that would let me show this graphically , instead of a python script finding prime numbers or anything like that , so Mario it is: Mario period= 50000 quota = 1000 [[~7 FPS]] (almost 100% throttling) docker run -ti — cpu-period= — cpu-quota= -e DISPLAY=$DISPLAY -v /home/jgarcia/Projects/games/games/:/games -v /tmp/.X11-unix:/tmp/.X11-unix -v /run/dbus/:/run/dbus/ — privileged 352b46a178cb 50000 1000 Results: nr_periods nr_throttled throttled_time 22032678629 411 385 50000x1000 Mario period= 50000 quota = 2000 [[~15 FPS]] (still bad..) docker run -ti --cpu-period= --cpu-quota= -e DISPLAY=$DISPLAY -v /home/jgarcia/Projects/games/games/:/games -v /tmp/.X11-unix:/tmp/.X11-unix -v /run/dbus/:/run/dbus/ --privileged 352b46a178cb 50000 2000 Results: nr_periods nr_throttled throttled_time 18784846882 419 397 50000 x 2000 Mario period= 50000 quota = 5000 [[~40 FPS]] (very good) docker run -ti --cpu-period= --cpu-quota= -e DISPLAY=$DISPLAY -v /home/jgarcia/Projects/games/games/:/games -v /tmp/.X11-unix:/tmp/.X11-unix -v /run/dbus/:/run/dbus/ --privileged 352b46a178cb 50000 5000 Results: nr_periods nr_throttled throttled_time 992353904 385 32 50000x5000 Mario running quota less [[~62 FPS]] (perfect!!) Run wild!! nr_periods 0nr_throttled 0throttled_time 0 No limits Final Remarks: I am not advocating to run limitless mario , but just wanted to show how easy is to actually get some data that it used to be very hard to collect , and make minor adjustments about it. Sorry about the size of the gifs i did all i could.