1edac3a2c900b27374d6163e2d8554110bb253ee
[openwrt-packages.git] /
1 commit 78714ea673cefa83d3dff5aa9aa5e97726cfb5cd
2 Author: Willy Tarreau <w@1wt.eu>
3 Date:   Mon Feb 25 15:02:04 2019 +0100
4
5     BUG/MINOR: listener: keep accept rate counters accurate under saturation
6     
7     The test on l->nbconn forces to exit the loop before updating the freq
8     counters, so the last session which reaches a listener's limit will not
9     be accounted for in the session rate measurement.
10     
11     Let's move the test at the beginning of the loop and mark the listener
12     as saturated on exit.
13     
14     This may be backported to 1.9 and 1.8.
15     
16     (cherry picked from commit 741b4d6b7aad1e4a66dd8584b5eff729b08fade7)
17     Signed-off-by: William Lallemand <wlallemand@haproxy.org>
18     (cherry picked from commit 5c7c7e447df84a04bda88c40382b652cdb77a079)
19     Signed-off-by: William Lallemand <wlallemand@haproxy.org>
20
21 diff --git a/src/listener.c b/src/listener.c
22 index 5f6fafbc..b94d823c 100644
23 --- a/src/listener.c
24 +++ b/src/listener.c
25 @@ -457,11 +457,6 @@ void listener_accept(int fd)
26         if (HA_SPIN_TRYLOCK(LISTENER_LOCK, &l->lock))
27                 return;
28  
29 -       if (unlikely(l->nbconn >= l->maxconn)) {
30 -               listener_full(l);
31 -               goto end;
32 -       }
33 -
34         if (!(l->options & LI_O_UNLIMITED) && global.sps_lim) {
35                 int max = freq_ctr_remain(&global.sess_per_sec, global.sps_lim, 0);
36  
37 @@ -520,7 +515,7 @@ void listener_accept(int fd)
38          * worst case. If we fail due to system limits or temporary resource
39          * shortage, we try again 100ms later in the worst case.
40          */
41 -       while (max_accept--) {
42 +       while (l->nbconn < l->maxconn && max_accept--) {
43                 struct sockaddr_storage addr;
44                 socklen_t laddr = sizeof(addr);
45                 unsigned int count;
46 @@ -627,11 +622,6 @@ void listener_accept(int fd)
47                         goto transient_error;
48                 }
49  
50 -               if (l->nbconn >= l->maxconn) {
51 -                       listener_full(l);
52 -                       goto end;
53 -               }
54 -
55                 /* increase the per-process number of cumulated connections */
56                 if (!(l->options & LI_O_UNLIMITED)) {
57                         count = update_freq_ctr(&global.sess_per_sec, 1);
58 @@ -659,6 +649,9 @@ void listener_accept(int fd)
59         limit_listener(l, &global_listener_queue);
60         task_schedule(global_listener_queue_task, tick_first(expire, global_listener_queue_task->expire));
61   end:
62 +       if (l->nbconn >= l->maxconn)
63 +               listener_full(l);
64 +
65         HA_SPIN_UNLOCK(LISTENER_LOCK, &l->lock);
66  }
67  
git clone https://git.99rst.org/PROJECT