a-j-wood / pv

Pipe Viewer - monitor the progress of data through a pipe

Home Page:https://www.ivarch.com/programs/pv.shtml

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Apply rate limits instantaneously, not averaged over the whole transfer

a-j-wood opened this issue · comments

Jered_Floyd-rate-limit.patch.txt

Date: Sat, 22 Dec 2018 12:32:09 -0500 (EST)
From: Jered Floyd jered@convivian.com
Subject: Patch for pv rate-limit behavior on bursty traffic

Hi Andrew,

I believe that the rate-limit functionality of pv is broken, or at least not what I expect and want. The problem is that bandwidth credits accumulate over time rather than being strictly attached to a rate-limit interval. This means that bursty input that can lead to bursty output that greatly exceeds the requested limit.

In my particular use case I have a process that is mostly quiet for several hours, and then very verbose (1 TB) after. When using the -L option, I find that I am not rate-limited for about an hour -- so instead of my requested 1 MB/s cap I use 80 MB/s and incur massive overage charges.

You can reproduce this behavior locally by watching the instantaneous rate monitor immediately after 60 seconds elapse with this command:
(sleep 60; cat /dev/urandom) | pv -ptebar -L10m > /dev/null

I'm not sure where the current behavior is desirable. I think the credit value in "cansend" should simply reset each rate interval. The below patch implements this behavior.

Regards,
Jered Floyd

The patch from vbychkoviak seems to fix this in a simpler way, so this issue is now closed (the fix will be in the next release after 1.6.20).