wget-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Wget-dev] wget2 | Add --limit-rate option (wget1.x) (#408)


From: Rohan Fletcher
Subject: Re: [Wget-dev] wget2 | Add --limit-rate option (wget1.x) (#408)
Date: Thu, 18 Apr 2019 23:05:57 +0000



Hello,
I had a look at implementing this - is it true that quota is only updated after 
the full body of each request is received? For larger files, this would not 
give you the resolution to properly implement speed control.

An alternative could be using a callback in the `wget_tcp_read` function in 
`net.c` similar to how dns_stats are being collected.

Something like the following pseudocode:
```c

int64 speedlimit_cfg_limit;
double speedlimit_cfg_interval;

int64 speedlimit_data_left;
mutex speedlimit_mutex;
time_t speedlimit_next_time;

int speed_limit_callback(int data_read) {
  int time_to_sleep = 0;
  mutex_get();
  if (data_read > 0) {
    speed_limit_data_left -= data_read;
  }
  if (speed_limit_data_left <= 0) {
    // bandwidth allocation has been used up - work out next refresh time
    time_to_sleep = next_time - now();
  }
  mutex_release();
  
  if (time_to_sleep > 0) {
    // wait for refresh
    sleep(time_to_sleep);
  }
}
```

Then at certain times you can run something like the following pseudocode in a 
timer or thread

```c
void timer_run() {
  speedlimit_next_time = now();

  while (1) {
    if (speedlimit_next_time < now()) {
      mutex_get();
      speedlimit_next_time = now() + speedlimit_cfg_interval;
      speed_limit_data_left = speedlimit_cfg_limit;
      // you could also do advanced scheduling here
      // like having per connection / per thread divided limits
      // with dynamic optimization when some connections are slower than others
      mutex_release();
    }
    sleep(speedlimit_next_time - now());
  }
}

```

What are your thoughts?

-- 
Reply to this email directly or view it on GitLab: 
https://gitlab.com/gnuwget/wget2/issues/408#note_162355027
You're receiving this email because of your account on gitlab.com.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]