Policy injection with unity in WCF cause high memory usage

Topics: Logging Application Block, Policy Injection Application Block
Dec 11, 2009 at 5:51 AM

Hi,

   I have a WCF that return data from MSSQL server. The WCF is configure to log any exception happens inside WCF into a file using Logging Application Block, and the exception is handle by PolicyInjection.CallHandlers.ExceptionHandler. During our stress test on the WCF (no exception happen), the memory keep pile up on  TextFormatter object of Logging Application (consume > 30% of the total WCF memory)

Attached is the configuration on WCF, anyone can explain why the textformatter object consume so high percentage of memory and yet there is no exception happen ?

<!--l version="1.0" encoding="utf-8-->
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
    <section name="exceptionHandling" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration.ExceptionHandlingSettings, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
    <section name="unity" type="Microsoft.Practices.Unity.Configuration.UnityConfigurationSection, Microsoft.Practices.Unity.Configuration, Version=1.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
  </configSections>
  <loggingConfiguration name="Logging Application Block" tracingEnabled="true"
    defaultCategory="General" logWarningsWhenNoCategoriesMatch="true">
    <listeners>
      <add fileName="logs\\Ice.ProductManagement.Service\\Exception.log"
        footer="----------------------------------------" formatter="Text Formatter Exception"
        header="----------------------------------------" rollFileExistsBehavior="Overwrite"
        rollInterval="None" rollSizeKB="0" timeStampPattern="yyyy-MM-dd"
        listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        traceOutputOptions="None" filter="All" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        name="Rolling Flat File Trace Listener Exception" />
    </listeners>
    <formatters>
      <add template="Timestamp: {timestamp(local)}&#xD;&#xA;Message: {message} - {dictionary({key} - {value})}&#xD;&#xA;Extended Properties: {dictionary({key} - {value})}&#xD;&#xA;Category: {category}&#xD;&#xA;Priority: {priority}&#xD;&#xA;EventId: {eventid}&#xD;&#xA;Severity: {severity}&#xD;&#xA;Title:{title}"
        type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        name="Text Formatter Exception" />
    </formatters>
    <categorySources>
      <add switchValue="All" name="Exception">
        <listeners>
          <add name="Rolling Flat File Trace Listener Exception" />
        </listeners>
      </add>
    </categorySources>
    <specialSources>
      <allEvents switchValue="All" name="All Events" />
      <notProcessed switchValue="All" name="Unprocessed Category" />
      <errors switchValue="All" name="Logging Errors &amp; Warnings">
        <listeners>
          <add name="Formatted EventLog TraceListener" />
        </listeners>
      </errors>
    </specialSources>
  </loggingConfiguration>
  <exceptionHandling>
    <exceptionPolicies>
      <add name="Log Only Policy">
        <exceptionTypes>
          <add type="System.Exception, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
            postHandlingAction="NotifyRethrow" name="Exception">
            <exceptionHandlers>
              <add logCategory="Exception" eventId="100" severity="Error" title="Enterprise Library Exception Handling"
                formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                priority="0" useDefaultLogger="false" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                name="Exception With Logging Handler" />
            </exceptionHandlers>
          </add>
        </exceptionTypes>
      </add>
    </exceptionPolicies>
  </exceptionHandling>
  <services name="IceProductManagementService">
    <service name="ProductService">
      <serviceType name="Ice.ProductManagement.Components.Service.ProductService" assembly="Ice.ProductManagement.Components, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
    </service>
  </services>
  <unity>
    <typeAliases>
      <typeAlias alias="string" type="System.String, mscorlib" />
      <typeAlias alias="bool" type="System.Boolean, mscorlib" />
      <typeAlias alias="int" type="System.Int32, mscorlib" />
      <typeAlias alias="TraceEventType" type="System.Diagnostics.TraceEventType, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
      <typeAlias alias="GenericList(string)" type="System.Collections.Generic.List`1[[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
    </typeAliases>
    <containers>
      <container name="UnityPolicy">
        <extensions>
          <add type="Microsoft.Practices.Unity.InterceptionExtension.Interception, Microsoft.Practices.Unity.Interception" />
        </extensions>
        <extensionConfig>
          <add name="interception" type="Microsoft.Practices.Unity.InterceptionExtension.Configuration.InterceptionConfigurationElement, Microsoft.Practices.Unity.Interception.Configuration">
            <policies>
              <policy name="ExceptionPolicy">
                <matchingRules>
                  <matchingRule type="Ice.Common.MatchingRule.MemberNameMatchingRule, Ice.Common" name="Member Name Matching Rule Exception Policy">
                    <injection>
                      <constructor>
                        <param name="namesToMatch" parameterType="string">
                          <value value="*" type="string" />
                        </param>
                        <param name="ignoreCase" parameterType="bool">
                          <value value="false" type="bool" />
                        </param>
                      </constructor>
                    </injection>
                  </matchingRule>
                </matchingRules>
                <callHandlers>
                  <callHandler type="Microsoft.Practices.EnterpriseLibrary.PolicyInjection.CallHandlers.ExceptionCallHandler, Microsoft.Practices.EnterpriseLibrary.PolicyInjection.CallHandlers, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="Exception Handler">
                    <injection>
                      <constructor>
                        <param name="exceptionPolicyName" parameterType="string">
                          <value value="Log Only Policy" type="string" />
                        </param>
                      </constructor>
                      <property name="Order" propertyType="int">
                        <value value="0" type="int" />
                      </property>
                    </injection>
                  </callHandler>
                </callHandlers>
              </policy>
            </policies>
          </add>
        </extensionConfig>
      </container>
    </containers>
  </unity>
  <system.serviceModel>
    <extensions>
      <behaviorExtensions>
        <add name="PolicyEndPointBehavior" type="IvisGroupKL.Common.InjectionHelper.PolicyInjectionBehavior.PolicyInjectionEndpointBehavior, IvisGroupKL.Common.InjectionHelper, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
      </behaviorExtensions>
    </extensions>
    <behaviors>
      <endpointBehaviors>
        <behavior name="PolicyInjectionEndPointBehavior">
          <PolicyEndPointBehavior />
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="Ice.ProductManagement.Components.ProductService.Behaviours">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <bindings>
      <wsHttpBinding>
        <binding name="wsHttpNormalBinding" maxReceivedMessageSize="5000000">
          <security mode="Message">
            <message clientCredentialType="Windows" negotiateServiceCredential="true" algorithmSuite="Default" establishSecurityContext="true" />
          </security>
        </binding>
      </wsHttpBinding>
    </bindings>
    <services>
      <service behaviorConfiguration="Ice.ProductManagement.Components.ProductService.Behaviours" name="Ice.ProductManagement.Components.Service.ProductService">
        <endpoint address="" behaviorConfiguration="PolicyInjectionEndPointBehavior" binding="wsHttpBinding" bindingConfiguration="wsHttpNormalBinding" contract="Ice.ProductManagement.Components.ServiceContracts.IProductService" />
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <endpoint binding="wsHttpBinding" bindingConfiguration="wsHttpNormalBinding" contract="Ice.Common.Framework.Integration.ServiceContracts.IIntegrationServiceSubscriber" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8080/Ice.ProductManagement.Service" />
          </baseAddresses>
        </host>
      </service>
    </services>
  </system.serviceModel>
</configuration>
<param name="namesToMatch" /> <param name="ignoreCase" /> <param name="exceptionPolicyName" />
Dec 14, 2009 at 7:38 AM

Hi,

Have you tried not associating a Text Formatter to your rolling flat file?

Valiant Dudan
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com