-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace synchronized
blocks with locks for performance in virtual threads
#1532
Comments
This – replacing |
There is no such "kill-switch" anymore (in 21). So, I guess that is one problem solved :) |
synchronized
blocks with locks for performance in virtual threads
@kelemen, thanks for tip! I have updated LOG4J2-3622 with the information you shared, and closed it. It is good to keep this ticket around for the |
This updates most of the uses of `synchronized` to instead use explicit locks and conditions. This is to make lock-related code more performant when used with virtual threads. Relates to #1532 and LOG4J2-3622.
I've updated most of the usages (at least in API and Core). There's a little bit left to do to migrate the rest, but this is largely complete. |
Hey guys I have been working on my own SLF4J adapter that is for Java 21. I was benchmarking against log4j2 and logback noticed when I load up like 10,000 vthreads log4j2 crushes in these scenarios (about half the time) and appears because it pins the threads and thus a single writer scenario happens (which is fast). I made sure this was the case as I disabled ThreadLocals and set garbage collection to epsilon etc (e.g. no gc). However the benchmark is flawed because:
The code seems to be in synchronized (this) {
ByteBufferDestinationHelper.writeToUnsynchronized(data, this);
} As soon as I did similar my library performed similar to log4j2. I'm just letting you know because there maybe some that actually want the above behavior (e.g. pinning the thread)! I'm trying to decide how to construct a more realistic test of virtual threads hitting other IO like a database and then logging to how bad |
Yeah, you can see that updated in 9d102de#diff-734786443edbd8c3b84ca999ecbf69a160ce730ac68eaedbf5f593955242142b where Pinning a thread for log output is one of the exact use cases for using asynchronous loggers so that appenders get pinned to that async thread. |
Log4j
usesmight be usingsynchronized
blocks on certain hot paths, e.g.,RollingFileManager
. This might cause performance degradation when such code runs in a virtual thread, sincesynchronized
blocks pin the carrier thread and undermine the whole non-blocking nature promised by virtual threads. To avoid this one can replacesynchronized
blocks with atomic components, locks, etc.This ticket aims to find such
synchronized
usages and replace them with more virtual-thread-friendly constructs.The text was updated successfully, but these errors were encountered: