2010-06-20 91 views
2

我有一個WCF服務,我正在分析其內存分配。
我看到36%對每個請求分配內存的,通過TimerCallBack.PerformTimerCallback,進而調用以下分配:
ExecutionContext.CreateCopy
ExecutionContext.Run
所有這些配置甚至不通過我的代碼,只分配像Hahtable.bucket和ExecutionContextRunData的通用對象。TimerCallback.PerformTimerCallback內存分配

我在我的服務中使用了一個計時器,因爲我用一個簡單的回調函數爲每個請求創建了一個更新布爾值的對象,並在之後立即處理它。它可能是相關的嗎?

這裏的相關分配圖:

<root> : 41 MB (100.00%) 
System.Threading._TimerCallback::PerformTimerCallback static void (Object): 41 MB (100.00%) 
    System.Threading.ExecutionContext::CreateCopy System.Threading.ExecutionContext(): 30 MB (73.96%) 
    System.Threading.ExecutionContext::Run static void (System.Threading.ExecutionContext System.Threading.ContextCallback Object): 11 MB (26.04%) 
    System.Threading.ExecutionContext::RunInternal static void (System.Threading.ExecutionContext System.Threading.ContextCallback Object): 7.8 MB (19.18%) 
    System.Data.ProviderBase.DbConnectionFactory::PruneConnectionPoolGroups void (Object): 2.6 MB (6.42%) 
    System.Data.ProviderBase.DbConnectionPool::CleanupCallback void (Object): 183 kB (0.44%) 
    System.Data.ProviderBase.DbConnectionPoolGroup::ClearInternal bool (bool): 1.2 MB (3.06%) 
    System.Collections.Generic.Dictionary<T,U>::.ctor void (int32): 840 kB (2.02%) 
    System.Threading.ThreadPool::QueueUserWorkItem static bool (System.Threading.WaitCallback): 183 kB (0.44%) 
    System.Collections.Generic.Dictionary<T,U>::.ctor void (int32 <UNKNOWN>): 840 kB (2.02%) 
    System.Collections.Specialized.HybridDictionary::Add void (Object Object): 305 kB (0.73%) 
    System.Collections.Specialized.HybridDictionary::GetEnumerator void(): 255 kB (0.61%) 
    System.Collections.Specialized.ListDictionary::Add void (Object Object): 255 kB (0.61%) 
    System.Collections.Specialized.ListDictionary.NodeEnumerator::get_Current Object(): 204 kB (0.49%) 
    System.Threading.ThreadPool::QueueUserWorkItemHelper static bool (System.Threading.WaitCallback Object System.Threading.StackCrawlMark& bool): 183 kB (0.44%) 
     System.Collections.Generic.Dictionary<T,U>::Initialize void (int32): 840 kB (2.02%) 
     System.Threading._ThreadPoolWaitCallback::.ctor void (System.Threading.WaitCallback Object bool System.Threading.StackCrawlMark&): 135 kB (0.32%) 
     System.Threading.ExecutionContext::Capture static System.Threading.ExecutionContext (System.Threading.StackCrawlMark&): 135 kB (0.32%) 
     System.Runtime.Remoting.Messaging.LogicalCallContext::Clone Object(): 26 MB (63.75%) 
     System.Collections.Hashtable::.ctor void (int32 float32): 15 MB (36.34%) 
     System.Collections.Hashtable::GetEnumerator System.Collections.IDictionaryEnumerator(): 2.9 MB (7.07%) 
      System.Collections.Hashtable.bucket [] : 15 MB (36.34%) 
      System.Threading.ExecutionContext.ExecutionContextRunData : 7.8 MB (19.18%) 
      System.Collections.Hashtable : 4.5 MB (11.10%) 
      System.Threading.ExecutionContext : 4.3 MB (10.53%) 
      System.Runtime.Remoting.Messaging.LogicalCallContext : 3.8 MB (9.24%) 
      System.Collections.Hashtable.HashtableEnumerator : 2.9 MB (7.07%) 
      System.Collections.Generic.Dictionary<T,U>.Entry [] : 611 kB (1.47%) 
      System.Collections.Generic.Dictionary<T,U> : 560 kB (1.34%) 
      System.Collections.Specialized.ListDictionary : 305 kB (0.73%) 
      System.Collections.Specialized.ListDictionary.NodeEnumerator : 255 kB (0.61%) 
      System.Collections.Specialized.ListDictionary.DictionaryNode : 255 kB (0.61%) 
      System.Collections.Specialized.HybridDictionary : 255 kB (0.61%) 
      System.Int32 [] : 229 kB (0.55%) 
      System.Collections.DictionaryEntry : 204 kB (0.49%) 
      System.Threading._ThreadPoolWaitCallback : 48 kB (0.12%) 
      <bottom> : 41 MB (100.00%) 

何處來自所有這些分配?這是正常的嗎?
有沒有辦法降低一些?

+0

您是否使用計時器?什麼樣的實例模型,InstancePerCall? – 2010-06-20 10:58:37

+0

我確實使用了Timer和InstancePerCall模型。 – 2010-06-20 12:11:02

+0

我還必須補充說,我的Timer的回調只會更新一個標誌來檢測超時。 – 2010-06-20 12:29:33

回答

0

爲了完整起見,問題是有人將MaxBufferSize和MaxBufferPoolSize值更改爲其先前值的1,000倍。