Home > bash, firefox > limit the CPU usage of Firefox / Dropbox / etc.

limit the CPU usage of Firefox / Dropbox / etc.

I have an older dual core laptop where Firefox sometimes uses 120%-130% CPU and slows down the machine completely. Restarting Firefox solves the problem for a few minutes but then again, it eats up the CPU. What to do?

I don’t have many tabs open but I still have this problem. I also uninstalled the Flash plugin but it didn’t solve the problem.

However, I found a nice tool called cpulimit:

Cpulimit is a tool which limits the CPU usage of a process (expressed in percentage, not in CPU time). It is useful to control batch jobs, when you don’t want them to eat too many CPU cycles. The goal is prevent a process from running for more than a specified time ratio. It does not change the nice value or other scheduling priority settings, but the real CPU usage. Also, it is able to adapt itself to the overall system load, dynamically and quickly. The control of the used CPU amount is done sending SIGSTOP and SIGCONT POSIX signals to processes. All the children processes and threads of the specified process will share the same percentage of CPU.” (from the README of the project)

The following setting worked for me:

$ cpulimit -l 80 firefox

Firefox uses several threads but as mentioned in the documentation, they will will share the same percentage of CPU.

The CPU usage may jump higher than the specified value, but cpulimit will push it back in a few seconds.

My old laptop has become useable again :)

Update (with Dropbox)
I noticed that Dropbox also loves my CPU. Here is how I could limit this greedy beast. Originally, I started “$HOME/.dropbox-dist/dropboxd” automatically at each startup. Create the file “$HOME/bin/cpulimit_dropboxd.sh” with the following content:

#!/usr/bin/env bash

cpulimit -l 50 $HOME/.dropbox-dist/dropboxd

Make it runnable (chmod u+x cpulimit_dropboxd.sh) and call this script (cpulimit_dropboxd.sh) when your system comes up. Here I give 50% CPU for Dropbox but you can play with that value.

Categories: bash, firefox Tags: ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: