refactor: improve service process output reading
Motivation
Currently service process output streams are read once per second on a single shared thread. This causes issues with delayed logs, especially when the JVM crashes at startup as 99% of the times the JVM crash reason wasn't read from the process error stream. This leaves users with nearly undiagnosable startup issues.
Example log output with an invalid JVM flag before the change:
4.0.0-RC11-SNAPSHOT-f66323ca => create by Proxy 1 --start
[26.08 09:26:50.417] INFO : Starting to create 1 services for Proxy
[26.08 09:26:50.641] INFO : CloudService [uniqueId=04789662-d056-48ba-975a-f69993ed56dd task=Proxy name=Proxy-1] has been started
[26.08 09:26:50.642] INFO : The services were created based on the task. They can be managed with the service command
[26.08 09:26:50.703] INFO : CloudService [uniqueId=04789662-d056-48ba-975a-f69993ed56dd task=Proxy name=Proxy-1] has been stopped
Modification
Now the log cache uses virtual threads to read the process output streams. This is very efficient as the whole process stream reading is based on I/O operations which means that the virtual thread can be unmounted until some data is available to be read. This means that even with starting 2 virtual threads per service, there shouldn't be any noticeable performance impacts on the node at all.
Additionally, empty log lines are now ignored in the parent log cache class and there is no need anymore for log caches to implement the handling themselfes. Also a small issue with caching was fixed that caused the cache to still contain 1 item even if the log cache entry limit was set to 0.
Result
Log output of services is not read immediately once data is available from the input or output stream, making the output more responsive (as it is nearly immediately printed) and also catches everything that is being logged.
Example log output with an invalid JVM flag & this change applied:
4.0.0-RC11-SNAPSHOT-b99d7fbc => create by Proxy 1 --start
[26.08 09:21:59.245] INFO : Starting to create 1 services for Proxy
[26.08 09:21:59.289] INFO : CloudService [uniqueId=3a718134-d248-41d4-9f40-75751e1c1d64 task=Proxy name=Proxy-1] has been started
[26.08 09:21:59.289] INFO : The services were created based on the task. They can be managed with the service command
[26.08 09:21:59.295] WARN : [Proxy-1/WARN]: Unrecognized option: -XIReallyKnowWhatIAmDoingISwear
[26.08 09:21:59.296] WARN : [Proxy-1/WARN]: Error: Could not create the Java Virtual Machine.
[26.08 09:21:59.296] WARN : [Proxy-1/WARN]: Error: A fatal exception has occurred. Program will exit.
[26.08 09:22:00.303] INFO : CloudService [uniqueId=3a718134-d248-41d4-9f40-75751e1c1d64 task=Proxy name=Proxy-1] has been stopped
Test Results
48 files ±0 48 suites ±0 1m 57s :stopwatch: +14s 420 tests ±0 420 :white_check_mark: ±0 0 :zzz: ±0 0 :x: ±0 751 runs ±0 751 :white_check_mark: ±0 0 :zzz: ±0 0 :x: ±0
Results for commit 3a4543fe. ± Comparison against base commit f66323ca.