Hi everyone,
let's say we have 20 different java applications/services running in an application server (Tomcat, etc.).
Each application has it's own valid log configuration, stored in a collective, single tinylog configuration file, which is used for the logging configuration of all applications, e.g.
tinylog.properties
writerSERVICE1 = rolling file
writerSERVICE1.tag = SERVICE1
writerSERVICE1.format = {date:yyyy-MM-dd HH:mm:ss.SSSZ} | {class-name} | {message}
writerSERVICE1.level = info
writerSERVICE1.file = /some/logpath/service1.{date:yyyyMMdd}.{count}.log
writerSERVICE1.policies = daily, size: 10mb
writerSERVICE1.backups = 5
writerSERVICE2 = rolling file
writerSERVICE2.tag = SERVICE2
writerSERVICE2.format = {date:yyyy-MM-dd HH:mm:ss.SSSZ} | {class-name} | {message}
writerSERVICE2.level = info
writerSERVICE2.file = /some/logpath/service2.{date:yyyyMMdd}.{count}.log
writerSERVICE2.policies = daily, size: 10mb
writerSERVICE2.backups = 5
[...]
writerSERVICE20 = rolling file
writerSERVICE20.tag = SERVICE20
writerSERVICE20.format = {date:yyyy-MM-dd HH:mm:ss.SSSZ} | {class-name} | {message}
writerSERVICE20.level = info
writerSERVICE20.file = /some/logpath/service20.{date:yyyyMMdd}.{count}.log
writerSERVICE20.policies = daily, size: 10mb
writerSERVICE20.backups = 5
Applications are mainly using their own Tag for logging, for example SERVICE1 uses the following code to log messages to its designated logfile:
Service1Impl.java
public static final TaggedLogger SERVICE1_LOGGER = Logger.tag("SERVICE1");
//[...]
SERVICE1_LOGGER1.info("Some Info");
SERVICE1_LOGGER1.error("Some error");
Applications are running fine with this configuration in the application server and whenever each Service is called, each logging message is stored in its own logfile, as intended.
Open file descriptors:
However when inspecting the open file descriptors under a Linux System, f.e. with the command
lsof -a -p APPLICATION_SERVER_PID | grep service1 | grep .log
what you see is up to 20 different open file descriptors for the same logfile.
It looks like file descriptors are opened by each service (20) for each tag (20), regardless if the tag is used or not.
So if each service already logged an initial message with the configuration above (in tinylog.properties), we can see up to 400 (20x20) open file descriptors, eventhough each service really only used its own Logging Tag for logging purposes.
There might be a possibility this introduces problems (Exceptions - Too many open files), because of a default maximum open files per process limit under linux. One can inspect that limit with the linux command:
ulimit -a
[...]
open files (-n) 1024
Is there a way, so that the file descriptors are opened only when they are really used ?
My first idea would be to either
- raise the maximum open file per process limit (this requires a manual operation from the system administrator)
- to split up the configuration file (tinylog.properties), so each service has its own configuration file, only with that logging tag configuration. (The latter might solve the file descriptor problem but introduces new problems ...)
In my opinion, a single configuration file seems much easier to handle than 20 different files. Also since tinylog 2.4 #201 it's possible to create a tagged logger with multiple tags that issues each log entry to all defined tags. So with multiple configuration files, you would have to configure a tag used by multiple services again and again, in multiple different files, ugh...
Do you have any other ideas ? Is there a way, so that file descriptors are only created f.e. the first time they are used ?
Thanks in Advance !!
question