Welcome! Log In Create A New Profile

Advanced

Re: Using rate limitation for files smaller than the defined limit.

July 31, 2012 11:18AM
Dear Maxim,

thank you for your reply. I changed the code you suggested:
1. changed ngx_cached_time to ngx_timeofday()
2. added 1ms to send some bytes at request start

--- src/http/ngx_http_write_filter_module.c 2012-01-18 16:07:43.000000000 +0100
+++ src/http/ngx_http_write_filter_module.c.new 2012-07-31 16:38:11.074836346 +0200
@@ -211,8 +211,17 @@
}

if (r->limit_rate) {
- limit = r->limit_rate * (ngx_time() - r->start_sec + 1)
- - (c->sent - clcf->limit_rate_after);
+ ngx_time_t *t = ngx_timeofday();
+
+ if (t->msec >= r->start_msec) {
+ limit = r->limit_rate * (t->sec - r->start_sec)
+ + r->limit_rate * (t->msec - r->start_msec + 1) / 1000
+ - (c->sent - clcf->limit_rate_after);
+ } else {
+ limit = r->limit_rate * (t->sec - r->start_sec - 1)
+ + r->limit_rate * (t->msec - r->start_msec + 1001) / 1000
+ - (c->sent - clcf->limit_rate_after);
+ }

if (limit <= 0) {
c->write->delayed = 1;

Can we avoid network segmentation by setting the following configuration directives?
tcp_nodelay off;
tcp_nopush on;

Do you have any other suggestions how to rate limit objects, which size is smaller than specified in limit_rate, other way?

Regards,
Gabor
Subject Author Posted

Using rate limitation for files smaller than the defined limit.

leki75 July 30, 2012 08:22AM

Re: Using rate limitation for files smaller than the defined limit.

Maxim Dounin July 30, 2012 01:28PM

Re: Using rate limitation for files smaller than the defined limit.

leki75 July 31, 2012 11:18AM

Re: Using rate limitation for files smaller than the defined limit.

Maxim Dounin July 31, 2012 12:22PM

Re: Using rate limitation for files smaller than the defined limit.

leki75 August 22, 2012 09:24AM

Re: Using rate limitation for files smaller than the defined limit.

Maxim Dounin September 04, 2012 06:56AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 75
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready