Log4net
  1. Log4net
  2. LOG4NET-148

ThreadContext uses LocalDataStore to store ThreadSpecific data instead should be using [ThreadStatic] variables.

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: 1.2.9, 1.2.10
    • Fix Version/s: 1.2.12
    • Component/s: Core
    • Labels:
      None
    • Environment:
      .Net Framework

      Description

      According to this article (http://blogs.msdn.com/junfeng/archive/2005/12/31/508423.aspx) and production issues encountered: using LocalDataStore is not a scalable approach for any web server that gets a significant amount of traffic.

      The ThreadContext object should be modified to use [ThreadStatic] variables.

      From the article:
      The Whidbey RTM implementation of Thread.GetData/Thread.SetData has several scalability issues caused by global locks being taken. The appdomain-global lock taken in LocalDataStore.SetData is one of them. There is another global lock taken in ThreadNative::GetDomainLocalStore that is even worse since it is process-global.

      The best workaround is to use [ThreadStatic] variables instead of Thread.GetData/Thread.SetData

        Activity

        Hide
        Simon Svensson added a comment - - edited

        It may also create a memory leak in .NET Framework 4.

        "After an application calls the Thread.AllocateDataSlot method to allocate a data slot in the Microsoft .NET Framework 4, the memory usage and the CPU usage keep increasing. When debug information is generated, the debug information indicates that a large number of the System.LocalDataStoreElement types occupy memory."
        Source: http://support.microsoft.com/kb/2540745

        Show
        Simon Svensson added a comment - - edited It may also create a memory leak in .NET Framework 4. "After an application calls the Thread.AllocateDataSlot method to allocate a data slot in the Microsoft .NET Framework 4, the memory usage and the CPU usage keep increasing. When debug information is generated, the debug information indicates that a large number of the System.LocalDataStoreElement types occupy memory." Source: http://support.microsoft.com/kb/2540745
        Hide
        Ron Grabowski added a comment -

        [ThreadStatic]
        private static PropertiesDictionary _dictionary;

        Show
        Ron Grabowski added a comment - [ThreadStatic] private static PropertiesDictionary _dictionary;
        Hide
        Ron Grabowski added a comment -

        Is the attached file what everyone had in mind?

        Show
        Ron Grabowski added a comment - Is the attached file what everyone had in mind?
        Hide
        Simon Svensson added a comment -

        Yes, it seems correct, except for some indenting issues.

        Show
        Simon Svensson added a comment - Yes, it seems correct, except for some indenting issues.
        Hide
        Dominik Psenner added a comment -

        Applied patch and fixed build errors as of revision: 1489904

        Show
        Dominik Psenner added a comment - Applied patch and fixed build errors as of revision: 1489904

          People

          • Assignee:
            Dominik Psenner
            Reporter:
            Hernando Torres-Rocca
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development