0

The question is about the access and error logs, particularly with multiple hosts (apache instances installed on more than one server) and keeping the logs centrally on a network file system.

Does apache close each log file after every write?

If yes, on a busy server hosting many sites each with it's own log, that would seem to be a potential performance bottleneck?

If No, what is the solution when having multiple servers writing to a single logging location on a network file system?

1
  • 2
    What is the problem you are having? Commented Aug 30, 2021 at 15:53

2 Answers 2

1

Does apache close each log file after every write?

Use the source, it is at: https://svn.apache.org/viewvc/httpd/httpd/branches/2.4.x/modules/loggers/mod_log_config.c?view=markup

You can read from it:

251 * log_writer is NULL before the log file is opened and is 252 * set to a opaque structure (usually a fd) after it is opened. 

That kind of hints that it is open only once. In fact if you look at the code, it is open early, at initialization, and then never closed, for obvious performance reasons.

If No, what is the solution when having multiple servers writing to a single logging location on a network file system?

Absolutely never do that, for two reasons. First do not log remotely that way. Log locally (and ship logfiles separately, you can rotate hourly for example) or use the appropriate daemons, syslog knows by default how to ship log content by UDP (or TCP), as do newer solutions. Don't mount a remote disk and write logfiles to it, that will kill performance and create a whole bunch of problems (especially if you mean remote as in "NFS").

And even if locally, each application should log to its own logfile, don't have multiple applications logging to the same file, this is bound to create all kind of race conditions, overwrite, etc. Apache itself is one application even if it forks, but if you had 2 Apache running separately on the same host with different configurations, they should each log to their own logfiles.

Or look at Apache feature to log to pipes, but this has drawbacks too.

0

AFAIK you cannot have multiple Apache web servers concurrently write to the same log file.

For clusters you either let every node write to its own log file and then you do some post processing to merge them, or you let Apache generate syslog events, send those to a central syslog server where you can merge them into a single file or you use a log aggregation solution like ELK Stack, Graylog, Splunk and/or others to ship log events from all cluster nodes to a single big data database

1
  • I expected this to be the answer. So I tested it with 4 instances of apache running in 4 containers and all writing to the same log. I started up a "load" test with bunches of processes requesting a page and let it run for an hour, and it worked fine. I fully expected only one instance to be able to write to the log, so I don't know what to make from it. Commented Aug 31, 2021 at 6:16

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.