Skip to content
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

3399/create logger no lock #3427

Open
wants to merge 2 commits into
base: 2.24.x
Choose a base branch
from

Conversation

tristantarrant
Copy link

@tristantarrant tristantarrant commented Jan 31, 2025

This PR includes and supersedes #3418
It fixes the issue of dangling WeakReferences, which are not being replaced causing excessive write lock acquisition by introducing a (very limited) WeakValuesHashMap to store the name -> logger mappings.

I've tested this successfully with Infinispan's core testsuite.

I've kept @ppkarwasz 's original commit and mine separate, but they should really be squashed together.

Closes #3399

ppkarwasz and others added 2 commits January 31, 2025 08:05
It has been reported that holding a lock on `InternalLoggerRegistry` during the creation of a logger can cause performance loss and deadlocks. The logger constructor can trigger property lookups and other pluggable operations, we don't entirely control. The fix to apache#3252 only covered one of these cases.

This change moves the instantiation of new `Logger`s outside the write lock. While in some cases, this will cause multiple instantiations of loggers with the same parameters, all such loggers are functionally equivalent. On the other hand, the change allows the creation of different loggers in parallel.

Closes apache#3399
@tristantarrant
Copy link
Author

Some additional info: here are the timings for running Infinispan's core testsuite on my laptop:

  • Log4j 2.23.1: 5m50s
  • Log4j 2.24.4-SNAPSHOT including this PR: 5m45s

Any difference is just attributable to noise.

@SuppressWarnings("unchecked")
private void processQueue() {
for (WeakValue<V> v = (WeakValue<V>) queue.poll(); v != null; v = (WeakValue<V>) queue.poll()) {
map.remove(v.getKey());
Copy link
Member

@vy vy Jan 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tristantarrant, methods accessed while holding a read-lock (e.g., getLogger()) might end up mutating the map, which is not thread-safe. Am I mistaken?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants