]> git.kaiwu.me - haproxy.git/commit
BUG/MINOR: time: frequency counters are not totally accurate
authorWilly Tarreau <w@1wt.eu>
Sat, 29 Dec 2012 20:50:07 +0000 (21:50 +0100)
committerWilly Tarreau <w@1wt.eu>
Sat, 29 Dec 2012 20:50:07 +0000 (21:50 +0100)
commiteab777c32eff7ee55a6ea12dd2f15fa14d66f233
tree1883c38a901ddb52ca670ca8a34f16fa74ebd21b
parenta3ecbd902345862b4a399f8a0bbaace6bc7ba4e6
BUG/MINOR: time: frequency counters are not totally accurate

When a frontend is rate-limited to 1000 connections per second, the
effective rate measured from the client is 999/s, and connections
experience an average response time of 99.5 ms with a standard
deviation of 2 ms.

The reason for this inaccuracy is that when computing frequency
counters, we use one part of the previous value proportional to the
number of milliseconds remaining in the current second. But even the
last millisecond still uses a part of the past value, which is wrong :
since we have a 1ms resolution, the last millisecond must be dedicated
only to filling the current second.

So we slightly adjust the algorithm to use 999/1000 of the past value
during the first millisecond, and 0/1000 of the past value during the
last millisecond.  We also slightly improve the computation by computing
the remaining time instead of the current time in tv_update_date(), so
that we don't have to negate the value in each frequency counter.

Now with the fix, the connection rate measured by both the client and
haproxy is a steady 1000/s, the average response time measured is 99.2ms
and more importantly, the standard deviation has been divided by 3 to
0.6 millisecond.

This fix should also be backported to 1.4 which has the same issue.
include/common/time.h
src/freq_ctr.c
src/time.c