Commit Graph

556 Commits

Author SHA1 Message Date
Willy Tarreau
e855f427cb [RELEASE] Released version 1.3.13 with the following main changes :
- replace the code under O'Reilly license (Arnaud Cornet)
    - add a small man page (Arnaud Cornet)
    - stats: report haproxy's version by default (Krzysztof Oledzki)
    - stats: count server retries and redispatches (Krzysztof Oledzki)
    - core: added easy support for Doug Lea's malloc (dlmalloc)
    - core: fade out memory usage when stopping proxies
    - core: moved the sockaddr pointer to the fdtab structure
    - core: add generic protocol support
    - core: implement client-side support for PF_UNIX sockets
    - stats: implement the CSV output
    - stats: add a link to the CSV export HTML page
    - stats: implement the statistics output on a unix socket
    - config: introduce the "stats" keyword in global section
    - build: centralize version and date into one file for each
    - tests: added a new hash algorithm
2007-10-18 22:38:22 +02:00
Krzysztof Oledzki
1cf36ba3ae [MEDIUM] stats: count server retries and redispatches
It is important to know how your installation performs. Haproxy masks
connection errors, which is extremely good for a client but it is bad for
an administrator (except people believing that "ignorance is a bless").

Attached patch adds retries and redispatches counters, so now haproxy:

1. For server:
 - counts retried connections (masked or not)

2. For backends:
 - counts retried connections (masked or not) that happened to
    a slave server
 - counts redispatched connections
 - does not count successfully redispatched connections as backend errors.
    Errors are increased only when client does not get a valid response,
    in other words: with failed redispatch or when this function is not
    enabled.

3. For statistics:
 - display Retr (retries) and Redis (redispatches) as a "Warning"
   information.
2007-10-18 19:12:30 +02:00
Willy Tarreau
9edd161554 [MINOR] use nolinger on health-checks if backend is set to nolinger
If the administrator finds it useful to disable lingering on the backend,
let's disable lingering on health-checks too.
2007-10-18 18:07:48 +02:00
Willy Tarreau
1388a3a8e8 [BUG] scope "." must match the backend and not the frontend 2007-10-18 16:38:37 +02:00
Willy Tarreau
10ae548052 [BUG] fix off-by-one in path length in destroy_uxst_socket()
An off-by-one error was left in the computation of the unix socket path.
2007-10-18 16:15:52 +02:00
Willy Tarreau
03f6d67c48 [BUILD] fix build of global section with older gcc versions
The way the global section was initialized was not correct, which
made older versions of GCC complain.
2007-10-18 15:15:57 +02:00
Willy Tarreau
fbee71331d [MEDIUM] introduce the "stats" keyword in global section
Removed old unused MODE_LOG and MODE_STATS, and replaced the "stats"
keyword in the global section. The new "stats" keyword in the global
section is used to create a UNIX socket on which the statistics will
be accessed.  The client must issue a "show stat\n" command in order
to get a CSV-formated output similar to the output on the HTTP socket
in CSV mode.
2007-10-18 14:16:11 +02:00
Willy Tarreau
3e76e728ce [MEDIUM] implement the statistics output on a unix socket
A unix socket can now access the statistics. It currently only
recognizes the "show stat\n" command at the beginning of the
input, then returns the statistics in CSV format.
2007-10-18 14:13:13 +02:00
Willy Tarreau
5031e6adf5 [MINOR] add a link to the CSV export on the stats page. 2007-10-18 14:12:30 +02:00
Willy Tarreau
55bb8450c0 [MEDIUM] implement the CSV output for the statistics
It is now possible to get CSV ouput from the statistics by
simply appending ";csv" to the HTTP request sent to get the
stats. The fields keep the same ordering as in the HTML page,
and a field "pxname" has been prepended at the beginning of
the line.
2007-10-18 14:12:28 +02:00
Willy Tarreau
9186126e1c [MEDIUM] moved stats and buffer generic functions to new files
Neither the primitives used to write data to a buffer, nor the stats
dump functions are HTTP-specific anymore. Move them to dedicated
files
2007-10-18 14:12:21 +02:00
Willy Tarreau
e6ad2b165e [MINOR] make it possible to set unix socket permissions
Under most systems, it is possible to set permissions on unix
sockets. This has been added to the listeners and to unix
sockets.
2007-10-18 14:11:55 +02:00
Willy Tarreau
92fb9836ee [MAJOR] implemented client-side support for PF_UNIX sockets
A new file, proto_uxst.c, implements support of PF_UNIX sockets
of type SOCK_STREAM. It relies on generic stream_sock_read/write
and uses its own accept primitive which also tries to be generic.

