Commit Graph

2073 Commits

Author SHA1 Message Date
Willy Tarreau
f5f3192e1e [DOC] fix typos, "#" is a sharp, not a dash
That's what happens when the same text is copy-pasted over and over...
2011-08-02 11:32:07 +02:00
Willy Tarreau
bc216c4ad0 [MINOR] proxy: make findproxy() return proxies from numeric IDs too
Sometimes it's useful to be able to search a proxy by its numeric ID,
so let's add support for names such as #<id>.
2011-08-02 11:25:54 +02:00
Willy Tarreau
e9b2602ac5 [MEDIUM] listeners: add a global listener management task
This global task is used to periodically check for end of resource shortage
and to try to enable queued listeners again. This is important in case some
temporary system-wide shortage is encountered, so that we don't have to wait
for an existing connection to be released before checking the queue again.

For situations where listeners are queued due to the global maxconn being
reached, the task is woken up at least every second. For situations where
a system resource shortage is detected (memory, sockets, ...) the task is
woken up at least every 100 ms. That way, recovery from severe events can
still be achieved under acceptable conditions.
2011-08-01 20:57:55 +02:00
Willy Tarreau
237250cc0d [BUG] proxy: stats frontend and peers were missing many initializers
This was revealed with one of the very latest patches which caused
the listener_queue not to be initialized on the stats socket frontend.
And in fact a number of other ones were missing too. This is getting so
boring that now we'll always make use of the same function to initialize
any proxy. Doing so has even saved about 500 bytes on the binary due to
the avoided code redundancy.

No backport is needed.
2011-07-29 02:00:19 +02:00
Willy Tarreau
918ff608f8 [MAJOR] proxy: finally get rid of maintain_proxies()
This function is finally not needed anymore, as it has been replaced with
a per-proxy task that is scheduled when some limits are encountered on
incoming connections or when the process is stopping. The savings should
be noticeable on configs with a large number of proxies. The most important
point is that the rate limiting is now enforced in a clean and solid way.
2011-07-25 16:33:49 +02:00
Willy Tarreau
26e4881a2d [MINOR] task: new function task_schedule() to schedule a wake up
This function is used when a task should be woken up at most at a given
date. This will be used with rate shapers.
2011-07-25 15:30:39 +02:00
Willy Tarreau
d634e7c673 [CLEANUP] proxy: merge maintain_proxies() operation inside a single loop
This will help transforming the processing into per-proxy tasks.
2011-07-25 11:54:17 +02:00
Willy Tarreau
bbe11b1e3c [BUG] proxy: peers must only be stopped once, not upon every call to maintain_proxies
Peers were stopped on every call to maintain_proxies when stopping=1,
while they should only be stopped once upon call to soft_stop(). This
bug has little impact, mostly increased CPU usage. It's not needed to
backport it.
2011-07-25 11:16:24 +02:00
Willy Tarreau
b32907b6c7 [MINOR] sessions: only wake waiting listeners up if rate limit is OK
Instead of waking a listener up then making it sleep, we only wake them up
if we know their rate limit is fine. In the future we could improve on top
of that by deciding to wake a proxy-specific task in XX milliseconds to
take care of enabling the listeners again.
2011-07-25 08:37:44 +02:00
Willy Tarreau
d408bd40f3 [MINOR] proxy: make session rate-limit more accurate
Patch d9bbe17b used to limit the rate-limit to off-by-one to avoid
a busy loop when the limit is reached. Now that the listeners are
automatically disabled and queued when a limit is reached, we don't
need this workaround anymore and can bring back the most accurate
computation.
2011-07-25 08:30:51 +02:00
Willy Tarreau
a17c2d9361 [MINOR] stats: report a "WAITING" state for sockets waiting for resource
This is useful when enabling socket-stats to know that a socket is being
waiting for some resource (RAM, global connections, etc...).
2011-07-25 08:18:47 +02:00
Willy Tarreau
562515cac1 [CLEANUP] proxy: rename a few proxy states (PR_STIDLE and PR_STRUN)
Those states have been replaced with PR_STFULL and PR_STREADY respectively,
as it is what matches them the best now. Also, two occurrences of PR_STIDLE
in peers.c have been removed as this did not provide any form of error recovery
anyway.
2011-07-25 08:11:52 +02:00
Willy Tarreau
f3f8c70bd6 [MEDIUM] listeners: don't change listeners states anymore in maintain_proxies
Now maintain_proxies() only changes proxies states and does not affect their
listeners anymore since they are autonomous. A proxy will switch between the
PR_STIDLE and PR_STRUN states depending whether it's saturated or not. Next
step will consist in renaming PR_STIDLE to PR_STFULL. This state is now only
used to report the proxy state in the stats.
2011-07-25 07:37:28 +02:00
Willy Tarreau
2242649b3a [MEDIUM] listeners: don't stop proxies when global maxconn is reached
Now we don't have to stop proxies anymore since their listeners will be
queued if they attempt to accept a connection past the global limits.
2011-07-25 07:08:45 +02:00
Willy Tarreau
07687c171e [MEDIUM] listeners: queue proxy-bound listeners at the proxy's
All listeners that are limited by a proxy-specific resource are now
queued at the proxy's and not globally. This allows finer-grained
wakeups when releasing resource.
2011-07-24 23:55:06 +02:00
Willy Tarreau
08ceb1012b [MEDIUM] listeners: put listeners in queue upon resource shortage
When an accept() fails because of a connection limit or a memory shortage,
we now disable it and queue it so that it's dequeued only when a connection
is released. This has improved the behaviour of the process near the fd limit
as now a listener with a no connection (eg: stats) will not loop forever
trying to get its connection accepted.

The solution is still not 100% perfect, as we'd like to have this used when
proxy limits are reached (use a per-proxy list) and for safety, we'd need
to have dedicated tasks to periodically re-enable them (eg: to overcome
temporary system-wide resource limitations when no connection is released).
2011-07-24 22:58:00 +02:00
Willy Tarreau
e6ca1fcd84 [MINOR] listeners: add support for queueing resource limited listeners
When a listeners encounters a resource shortage, it currently stops until
one re-enables it. This is far from being perfect as it does not yet handle
the case where the single connection from the listener is rejected (eg: the
stats page).

Now we'll have a special status for resource limited listeners and we'll
queue them into one or multiple lists. That way, each time we have to stop
a listener because of a resource shortage, we can enqueue it and change its
state, so that it is dequeued once more resources are available.

This patch currently does not change any existing behaviour, it only adds
the basic building blocks for doing that.
2011-07-24 22:03:52 +02:00
Willy Tarreau
627937158f [MINOR] listeners: add listen_full() to mark a listener full
This is just a cleanup which removes calls to EV_FD_CLR() and state
setting everywhere in the code.
2011-07-24 19:25:28 +02:00
Willy Tarreau
ff45b8ccc6 [BUG] stream_sock: ensure orphan listeners don't accept too many connections
For listeners that are not bound to a frontend, the limit on the
number of accepted connections is tested at the end of the accept()
loop, but we don't break out of the loop, meaning that if more
connections than what the listener allows are available and if this
is less than the proxy's limits and within the size of a batch, then
they could be accepted. In practice, this problem currently cannot
appear since all listeners are bound to a frontend, and it's a very
minor issue anyway.

1.4 has the same issue (which cannot happen there either), but there
is some code after it, so it's the code cleanup which revealed it.
2011-07-24 19:16:52 +02:00
Willy Tarreau
be58c38264 [MEDIUM] proxy: add a PAUSED state to listeners and move socket tricks out of proxy.c
Managing listeners state is difficult because they have their own state
and can at the same time have theirs dictated by their proxy. The pause
is not done properly, as the proxy code is fiddling with sockets. By
introducing new functions such as pause_listener()/resume_listener(), we
make it a bit more obvious how/when they're supposed to be used. The
listen_proxies() function was also renamed to resume_proxies() since
it's only used for pause/resume.

