Hello, Maxim!
It takes me some time to express new parameter with words, but finally it is as simple as "start to delay after N requests". I agree it more suitable then nodelay= and there is no need to warn about delay>burst.
Thank you, I'll be very happy to see this feature in upstream.
PS
There is now a small gotcha when trying to calculate delay (in seconds) based on excess value reported in log file, one should remember to subtract delay value from excess to get correct delay.
I am attaching updated tests in case you found them useful:
changeset: 1390:6ca33dd13079
tag: tip
user: Peter Shchuchkin <pet...@yandex.ru>
date: Sun Oct 28 11:34:41 2018 +0300
summary: Tests: testing limit_req with "burst=A delay=B" configuration
diff -r 73a9504ae6fd -r 6ca33dd13079 limit_req.t
--- a/limit_req.t Fri Oct 19 18:49:45 2018 +0300
+++ b/limit_req.t Sun Oct 28 11:34:41 2018 +0300
@@ -21,7 +21,7 @@
select STDERR; $| = 1;
select STDOUT; $| = 1;
-my $t = Test::Nginx->new()->has(qw/http limit_req/)->plan(6);
+my $t = Test::Nginx->new()->has(qw/http limit_req/)->plan(8);
$t->write_file_expand('nginx.conf', <<'EOF');
@@ -38,6 +38,7 @@
limit_req_zone $binary_remote_addr zone=one:1m rate=2r/s;
limit_req_zone $binary_remote_addr zone=long:1m rate=2r/s;
limit_req_zone $binary_remote_addr zone=fast:1m rate=1000r/s;
+ limit_req_zone $binary_remote_addr zone=mixed:1m rate=10r/s;
server {
listen 127.0.0.1:8080;
@@ -56,6 +57,12 @@
location /fast {
limit_req zone=fast burst=1;
}
+ location /mixed {
+ limit_req zone=mixed burst=2 delay=1;
+ }
+ location /mixed-pass {
+ limit_req zone=mixed burst=2 nodelay;
+ }
}
}
@@ -64,6 +71,8 @@
$t->write_file('test1.html', 'XtestX');
$t->write_file('long.html', "1234567890\n" x (1 << 16));
$t->write_file('fast.html', 'XtestX');
+$t->write_file('mixed.html', 'XtestX');
+$t->write_file('mixed-pass.html', 'XtestX');
$t->run();
###############################################################################
@@ -94,4 +103,20 @@
select undef, undef, undef, 0.1;
like(http_get('/fast.html'), qr/^HTTP\/1.. 200 /m, 'negative excess');
+# make sure requests are delayed when 0 < delay < burst
+# this test should fail when using nodelay or when delay>=burst
+
+http_get('/mixed.html');
+http_get('/mixed.html');
+http_get('/mixed.html');
+like(http_get('/mixed.html'), qr/^HTTP\/1.. 200 /m, 'mixed request is not rejected');
+
+# make sure it is possible to partially fill up excess through /mixed.html and get last request rejected
+# this test should fail when using "burst=A" with all delayed
+
+http_get('/mixed.html');
+http_get('/mixed.html');
+http_get('/mixed-pass.html');
+like(http_get('/mixed-pass.html'), qr/^HTTP\/1.. 503 /m, 'mixed request is rejected');
+
###############################################################################
_______________________________________________ nginx-devel mailing list nginx-devel@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx-devel