Right now it only implements an echo service in sight of a general
support for start dumping via unix socket. The echo code is more
of a proof of concept than useful code.
2007-10-18 14:11:15 +02:00
Willy Tarreau
dd81598553 [MAJOR] added generic protocol support
A new generic protocol mechanism has been added. It provides
an easy method to implement new protocols with different
listeners (eg: unix sockets).

The listeners are automatically started at the right moment
and enabled after the possible fork().
2007-10-18 14:11:12 +02:00
Willy Tarreau
d680371064 [BUG] remove condition for exit() under fork() failure
This must come from a copy-paste typo: in the unlikely event that
fork() would fail, the parent process would only exit(1) if there
were old pids. That's non-sense.
2007-10-16 07:44:56 +02:00
Willy Tarreau
d95dcb51a8 [BUG] fix wrong timeout computation in event_accept()
In case the incoming socket is set for write and not for read (very
unlikely, except in HEALTH mode), the timeout may remain eternity due
to a copy-paste typo.
2007-10-16 07:41:52 +02:00
Willy Tarreau
177a16a8d1 [BUG] fix segfault on exit in new appsession code
The new appsession code didn't like it when appsession_hash_destroy()
was called with an empty hash table. Simply add the check.
2007-10-15 20:08:16 +02:00
Willy Tarreau
f223cc0b5c [MEDIUM] fixed call to chroot() during startup
It wasn't very wise to chroot() early during the startup. Also,
the exit() was missing if the chroot() failed.
2007-10-15 18:57:08 +02:00
Willy Tarreau
e94ebd0e37 [MEDIUM] moved the sockaddr pointer to the fdtab structure
The stream_sock_* functions had to know about sessions just in
order to get the server's address for a connect() operation. This
is not desirable, particularly for non-IP protocols (eg: PF_UNIX).

Put a pointer to the peer's sockaddr_storage or sockaddr address
in the fdtab structure so that we never need to look further.

With this small change, the stream_sock.c file is now 100% protocol
independant.
2007-10-15 17:14:01 +02:00
Krzysztof Oledzki
d9db9274fe [MINOR] report haproxy's version by default on the stats page
For people who manage many haproxies, it is sometimes convenient
to be informed of their version. This patch adds this, with the
option to disable this report by specifying "stats hide-version".

Also, the feature may be permanently disabled by setting the
STATS_VERSION_STRING to "" (empty string), or the format can
simply be adjusted.
2007-10-15 10:05:11 +02:00
Willy Tarreau
fe255b7061 [DOC] document spread-checks 2007-10-15 09:33:20 +02:00
Willy Tarreau
44ec0f003d [MINOR] spread checks also when the server is OK.
Initial patch only managed to spread the checks when the checks
failed. The randomization code needs to be added also in the path
where the server is going fine.
2007-10-15 09:33:17 +02:00
Willy Tarreau
2c43a1e2f0 [MEDIUM] only consider slow checks when looking for the common interval
When one server in one backend has a very low check interval, it imposes
its value as the minimal interval, causing all other servers to start
their checks close to each other, thus partially voiding the benefits of
the spread checks.

The solution consists in ignoring intervals lower than a given value
(SRV_CHK_INTER_THRES = 1000 ms) when computing the minimal interval,
and then assigning them a start date relative to their own interval
and not the global one.

With this change, the checks distribution clearly looks better.
2007-10-15 09:33:14 +02:00
Krzysztof Oledzki
b304dc7fd7 [MEDIUM] Spread health checks even more
When one server appears at the same position in multiple backends, it
receives all the checks from all the backends exactly at the same time
because the health-checks are only spread within a backend but not
globally.

Attached patch implements per-server start delay in a different way.
Checks are now spread globally - not locally to one backend. It also makes
them start faster - IMHO there is no need to add a 'server->inter' when
calculating first execution. Calculation were moved from cfgparse.c to
checks.c. There is a new function start_checks() and now it is not called
when haproxy is started in MODE_CHECK.

With this patch it is also possible to set a global 'spread-checks'
parameter. It takes a percentage value (1..50, probably something near
5..10 is a good idea) so haproxy adds or removes that many percent to the
original interval after each check. My test shows that with 18 backends,
54 servers total and 10000ms/5% it takes about 45m to mix them completely.

I decided to use rand/srand pseudo-random number generator. I am aware it
is not recommend for a good randomness but a) we do not need a good random
generator here b) it is probably the most portable one.
2007-10-15 09:33:10 +02:00
Alexandre Cassen
87ea548313 [MINOR] add the "nolinger" option to disable data lingering
The following patch will give the ability to tweak socket linger mode.
You can use this option with "option nolinger" inside fronted or backend
configuration declaration.

This will help in environments where lots of FIN_WAIT sockets are
encountered.
2007-10-15 09:33:06 +02:00
Krzysztof Oledzki
9198ab5e7c [MEDIUM] do not add a cache-control: header when on non-cacheable responses
I noticed that haproxy, with "cookie (...) nocache" option, always adds
"Cache-control: private" at the end of a header list received from this
server:

Cache-Control: no-cache
(...)
Set-Cookie: SERVERID=s6; path=/
Cache-control: private

or:

Set-Cookie: ASPSESSIONIDCSRCTSSB=HCCBGGACGBHDHMMKIOILPHNG; path=/
Cache-control: private
Set-Cookie: SERVERID=s5; path=/
Cache-control: private

It may be just redundant (two "Cache-control: private"), but sometimes it
may be quite confused as we may end with two different, more and less
restricted directions (no-cache & private) and even quite conflicting
directions (eg. public & private):

So, I added and rearranged a code, so now haproxy adds a "Cache-control:
private" header only when there is no the same (private) or more
restrictive (no-cache) one. It was done in three steps:

1. Use check_response_for_cacheability to check if response is
not cacheable. I simply moved this call before http_header_add_tail2.

2. Use TX_CACHEABLE (not TX_CACHE_COOK - apache <= 1.3.26) to check if we
need to add a Cache-control header. If we add it, clear TX_CACHEABLE and
TX_CACHE_COOK.

3. Check cacheability not only with PR_O_CHK_CACHE but also with
PR_O_COOK_NOC, so:

-                           unlikely(t->be->options & PR_O_CHK_CACHE))
+                           (t->be->options & (PR_O_CHK_CACHE|PR_O_COOK_NOC)))
                                txn->flags |= TX_CACHEABLE | TX_CACHE_COOK;

I removed this unlikely since I believe that now it is not so unlikely.

The patch is definitely not perfect, proxy should probably also remove
"Cache-control: public". Unfortunately, I do not know the code good enough
to do in myself, yet. ;)

Anyway, I think that even now, it should be very useful.
2007-10-15 09:33:02 +02:00
Krzysztof Oledzki
6b3f8b4b8f [MINOR] prevent the system from sending an RST when closing health-checks
On Sat, 22 Sep 2007, Willy Tarreau wrote:
> On Sun, Sep 23, 2007 at 03:23:38AM +0200, Krzysztof Oledzki wrote:
> > I noticed that with httpchk, haproxy generates TCP RST at end of a check.
> > IMHO, it would be more polite to send FIN to a server, especially that
> > each TCP RST found by a tcpdump makes me concerned that something is
> > wrong, as it is hard to distinguish between a RST from a httpchk and from
> > a normal request, forwarded for a client.
>
> I have also noticed it very recently. In fact, it's never the
> application (here haproxy) which decides to send an RST, it's the
> system. It does so because the server returns data on a terminated
> socket. I guess it's because the health-check code does not read much
> of the response. In fact, we just need to read enough to process common
> responses. If people are dumb enough to check with something like "GET
> /image.iso", they should expect to get an RST after a few kbytes
> instead of reading the whole file!

Right, that was easy. Attached patch changed what you described. Now
haproxy finishes http checks with FIN.
2007-10-15 09:32:58 +02:00
Krzysztof Oledzki
56f1e8b368 [BUG] fix double-free during clean exit
This patch fixes a nasty bug raported by both glibc and valgrind, which
leads into a problem that haproxy does not exit when a new instace
starts ap (-sf/-st).

==9299== Invalid free() / delete / delete[]
==9299==    at 0x401D095: free (in
/usr/lib/valgrind/x86-linux/vgpreload_memcheck.so)
==9299==    by 0x804A377: deinit (haproxy.c:721)
==9299==    by 0x804A883: main (haproxy.c:1014)
==9299==  Address 0x41859E0 is 0 bytes inside a block of size 21 free'd
==9299==    at 0x401D095: free (in
/usr/lib/valgrind/x86-linux/vgpreload_memcheck.so)
==9299==    by 0x804A84B: main (haproxy.c:985)
==9299==

6542  open("/dev/tty", O_RDWR|O_NONBLOCK|O_NOCTTY) = -1 ENOENT (No such file
or directory)
6542  writev(2, [{"*** glibc detected *** ", 23}, {"corrupted double-linked
list", 28}, {": 0x", 4}, {"6ff91878", 8}, {" ***\n", 5}], 5) = -1 EBADF (Bad
file descriptor)

I found this bug trying to find why, after one week with many restarts, I
finished with >100 haproxy process running. ;)
2007-10-15 09:32:54 +02:00
Willy Tarreau
d1eb3f0919 [TESTS] added a file to check that "retries" works. 2007-10-15 09:32:21 +02:00
Willy Tarreau
6e4261ee2f [MAJOR] timeouts and retries could be ignored when switching backend
When switching from a frontend to a backend, the "retries" parameter
was not kept, resulting in the impossibility to reconnect after the
first connection failure. This problem was reported and analyzed by
Krzysztof Oledzki.

While fixing the code, it appeared that some of the backend's timeouts
were not updated in the session when using "use_backend" or "default_backend".
It seems this had no impact but just in case, it's better to set them as
they should have been.
2007-10-15 09:32:19 +02:00
Willy Tarreau
33a89a2803 [DOC] added missing keywords from haproxy.vim
Pawel Golaszewski from pld-linux sent an update for the syntax highlight
in haproxy.vim.
2007-10-15 09:32:17 +02:00
Willy Tarreau
5fcc8f1ed9 [MINOR] fix the SIGHUP message not to alert on server-less proxies
The SIGHUP message was designed long before it was possible to have no
server in a proxy. Remove the alert in case there's no server.
2007-10-15 09:32:15 +02:00
Willy Tarreau
fdd0f5568a [MEDIUM] pre-initialize timeouts to infinity, not zero
Since the timers have been changed, the timeouts for the default instance
have not been adjusted. This results in unspecified timeouts becoming zero
instead of infinite.
2007-10-15 09:32:11 +02:00
Willy Tarreau
3d08953ce0 [MINOR] set the log socket receive window to zero bytes
The syslog UDP socket may receive data, which is not cool because those
data accumulate in the system buffers up to the receive socket buffer size.
To prevent this, we set the receive window to zero and try to shutdown(SHUT_RD)
the socket.
2007-10-15 09:32:07 +02:00
Willy Tarreau
193cf93ec0 [MEDIUM] fix configuration sanity checks for TCP listeners
A log chain of if/else prevented many sanity checks from being
performed on TCP listeners, resulting in dangerous configs being
accepted. Removed the offending 'else'.
2007-10-15 09:32:02 +02:00
Willy Tarreau
10806d50da [DOC] fixed 2 typos in haproxy-en/fr
-st was indicated instead of -sf, and the pidfile was wrong.
2007-09-09 23:49:18 +02:00
Willy Tarreau
ec69256382 [BUILD] centralize version and date into one file for each
The version does not appear anymore in the Makefiles nor in
the include files. It was a nightmare to maintain. Now there
is a VERSION file which contains the major version, a VERDATE
file which contains the date for this version and a SUBVERS
file which may contain a sub-version.

A "make version" target has been added to all makefiles to
check the version. The GNU Makefile also has an update-version
target to update those files. This should never be used.

It is still possible to override those values by specifying
them in the equivalent make variables. By default, the GNU
makefile tries to detect a GIT repository and always uses the
version and date from the current repository. This can be
disabled by setting IGNOREGIT to a non-void value.
2007-09-09 23:31:11 +02:00
Willy Tarreau
031a26b4a7 [DOC] added a small man page
Arnaud Cornet has started a small man page based on some information
gathered from the docs. I've completed it a bit.
2007-09-09 22:40:07 +02:00
Willy Tarreau
51041c737c [MAJOR] remove files distributed under an obscure license
src/chtbl.c, src/hashpjw.c and src/list.c are distributed under
an obscure license. While Aleks and I believe that this license
is OK for haproxy, other people think it is not compatible with
the GPL.

Whether it is or not is not the problem. The fact that it rises
a doubt is sufficient for this problem to be addressed. Arnaud
Cornet rewrote the unclear parts with clean GPLv2 and LGPL code.
The hash algorithm has changed too and the code has been slightly
simplified in the process. A lot of care has been taken in order
to respect the original API as much as possible, including the
LGPL for the exportable parts.

The new code has not been thoroughly tested but it looks OK now.
2007-09-09 21:56:53 +02:00
Willy Tarreau
ab28b8b9fd [TESTS] added a new hash algorithm
added "wt_hash" which shows only 60 collisions in 575k values, which
sets it between hashword() and djbx33(). It's also between both in
terms of performance, but the most important part is that its variable
length rotation mechanism should make it really harder to predict and
attack than the other ones.
2007-09-09 21:13:47 +02:00
Willy Tarreau
4eac209555 [MAJOR] spec I/O: fix allocations of spec entries for an FD
Under some circumstances, it was possible with speculative I/O to
reallocate multiple entries for the same FD if an fd_{set,clr,set}
or fd_{clr,set,clr} sequences were performed before a schedule.

Fix this by keeping a an allocation flag for each fd.
2007-09-09 21:09:29 +02:00
Willy Tarreau
e7150cdcfa [MEDIUM] stats page: added links for 'refresh' and 'hide down'
The stats page now supports an option to hide servers which are DOWN
and to enable/disable automatic refresh. It is also possible to ask
for an immediate refresh.
2007-09-09 21:09:29 +02:00
Willy Tarreau
dceaa0894b [MEDIUM] ensure we never overflow in chunk_printf()
The result of the vsnprintf() called in chunk_printf() must be checked,
and should be added only if lower than the requested size. We simply
return zero if we cannot write the chunk.
2007-09-09 21:09:28 +02:00
Willy Tarreau
ca769dc631 [TESTS] provide a test configuration file for stats and checks
A file with 1000 servers and a stats interface has been added.
2007-09-09 21:09:28 +02:00
Willy Tarreau
bbd42123e1 [MINOR] add support for "stats refresh <interval>"
Sometimes it may be desirable to automatically refresh the
stats page. Most browsers support the "Refresh:" header with
an interval in seconds. Specifying "stats refresh xxx" will
automatically add this header.
2007-09-09 21:09:28 +02:00
Willy Tarreau
24e779b71d [DOC] the "stats" keyword is not allowed in a pure frontend. 2007-09-09 21:09:28 +02:00
Willy Tarreau
6a06a40501 [DOC] started a new configuration manual
This new configuration manual intends to document every known keyword
of the configuration language. Right now, it enumerates them all and
describes how to use ACLs.
2007-09-09 21:09:28 +02:00
Willy Tarreau
4b946c8564 [MINOR] fix backend's weight in the stats page.
The GCD used when computing the servers' weights causes the total
weight of the backend to appear lower than expected because it is
divided by the GCD. Easy solution consists in recomputing the GCD
from the first server and apply it to the global weight.
2007-09-09 21:09:28 +02:00
Willy Tarreau
5af3a694f5 [MEDIUM] improve behaviour with large number of servers per proxy
When a very large number of servers is configured (thousands),
shutting down many of them at once could lead to large number
of calls to recalc_server_map() which already takes some time.
This would result in an O(N^3) computation time, leading to
noticeable pauses on slow embedded CPUs on test platforms.

Instead, mark the map as dirty and recalc it only when needed.
2007-09-09 21:09:28 +02:00
Willy Tarreau
632f5a7b6f [MEDIUM] fade out memory usage when stopping proxies
Now we try to free as many pools as possible when a proxy is stopping.
The reason is that we want to ease the process replacement when applying
a new configuration, without keeping too many unused memory allocated.
2007-07-11 10:42:35 +02:00