This patch is the first in a series aiming at getting rid of the maintain_proxies
mess. In the end, proxies should not call enable_listener()/disable_listener()
anymore.
2011-07-24 19:09:37 +02:00
Willy Tarreau
100298749b [BUG] stream_sock: disable listener when system resources are exhausted
When an accept() returns -1 ENFILE du to system limits, it leaves the
connection pending in the backlog and epoll() comes back immediately
afterwards trying to make it accept it again. This causes haproxy to
remain at 100% CPU until something makes an accept() possible again.
Now upon such resource shortage, we mark the listener FULL so that we
only enable it again once at least one connection has been released.
In fact we only do that if there are some active connections on this
proxy, so that it has a chance to be marked not full again. This makes
haproxy remain idle when all resources are used, which helps a lot
releasing those resource as fast as possible.

Backport to 1.4 might be desirable but difficult and tricky.
2011-07-24 16:16:14 +02:00
Willy Tarreau
4827fd2a7e [OPTIM] stream_sock: reduce the default number of accepted connections at once
By default on a single process, we accept 100 connections at once. This is too
much on recent CPUs where the cache is constantly thrashing, because we visit
all those connections several times. We should batch the processing slightly
less so that all the accepted session may remain in cache during their initial
processing.

Lowering the batch size from 100 to 32 has changed the connection rate for
concurrencies between 5-10k from 67 kcps to 94 kcps on a Core i5 660 (4M L3),
and forward rates from 30k to 39.5k.

Tests on this hardware show that values between 10 and 30 seem to do the job fine.
2011-07-24 16:12:27 +02:00
Willy Tarreau
2b15492a75 [MINOR] session: try to emit a 500 response on memory allocation errors
When we fail to create a session because of memory shortage, let's at
least try to send a 500 message directly on the socket. Even if we don't
have any buffers left, the kernel's orphans management will take care of
delivering the message as long as there are socket buffers left.
2011-07-24 16:12:25 +02:00
Willy Tarreau
9bd0d744ef [BUG] session: risk of crash on out of memory (1.5-dev regression)
Patch af5149 introduced an issue which can be detected only on out of
memory conditions : a LIST_DEL() may be performed on an uninitialized
struct member instead of a LIST_INIT() during the accept() phase,
causing crashes and memory corruption to occur.

This issue was detected and diagnosed by the Exceliance R&D team.

This is 1.5-specific and very recent, so no existing deployment should
be impacted.
2011-07-20 00:22:54 +02:00
Simon Horman
6fb8259014 [MINOR] Free stick rules on denint()
The motivation for this is that when soft-restart is merged
it will be come more important to free all relevant memory in deinit()

Discovered using valgrind.
2011-07-18 10:21:24 +02:00
Simon Horman
b08584ac71 [MINOR] Free stick table pool on denint()
The motivation for this is that when soft-restart is merged
it will be come more important to free all relevant memory in deinit()

Discovered using valgrind.
2011-07-18 10:21:24 +02:00
Simon Horman
ac8214260e [MINOR] Free tcp rules on denint()
The motivation for this is that when soft-restart is merged
it will be come more important to free all relevant memory in deinit()

Discovered using valgrind.
2011-07-18 10:21:23 +02:00
Simon Horman
a31c7f716b [MINOR] Free rdp_cookie_name on denint()
The motivation for this is that when soft-restart is merged
it will be come more important to free all relevant memory in deinit()

Discovered using valgrind.
2011-07-18 10:21:23 +02:00
Simon Horman
5e55f5dadc [MINOR] Consistently free expr on error in cfg_parse_listen()
It seems to me that without this change cfg_parse_listen()
may leak memory.
2011-07-18 10:21:23 +02:00
Simon Horman
6c54d8b63b [MINOR] Consistently use error in tcp_parse_tcp_req()
It seems to me that without this change tcp_parse_tcp_req()
may leak memory.
2011-07-18 10:21:23 +02:00
Willy Tarreau
14389e7036 [OPTIM] halog: remove support for tab delimiters in input data
Haproxy does not use tabs when sending logs, and checking for them
wastes no less than 4% of CPU cycles. Better get rid of these tests.
2011-07-11 06:48:04 +02:00
Willy Tarreau
a2b39fb5c5 [OPTIM] halog: remove many 'if' by using a function pointer for the filters
There were too many filters, we were losing time in all the "if" statements.
By moving all the filters to independant functions, we made the code cleaner
and slightly faster (3%).

One minor bug was found, the -tc and -st options did not report the number
of output lines, but always zero.
2011-07-11 06:48:04 +02:00
Willy Tarreau
26deaf51d9 [OPTIM] halog: check once for correct line format and reuse the pointer
Almost all filters first check the line format, which takes a lot of code
and requires parsing back and forth. By centralizing this test, we can
save about 15-20 more percent of performance for all filters.

Also, the test was wrong, it was checking that the source IP address was
starting with a digit, which is not always true with local IPv6 addresses.
Instead, we now check that the next field (accept field) starts with an
opening bracket and is followed by a digit between 0 and 3 (day of the
month). Doing this has contributed a 2% speedup because all other field
calculations were relative to a closer field.
2011-07-11 06:48:04 +02:00
Willy Tarreau
758a6ea46c [OPTIM] halog: cache some common fields positions
Since many fields are relative and some are used a lot, try to cache them
the first time they're used in order to avoid skipping them twice. The
status counts with HTTP pre-check enabled has sped up by 40%.
2011-07-11 06:48:03 +02:00
Willy Tarreau
df6f0d1e49 [MINOR] halog: gain back performance before SKIP_CHAR fix
The SKIP_CHAR fix caused a measurable performance drop. Since we can
consider all chars below 0x20 as delimiters, we can avoid a cache lookup
which requires a char to pointer conversion.
2011-07-11 06:48:03 +02:00
Willy Tarreau
70c428f7c6 [MINOR] halog: add support for HTTP log matching (-H)
Now it's possible to restrict analysis to HTTP-looking logs when passing -H.
-H -v gives the opposite (most likely TCP logs).
2011-07-11 06:48:03 +02:00
Willy Tarreau
c82570edec [MINOR] halog: make SKIP_CHAR stop on field delimiters
The SKIP_CHAR() macro did not consider field delimiters, causing the timer parser
to be able to search timers at wrong places when fed with TCP logs.
2011-07-11 06:48:02 +02:00
Willy Tarreau
812e7a73b2 [BUG] halog: correctly handle truncated last line
If last line is truncated (eg: truncated file), then halog would loop on
it forever.
2011-07-11 06:48:02 +02:00
Willy Tarreau
b3eb221e78 [MEDIUM] http: add support for 'cookie' and 'set-cookie' patterns
This is used to perform cookie-based stickiness with table replication
between multiple masters and across restarts. This partially overrides
some of the appsession capabilities.
2011-07-01 16:16:17 +02:00
Willy Tarreau
d8dc99f68d [DOC] add missing entry or stick store-response 2011-07-01 11:33:25 +02:00
Simon Horman
fa46168c8f [MINOR] Add non-stick server option
Never add connections allocated to this sever to a stick-table.
This may be used in conjunction with backup to ensure that
stick-table persistence is disabled for backup servers.
2011-06-25 21:14:17 +02:00
Simon Horman
de072bd8ff [CLEANUP] Remove unnecessary casts
There is no need to cast when going to or from void *
2011-06-25 21:14:10 +02:00
Simon Horman
ab814e0a6b [MINOR] Add rdp_cookie pattern fetch function
This pattern fetch function extracts the value of the rdp cookie <name> as
a string and uses this value to match. This enables implementation of
persistence based on the mstshash cookie. This is typically done if there
is no msts cookie present.

This differs from "balance rdp-cookie" in that any balancing algorithm may
be used and thus the distribution of clients to backend servers is not
linked to a hash of the RDP cookie. It is envisaged that using a balancing
algorithm such as "balance roundrobin" or "balance leastconnect" will lead
to a more even distribution of clients to backend servers than the hash
used by "balance rdp-cookie".

