Rate-limiting processes?

Is there any way to IO rate-limit an individual process inside a vps? I've got a process that md5's a lot of files and I'd like to slow it down so I don't use up all my io tokens.

Linux xxx 2.4.26-linode31-1um #1 Thu Jul 8 18:24:02 EDT 2004 i686 UML User Mode Linux GNU/Linux

8 Replies

if you call the md5 process from a basic bash script you can include a wait command or you could even grep the iotoken counter too make sure you stay above a current amount.

You could spawn the md5 process, fetch the process ID and as long as it is running, use a simple bash script that monitor /proc/io_status, send SIGSTOP to the PID when the bucket is below a fixed value and send a SIGCONT to the PID when the bucket is back above another.

Take a look at this:

http://www.kotalampi.com/scripts/watchtokens

It is watching your system load & available io tokens and will stop and start services if they go too low/high and restart when systems have returned to normal.

You can modify it for your purposes as follows:

Put your start/stop commands to these files:

$startfile ="/etc/rc.d/start.sh";

$stopfile ="/etc/rc.d/stop.sh";

When to stop services (when load/tokens is at these levels):

$maxload = 3.0;

$l = 0.2; # <20% of max io_tokens

When to restart services (when load/tokens is back at these levels):

$minload = 1.1;

$u = 0.5; # >50% of max io_tokens

Cheers,

Risto

The kill -STOP and CONT would work, but it is going to be pretty bursty. I was thinking more towards something that would keep the usage smooth.

> $a2 = "\$a2";

$a3 = "\$a3";

$a4 = "\$a4";

$a5 = "\$a5";

$a6 = "\$a6";

I'm scared looking at that code lol :)

Maybe this won't be that scary… :-)

if($out =~ /^(iocount=)(\d+)(\s+)(iorate=)(\d+)(\s+)(iotokens=)(\d+)(\s+)(tokenrefill=)(\d+)(\s+)(token_max=)(\d+)$/){

$io_rate = $5;

$io_tokens = $8;

$token_refill = $11;

$token_max = $14;

}

else

{

print STDERR "Invalid /proc/io_status syntax\n";

exit(-1);

}

New version is available in the URL above, too.

Risto

(?:pattern) is your friend. ditto with |=

Also check out this thread:

http://www.linode.com/forums/viewtopic.php?t=1147

In the end of that thread caker alludes to an ionice-type capability being available in the future. Anybody know if that's here yet?

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct