Logs: a thread and a queue for each log; build-time defaults

Once 3proxy runs (after the first configuration is in force, so after a
daemon's fork), each logger has a thread of its own writing from a
queue, and a client never waits for a log: ODBC, RADIUS, a full disk or
a pipe nobody reads hold up only that log's thread.

A queued line is fixed size: the part of struct clientparam logging
reads (everything before the filters: addresses, counters, names and
credentials, which hold no pointer it follows but srv), the time it was
logged, and its text, 256 bytes inline or a copy of its own if longer.
The thread formats it: struct tm is per call now, timechanged() and
dologname() included, and the type's format() takes the time.

minlogqueue (64) slots are allocated as the thread starts and kept,
maxlogqueue (4096) lines are queued at most. A line which finds the
queue full is dropped and counted on the last one queued; once that is
written, "Log X has its queue full, N records dropped" goes to where
errors go. A log which fails is no longer written to the error log
instead: its lines are dropped and counted while it is retried every
minute, and the count is told when it is open again, or when it was
reopened after failed writes.

A service which ended is stopped at once (srvstop(): sockets, listener,
its clients gone), but freed (srvrelease()) through its log's queue,
behind the lines which refer to it and to its configuration: the event
is part of struct srvparam, so a full queue never drops it. logfinish()
writes what is queued, 10 seconds at most, also as 3proxy exits on Unix.
Standalone services write as before, as each line comes.

LOGQUEUEMIN, LOGQUEUEMAX, DEFAULT_MAXCHILD, DEFAULT_POOLMAX,
DEFAULT_POOLTIMEOUT and POOLPERSERVICE (the automatic thread pool cap
for each service, which was 32 in the code) can be set with -D at build
time.

Tests: a log nobody reads (a FIFO) holds no client up, drops past its
queue and says so, and lines queued for a service a reload removed are
written as it formatted them; /dev/full says what it dropped.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Vladimir DubrovinandClaude Opus 5.5 committed 2026-10-23 19:41:48 +03:00
1 parent a3c417c82a
commit 2052dc0a4f
13 files changed
+930 -158

No files matched your search

+19
View File
@@ -34,7 +34,22 @@
#define MAXUSERNAME 128
#define _PASSWORD_LEN 256
/* Defaults, -D at build time sets others: maxconn; threadpool, the idle
workers kept (-1 automatic: POOLPERSERVICE for each service, no more than
their maxconn together) and how long one waits, in seconds. Each idle
worker keeps its thread and its struct clientparam. */
#ifndef DEFAULT_MAXCHILD
#define DEFAULT_MAXCHILD 500
#endif
#ifndef DEFAULT_POOLMAX
#define DEFAULT_POOLMAX -1
#endif
#ifndef DEFAULT_POOLTIMEOUT
#define DEFAULT_POOLTIMEOUT 60
#endif
#ifndef POOLPERSERVICE
#define POOLPERSERVICE 32
#endif
/* How much of a connection's buffer is read into at once: all of it, or
less if the service was told so with -b. */
@@ -342,6 +357,7 @@ void dolog(struct clientparam * param, const unsigned char *s);
int dobuf(struct clientparam * param, unsigned char * buf, const unsigned char *s, const unsigned char * doublec);
int dobuf2(struct clientparam * param, unsigned char * buf, const unsigned char *s, const unsigned char * doublec, struct tm* tm, char * format);
int logbuf(struct clientparam * param, unsigned char * buf, const unsigned char *s, const unsigned char * doublec);
int logbuft(struct clientparam * param, unsigned char * buf, const unsigned char *s, const unsigned char * doublec, time_t sec, unsigned msec);
void logdo(struct clientparam * param, const unsigned char *s);
void logerror(const unsigned char *s);
void loginit(void);
@@ -355,6 +371,7 @@ void logstdclose(void);
size_t logselen(const unsigned char *selector);
void logtick(time_t t);
void logfinish(void);
void logcall(struct logger *lg, struct logevent *ev, void (*func)(void *), void *arg);
int timechanged (time_t oldtime, time_t newtime, ROTATION lt);
extern struct logger lognull;
#ifdef WITH_ODBC
@@ -500,6 +517,8 @@ FILTER_ACTION handledatfltsrv(struct clientparam *param, unsigned char ** buf_p,
void srvinit(struct srvparam * srv, struct clientparam *param);
void srvinit2(struct srvparam * srv, struct clientparam *param);
void srvfree(struct srvparam * srv);
void srvstop(struct srvparam * srv);
void srvrelease(struct srvparam * srv);
unsigned char * dologname (unsigned char *buf, unsigned char *name, const unsigned char *ext, ROTATION lt, time_t t);
int readconfig(FILE * fp);
void initcommands(void);