CPULeash: A tool for capping per-process and process group CPU utilisation from userspace

It’s now mid October, there are 0 posts in 2017. Therefore I think it’s time to loosen up posting constraints and try make a bit more casual posts. For a start I will dig up one of the unfinished works. I will start with a quick overview of an old piece of tool (unmaintained) I wrote quite a few years ago. The tool caps the maximum CPU utilisation of a process from userspace without requiring root access. One instance of the process can cap multiple processes individually, in a group or it can also cap an entire process sub-tree. I intended to post about it in great detail, but this time I will keep it brief, and dig deeper in the next opportunity. Let’s get into it.

Motivation (from agony)

A few years ago, I was used to run different CPU intensive experiments on my old laptop, which would sometime run weeks. The CPU temperature used to go up to 95 Deg C. Sometimes it went upto 99 Deg C and then it used to throttle down the cores to get the temperature down. This is definitely not a healthy temperature, therefore I feared of hardware damage. The laptop had a metal case, which became so hot that it left red marks on my thighs. One time an entire chocolate bar melted into a pool of liquid chocolate (someone left it near the exhaust fan). Therefore it was time that I figure something out, such that I can run the experiments, but keep the laptop cool (relatively).

The obvious idea was to cap the CPU usage for the processes. An easy solution is to install a virtual machine and run the code inside the virtual environment. Note that, in my case nice does not work, as it does not help control how much of the CPU a processes utilises when it acquires it. I could have used cgroups, but I didn’t want to (I don’t know why). At that point of time I was feeling the need for Solaris Zones.

Essentially what I wanted is something portable in any *nix system, works completely from userspace and also does not need root privilege. Therefore I made a small tool which does in. It was written in C and POSIX compliant libraries.

Also note that, there is a similiar kind of tool called cpulimit, which I didn’t know existed when I wrote this. This tool works well too.

Given this situation, it was time to write something in-house … drum rollCPULeash.

Continue reading “CPULeash: A tool for capping per-process and process group CPU utilisation from userspace”

Advertisements

2014 in review

This is pretty embarrassing. I promised to post several posts in last year and now ended up posting two posts in the last year, also none of those posts were actually a post. The worst year ever. Let’s see this year.

 

The WordPress.com stats helper monkeys prepared a 2014 annual report for this blog.

Here’s an excerpt:

The Louvre Museum has 8.5 million visitors per year. This blog was viewed about 92,000 times in 2014. If it were an exhibit at the Louvre Museum, it would take about 4 days for that many people to see it.

Click here to see the complete report.

Blogging update

I promised (myself and you all) to post atleast 2 posts per month this year. Which clearly did not work at all. This is because this post is the second post after the “promise post”. What is going on then. The fact is I am not that much busy that I cannot put up a new post on the blog. The fact is that right now there are at least three different things I need to handle and this context switch every day or multiple times a week does not let me actually click the publish button (you all know how hard it is to click that button).

Recently (more than a year now) I was working on a cluster analysis algorithm and previously I was learning while working with some basic feed forward neural networks. Along with this I also keep in touch with *nix system programming and Linux OS kernel architecture (and a bit of Solaris recently). Therefore things are diverse. The job I do in the daytime (for which I get paid) is another domain (though similar to the system programming thing, but not exactly). Therefore the contexts are pretty diverse for me therefore the focus keeps shifting.

There are quite a few good ideas, for which there are drafts written, but as usual, it stays at on the disk. Why I am posting this? I am posting this because I need to press the “Publish” button and try again start the posting.

Therefore let’s see.