Mercurial > hg > nginx
annotate src/http/modules/perl/nginx.pm @ 7281:bd6563e81cea
Limit req: improved handling of negative times.
Negative times can appear since workers only update time on an event
loop iteration start. If a worker was blocked for a long time during
an event loop iteration, it is possible that another worker already
updated the time stored in the node. As such, time since last update
of the node (ms) will be negative.
Previous code used ngx_abs(ms) in the calculations. That is, negative
times were effectively treated as positive ones. As a result, it was
not possible to maintain high request rates, where the same node can be
updated multiple times from during an event loop iteration.
In particular, this affected setups with many SSL handshakes, see
http://mailman.nginx.org/pipermail/nginx/2018-May/056291.html.
Fix is to only update the last update time stored in the node if the
new time is larger than previously stored one. If a future time is
stored in the node, we preserve this time as is.
To prevent breaking things on platforms without monotonic time available
if system time is updated backwards, a safety limit of 60 seconds is
used. If the time stored in the node is more than 60 seconds in the future,
we assume that the time was changed backwards and update lr->last
to the current time.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Wed, 30 May 2018 15:40:34 +0300 |
parents | be5cfa918bfc |
children | 985b0bda403c |
rev | line source |
---|---|
599 | 1 package nginx; |
2 | |
3 use 5.006001; | |
4 use strict; | |
5 use warnings; | |
6 | |
7 require Exporter; | |
8 | |
9 our @ISA = qw(Exporter); | |
10 | |
11 our @EXPORT = qw( | |
12 OK | |
13 DECLINED | |
914 | 14 |
599 | 15 HTTP_OK |
914 | 16 HTTP_CREATED |
3604 | 17 HTTP_ACCEPTED |
914 | 18 HTTP_NO_CONTENT |
19 HTTP_PARTIAL_CONTENT | |
20 | |
21 HTTP_MOVED_PERMANENTLY | |
22 HTTP_MOVED_TEMPORARILY | |
599 | 23 HTTP_REDIRECT |
4491
d11f86a16e3b
Added support for the 307 Temporary Redirect.
Ruslan Ermilov <ru@nginx.com>
parents:
4483
diff
changeset
|
24 HTTP_SEE_OTHER |
914 | 25 HTTP_NOT_MODIFIED |
4491
d11f86a16e3b
Added support for the 307 Temporary Redirect.
Ruslan Ermilov <ru@nginx.com>
parents:
4483
diff
changeset
|
26 HTTP_TEMPORARY_REDIRECT |
6977
be5cfa918bfc
Added support for the "308 Permanent Redirect" (ticket #877).
Simon Leblanc <contact@leblanc-simon.eu>
parents:
5146
diff
changeset
|
27 HTTP_PERMANENT_REDIRECT |
914 | 28 |
29 HTTP_BAD_REQUEST | |
30 HTTP_UNAUTHORIZED | |
31 HTTP_PAYMENT_REQUIRED | |
32 HTTP_FORBIDDEN | |
599 | 33 HTTP_NOT_FOUND |
914 | 34 HTTP_NOT_ALLOWED |
35 HTTP_NOT_ACCEPTABLE | |
36 HTTP_REQUEST_TIME_OUT | |
37 HTTP_CONFLICT | |
38 HTTP_GONE | |
39 HTTP_LENGTH_REQUIRED | |
40 HTTP_REQUEST_ENTITY_TOO_LARGE | |
41 HTTP_REQUEST_URI_TOO_LARGE | |
42 HTTP_UNSUPPORTED_MEDIA_TYPE | |
43 HTTP_RANGE_NOT_SATISFIABLE | |
44 | |
45 HTTP_INTERNAL_SERVER_ERROR | |
599 | 46 HTTP_SERVER_ERROR |
914 | 47 HTTP_NOT_IMPLEMENTED |
48 HTTP_BAD_GATEWAY | |
49 HTTP_SERVICE_UNAVAILABLE | |
50 HTTP_GATEWAY_TIME_OUT | |
51 HTTP_INSUFFICIENT_STORAGE | |
599 | 52 ); |
53 | |
5146
f45b83d20cfb
Simplified nginx version maintenance.
Ruslan Ermilov <ru@nginx.com>
parents:
5140
diff
changeset
|
54 our $VERSION = '%%VERSION%%'; |
599 | 55 |
56 require XSLoader; | |
57 XSLoader::load('nginx', $VERSION); | |
58 | |
59 # Preloaded methods go here. | |
60 | |
914 | 61 use constant OK => 0; |
62 use constant DECLINED => -5; | |
63 | |
64 use constant HTTP_OK => 200; | |
65 use constant HTTP_CREATED => 201; | |
3604 | 66 use constant HTTP_ACCEPTED => 202; |
914 | 67 use constant HTTP_NO_CONTENT => 204; |
68 use constant HTTP_PARTIAL_CONTENT => 206; | |
69 | |
70 use constant HTTP_MOVED_PERMANENTLY => 301; | |
71 use constant HTTP_MOVED_TEMPORARILY => 302; | |
72 use constant HTTP_REDIRECT => 302; | |
4491
d11f86a16e3b
Added support for the 307 Temporary Redirect.
Ruslan Ermilov <ru@nginx.com>
parents:
4483
diff
changeset
|
73 use constant HTTP_SEE_OTHER => 303; |
914 | 74 use constant HTTP_NOT_MODIFIED => 304; |
4491
d11f86a16e3b
Added support for the 307 Temporary Redirect.
Ruslan Ermilov <ru@nginx.com>
parents:
4483
diff
changeset
|
75 use constant HTTP_TEMPORARY_REDIRECT => 307; |
6977
be5cfa918bfc
Added support for the "308 Permanent Redirect" (ticket #877).
Simon Leblanc <contact@leblanc-simon.eu>
parents:
5146
diff
changeset
|
76 use constant HTTP_PERMANENT_REDIRECT => 308; |
599 | 77 |
914 | 78 use constant HTTP_BAD_REQUEST => 400; |
79 use constant HTTP_UNAUTHORIZED => 401; | |
80 use constant HTTP_PAYMENT_REQUIRED => 402; | |
81 use constant HTTP_FORBIDDEN => 403; | |
82 use constant HTTP_NOT_FOUND => 404; | |
83 use constant HTTP_NOT_ALLOWED => 405; | |
84 use constant HTTP_NOT_ACCEPTABLE => 406; | |
85 use constant HTTP_REQUEST_TIME_OUT => 408; | |
86 use constant HTTP_CONFLICT => 409; | |
87 use constant HTTP_GONE => 410; | |
88 use constant HTTP_LENGTH_REQUIRED => 411; | |
89 use constant HTTP_REQUEST_ENTITY_TOO_LARGE => 413; | |
90 use constant HTTP_REQUEST_URI_TOO_LARGE => 414; | |
91 use constant HTTP_UNSUPPORTED_MEDIA_TYPE => 415; | |
92 use constant HTTP_RANGE_NOT_SATISFIABLE => 416; | |
93 | |
94 use constant HTTP_INTERNAL_SERVER_ERROR => 500; | |
95 use constant HTTP_SERVER_ERROR => 500; | |
96 use constant HTTP_NOT_IMPLEMENTED => 501; | |
97 use constant HTTP_BAD_GATEWAY => 502; | |
98 use constant HTTP_SERVICE_UNAVAILABLE => 503; | |
99 use constant HTTP_GATEWAY_TIME_OUT => 504; | |
100 use constant HTTP_INSUFFICIENT_STORAGE => 507; | |
599 | 101 |
102 | |
1178
a77f6980de50
rename $r->rflush to $r->flush
Igor Sysoev <igor@sysoev.ru>
parents:
1177
diff
changeset
|
103 sub rflush { |
a77f6980de50
rename $r->rflush to $r->flush
Igor Sysoev <igor@sysoev.ru>
parents:
1177
diff
changeset
|
104 my $r = shift; |
a77f6980de50
rename $r->rflush to $r->flush
Igor Sysoev <igor@sysoev.ru>
parents:
1177
diff
changeset
|
105 |
a77f6980de50
rename $r->rflush to $r->flush
Igor Sysoev <igor@sysoev.ru>
parents:
1177
diff
changeset
|
106 $r->flush; |
a77f6980de50
rename $r->rflush to $r->flush
Igor Sysoev <igor@sysoev.ru>
parents:
1177
diff
changeset
|
107 } |
a77f6980de50
rename $r->rflush to $r->flush
Igor Sysoev <igor@sysoev.ru>
parents:
1177
diff
changeset
|
108 |
a77f6980de50
rename $r->rflush to $r->flush
Igor Sysoev <igor@sysoev.ru>
parents:
1177
diff
changeset
|
109 |
599 | 110 1; |
111 __END__ | |
112 | |
113 =head1 NAME | |
114 | |
115 nginx - Perl interface to the nginx HTTP server API | |
116 | |
117 =head1 SYNOPSIS | |
118 | |
119 use nginx; | |
120 | |
121 =head1 DESCRIPTION | |
122 | |
123 This module provides a Perl interface to the nginx HTTP server API. | |
124 | |
125 | |
126 =head1 SEE ALSO | |
127 | |
4977
b216d212920b
Brought the link to ngx_http_perl_module documentation up to date.
Ruslan Ermilov <ru@nginx.com>
parents:
4942
diff
changeset
|
128 http://nginx.org/en/docs/http/ngx_http_perl_module.html |
599 | 129 |
130 =head1 AUTHOR | |
131 | |
132 Igor Sysoev | |
133 | |
134 =head1 COPYRIGHT AND LICENSE | |
135 | |
136 Copyright (C) Igor Sysoev | |
4411 | 137 Copyright (C) Nginx, Inc. |
599 | 138 |
139 | |
140 =cut |