Example :
	listen tse-farm
	    bind 0.0.0.0:3389
	    # wait up to 5s for an RDP cookie in the request
	    tcp-request inspect-delay 5s
	    tcp-request content accept if RDP_COOKIE
	    # apply RDP cookie persistence
	    persist rdp-cookie
	    # Persist based on the mstshash cookie
	    # This is only useful makes sense if
	    # balance rdp-cookie is not used
	    stick-table type string size 204800
	    stick on rdp_cookie(mstshash)
	    server srv1 1.1.1.1:3389
	    server srv1 1.1.1.2:3389
2011-06-25 21:07:02 +02:00
Simon Horman
e869176486 [MINOR] Make appsess{,ion}_refresh static
apsession_refresh() and apsess_refressh are only used inside apsession.c
and thus can be made static.

The only use of apsession_refresh() is appsession_task_init().
These functions have been re-ordered to avoid the need for
a forward-declaration of apsession_refresh().
2011-06-25 21:07:01 +02:00
Simon Horman
752dc4ab2d [MINOR] Add down termination condition
If a connection is closed by because the backend became unavailable
then log 'D' as the termination condition.

Signed-off-by: Simon Horman <horms@verge.net.au>
2011-06-21 22:10:56 +02:00
Simon Horman
e0d1bfb4c1 [MINOR] Allow shutdown of sessions when a server becomes unavailable
This adds the "on-marked-down shutdown-sessions" statement on "server" lines,
which causes all sessions established on a server to be killed at once when
the server goes down. The task's priority is reniced to the highest value
(1024) so that servers holding many tasks don't cause a massive slowdown due
to the wakeup storm.
2011-06-21 22:00:21 +02:00
Simon Horman
af51495397 [MINOR] Add active connection list to server
The motivation for this is to allow iteration of all the connections
of a server without the expense of iterating over the global list
of connections.

The first use of this will be to implement an option to close connections
associated with a server when is is marked as being down or in maintenance
mode.
2011-06-21 22:00:12 +02:00
Simon Horman
dec5be4ed4 [CLEANUP] session.c: Make functions static where possible 2011-06-18 20:27:19 +02:00
Simon Horman
96553775a0 [CLEANUP] peers.h: fix declarations
* The declaration of peer_session_create() does
  not match its definition. As it is only
  used inside of peers.c make it static.

* Make the declaration of peers_register_table()
  match its definition.

* Also, make all functions in peers.c that
  are not also in peers.h static
2011-06-18 20:27:19 +02:00
Simon Horman
70735c98f7 [CLEANUP] Remove assigned but unused variables
gcc (Debian 4.6.0-2) 4.6.1 20110329 (prerelease)
Copyright (C) 2011 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

...
src/proto_http.c:3029:14: warning: variable ‘del_cl’ set but not used [-Wunused-but-set-variable]
In file included from ebtree/eb64tree.c:23:0:
ebtree/eb64tree.h: In function ‘__eb64_lookup’:
ebtree/eb64tree.h:128:6: warning: variable ‘node_bit’ set but not used [-Wunused-but-set-variable]
ebtree/eb64tree.h: In function ‘__eb64i_lookup’:
ebtree/eb64tree.h:180:6: warning: variable ‘node_bit’ set but not used [-Wunused-but-set-variable]
In file included from ebtree/ebpttree.h:26:0,
                 from ebtree/ebimtree.c:23:
ebtree/eb64tree.h: In function ‘__eb64_lookup’:
ebtree/eb64tree.h:128:6: warning: variable ‘node_bit’ set but not used [-Wunused-but-set-variable]
ebtree/eb64tree.h: In function ‘__eb64i_lookup’:
ebtree/eb64tree.h:180:6: warning: variable ‘node_bit’ set but not used [-Wunused-but-set-variable]
In file included from ebtree/ebpttree.h:26:0,
                 from ebtree/ebistree.h:25,
                 from ebtree/ebistree.c:23:
ebtree/eb64tree.h: In function ‘__eb64_lookup’:
ebtree/eb64tree.h:128:6: warning: variable ‘node_bit’ set but not used [-Wunused-but-set-variable]
ebtree/eb64tree.h: In function ‘__eb64i_lookup’:
ebtree/eb64tree.h:180:6: warning: variable ‘node_bit’ set but not used [-Wunused-but-set-variable]
2011-06-18 20:21:33 +02:00