haproxy public development tree
Go to file
Willy Tarreau 5064ab6a98 OPTIM: lb-leastconn: do not unlink the server if it did not change
Due to the two-phase server reservation, there are 3 calls to
fwlc_srv_reposition() per request, one during assign_server() to reserve
the slot, one in connect_server() to commit it, and one in process_stream()
to release it. However only one of the first two will change the key, so
it's needlessly costly to take the lock, remove a server and insert it
again at the same place when we can already figure we ought not to even
have taken the lock.

Furthermore, even when the server needs to move, there can be quite some
contention on the lbprm lock forcing the thread to wait. During this time
the served and nbpend server values might have changed, just like the
lb_node.key itself. Thus we measure the values again under the lock
before updating the tree. Measurements have shown that under contention
with 16 servers and 16 threads, 50% of the updates can be avoided there.

This patch makes the function compute the new key and compare it to
the current one before deciding to move the entry (and does it again
under the lock forthe second test).

This removes between 40 and 50% of the tree updates depending on the
thread contention and the number of servers. The performance gain due
to this (on 16 threads) was:

   16 servers:  415 krps -> 440 krps (6%, contention on lbprm)
    4 servers:  554 krps -> 714 krps (+29%, little contention)

One point worth thinking about is that it's not logic to update the
tree 2-3 times per request while it's only read once. half to 2/3 of
these updates are not needed. An experiment consisting in subscribing
the server to a list and letting the readers reinsert them on the fly
showed further degradation instead of an improvement.

A better approach would probably consist in avoinding writes to shared
cache lines by having the leastconn nodes distinct from the servers,
with one node per value, and having them hold an mt-list with all the
servers having that number of connections. The connection count tree
would then be read-mostly instead of facing heavy writes, and most
write operations would be performed on 1-3 list heads which are way
cheaper to migrate than a tree node, and do not require updating the
last two updated neighbors' cache lines.
2021-02-18 10:06:45 +01:00
.github CI: Fix the coverity builds 2021-01-28 20:40:14 +01:00
contrib MEDIUM: contrib/prometheus-exporter: add listen stats 2021-02-15 14:14:59 +01:00
doc [RELEASE] Released version 2.4-dev8 2021-02-13 10:17:27 +01:00
examples
include MINOR: lb/api: let callers of take_conn/drop_conn tell if they have the lock 2021-02-18 10:06:45 +01:00
reg-tests REGTESTS: fix http_reuse_conn_hash proxy test 2021-02-17 09:11:52 +01:00
scripts BUILD: Makefile: move REGTESTST_TYPE default setting 2021-02-05 11:41:16 +01:00
src OPTIM: lb-leastconn: do not unlink the server if it did not change 2021-02-18 10:06:45 +01:00
tests MEDIUM: config: remove the deprecated and dangerous global "debug" directive 2020-10-09 19:18:45 +02:00
.cirrus.yml CI: cirrus: update FreeBSD image to 12.2 2021-02-12 16:04:52 +01:00
.gitattributes
.gitignore CLEANUP: Update .gitignore 2020-09-12 13:11:24 +02:00
.travis.yml CI: travis-ci: drop coverity scan builds 2020-12-22 19:39:23 +01:00
BRANCHES DOC: fix some spelling issues over multiple files 2021-01-08 14:53:47 +01:00
CHANGELOG [RELEASE] Released version 2.4-dev8 2021-02-13 10:17:27 +01:00
CONTRIBUTING DOC: fix some spelling issues over multiple files 2021-01-08 14:53:47 +01:00
INSTALL DOC: fix some spelling issues over multiple files 2021-01-08 14:53:47 +01:00
LICENSE
MAINTAINERS DOC: Add maintainers for the Prometheus exporter 2021-01-08 15:14:15 +01:00
Makefile MEDIUM: resolvers/dns: split dns.c into dns.c and resolvers.c 2021-02-13 10:03:46 +01:00
README
ROADMAP
SUBVERS
VERDATE [RELEASE] Released version 2.4-dev8 2021-02-13 10:17:27 +01:00
VERSION [RELEASE] Released version 2.4-dev8 2021-02-13 10:17:27 +01:00

README

The HAProxy documentation has been split into a number of different files for
ease of use.

Please refer to the following files depending on what you're looking for :

  - INSTALL for instructions on how to build and install HAProxy
  - BRANCHES to understand the project's life cycle and what version to use
  - LICENSE for the project's license
  - CONTRIBUTING for the process to follow to submit contributions

The more detailed documentation is located into the doc/ directory :

  - doc/intro.txt for a quick introduction on HAProxy
  - doc/configuration.txt for the configuration's reference manual
  - doc/lua.txt for the Lua's reference manual
  - doc/SPOE.txt for how to use the SPOE engine
  - doc/network-namespaces.txt for how to use network namespaces under Linux
  - doc/management.txt for the management guide
  - doc/regression-testing.txt for how to use the regression testing suite
  - doc/peers.txt for the peers protocol reference
  - doc/coding-style.txt for how to adopt HAProxy's coding style
  - doc/internals for developer-specific documentation (not all up to date)