Uploaded image for project: 'logback'
  1. logback
  2. LOGBACK-1476

Avoid synchronized blocks when copying MDC to a function-local map

    XMLWordPrintable

Details

    • Icon: Improvement Improvement
    • Resolution: Unresolved
    • Icon: Major Major
    • 1.5.12
    • None
    • None
    • None

    Description

      When setting or duplicating the MDC context map, a synchronized map is used. This incurs the overhead of locking when putting key-value pairs into the map. This overhead can be avoided, because the map is method-local and only a single thread can access it a single time.

      Delay wrapping the map in a synchronizedMap until before it leaves the scope of the method.

      You can find the proposed changes in https://github.com/qos-ch/logback/pull/462

      I have not performed any benchmarks and would appreciate if somebody could write some. Maybe the JVM is already clever enough to detect this useless synchronization and elides the lock?

      Attachments

        Activity

          People

            logback-dev Logback dev list
            efdknittlfrank Daniel Knittl-Frank
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: