none
wcf performance issue RRS feed

  • Question

  • Hi,

    I am developing a web app using wcf. The app itself works fine but we are having performance issues. I have developed a demo solution that isolates the issue. The demo solution consists of three projects - Client, Serverhost, Service.

    The Serverhost has one cs file - Program.cs

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.ServiceModel;
    using Service;
    using System.ServiceModel.Channels;
    using System.ServiceModel.Description;
    
    namespace ServerHost
    {
        class Program
        {
            static void Main(string[] args)
            {
                try
                {
    
                    using (ServiceHost host = new ServiceHost(typeof(DeployerService), new Uri[] { }))
                    {
                        ServiceMetadataBehavior behavior = new ServiceMetadataBehavior();
                        host.Description.Behaviors.Add(behavior);
    
                        host.AddServiceEndpoint(typeof(IDeployerService), new CustomBinding("DeployerService"), "http://127.0.0.1:88/DeployerService.svc");
                        host.AddServiceEndpoint(typeof(IMetadataExchange), MetadataExchangeBindings.CreateMexHttpBinding(), "http://127.0.0.1:88/DeployerService/mex");
                        host.Open();
                        Console.WriteLine("Press <Enter> to terminate the Host application.");
                        Console.WriteLine();
                        Console.ReadLine();
                    }
                }
                catch (Exception ex)
                {
                    Console.Write(ex.ToString());
                    Console.WriteLine("Press <Enter> to terminate the Host application.");
                    Console.WriteLine();
                    Console.ReadLine();
                }
            }
        }
    }
    


    The app.config for the Serverhost looks like the following:

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <system.serviceModel>
        <services>
          <service behaviorConfiguration="DeploymentServer.DeployerServiceBehavior" name="DeploymentServer.DeployerService">
            <endpoint address="" binding="customBinding" bindingConfiguration="DeployerService" contract="ServiceContracts.DeploymentServer.IDeployerService">
            </endpoint>
            <host>
              <baseAddresses>
                <add baseAddress="http://127.0.0.1/" />
              </baseAddresses>
            </host>
          </service>
        </services>
        <bindings>
          <customBinding>
            <binding
              name="DeployerService"
              closeTimeout="00:00:30"
              openTimeout="00:00:30"
              receiveTimeout="00:00:30"
              sendTimeout="00:00:30">
              <mtomMessageEncoding
                messageVersion="Soap12"
                maxReadPoolSize="64"
                maxBufferSize="5242880"
                maxWritePoolSize="64">
                <readerQuotas
                  maxDepth="32"
                  maxStringContentLength="2147483647"
                  maxArrayLength="2147483647"
                  maxBytesPerRead="65535"
                  maxNameTableCharCount="2147483647"/>
              </mtomMessageEncoding>
              <httpTransport
                maxBufferPoolSize="524288"
                maxBufferSize="5242880"
                maxReceivedMessageSize="5242880"
                allowCookies="false"
                keepAliveEnabled="false"
                authenticationScheme="Anonymous"
              />
            </binding>
          </customBinding>
        </bindings>
        <behaviors>
          <serviceBehaviors>
            <behavior name="DeploymentServer.DeployerServiceBehavior">
              <dataContractSerializer maxItemsInObjectGraph="2147483647" />
              <serviceMetadata httpGetEnabled="true" />
              <serviceDebug includeExceptionDetailInFaults="true" />
              <serviceThrottling maxConcurrentCalls="256" maxConcurrentInstances="256" maxConcurrentSessions="256" />
            </behavior>
          </serviceBehaviors>
        </behaviors>
      </system.serviceModel>
    </configuration>
    




    The Serviceproject has two files, IDeployerService.cs and DeployerService.cs which implements the IDeployerService interface.
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.ServiceModel;
    using System.Threading;
    
    namespace Service
    {
        [ServiceBehavior(
            InstanceContextMode = InstanceContextMode.Single,
            ConcurrencyMode = ConcurrencyMode.Multiple
        )]
        public class DeployerService : IDeployerService
        {
            public int ProcessNext()
            {
                Thread.Sleep(25);
                return 5;
            }
        }
    }
    



    The Client project has a file program.cs
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Windows.Forms;
    
    namespace Client
    {
        static class Program
        {
            /// <summary>
            /// The main entry point for the application.
            /// </summary>
            [STAThread]
            static void Main()
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new Form1());
            }
        }
    }
    
    




    The Client also has a form form1.cs

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Diagnostics;
    using System.Threading;
    
    namespace Client
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                Performance.InitialisePerformanceCounters();
    
                for (int i = 0; i < 20; i++)
                {
                    Thread t = new Thread(ProcessNext);
                    t.Start();
                }
            }
    
    
            void ProcessNext()
            {
                DeployerServiceClient.DeployerServiceClient _client = new Client.DeployerServiceClient.DeployerServiceClient();
                while (true)
                {
                    int ret = _client.ProcessNext();
                    Performance.TotalSendRate.Increment();
                }
            }
        }
    }
    




    And a file Performance.cs

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Diagnostics;
    
    namespace Client
    {
        public class Performance
        {
            const string CAT_NAME = "WCFIssuesDemo";
            const string CALLS_RATE_NAME = "# calls / sec";
    
    
            public static void InitialisePerformanceCounters()
            {
                if (PerformanceCounterCategory.Exists(CAT_NAME))
                    PerformanceCounterCategory.Delete(CAT_NAME);
    
                if (!PerformanceCounterCategory.Exists(CAT_NAME))
                {
                    CounterCreationDataCollection counters = new CounterCreationDataCollection();
    
                    CounterCreationData sendRate = new CounterCreationData();
                    sendRate.CounterName = CALLS_RATE_NAME;
                    sendRate.CounterHelp = "";
                    sendRate.CounterType = PerformanceCounterType.RateOfCountsPerSecond32;
                    counters.Add(sendRate);
    
                    PerformanceCounterCategory.Create(
                        CAT_NAME,
                        "Performance Counters", PerformanceCounterCategoryType.MultiInstance, counters);
                }
            }
    
            static PerformanceCounter _totalSendRate = null;
            public static PerformanceCounter TotalSendRate
            {
                get
                {
                    if (_totalSendRate == null)
                    {
                        _totalSendRate = new PerformanceCounter();
                        _totalSendRate.CategoryName = CAT_NAME;
                        _totalSendRate.CounterName = CALLS_RATE_NAME;
                        _totalSendRate.InstanceName = "Total rate";
                        _totalSendRate.MachineName = ".";
                        _totalSendRate.ReadOnly = false;
                    }
                    return _totalSendRate;
                }
            }
    
            public static void Close()
            {
                TotalSendRate.Close();
            }
    
    
        }
    }
    
    
    



    And the app.config for the Client project looks like the following:

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <system.net>
        <connectionManagement>
          <add address="*" maxconnection="256" />
        </connectionManagement>
      </system.net>
      <system.serviceModel>
            <bindings>
                <customBinding>
                    <binding name="CustomBinding_IDeployerService">
                        <mtomMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16"
                            messageVersion="Soap12" maxBufferSize="65536" writeEncoding="utf-8">
                            <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                                maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                        </mtomMessageEncoding>
                        <httpTransport manualAddressing="false" maxBufferPoolSize="524288"
                            maxReceivedMessageSize="65536" allowCookies="false" authenticationScheme="Anonymous"
                            bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                            keepAliveEnabled="true" maxBufferSize="65536" proxyAuthenticationScheme="Anonymous"
                            realm="" transferMode="Buffered" unsafeConnectionNtlmAuthentication="false"
                            useDefaultWebProxy="true" />
                    </binding>
                </customBinding>
            </bindings>
            <client>
                <endpoint address="http://127.0.0.1:88/DeployerService.svc" binding="customBinding"
                    bindingConfiguration="CustomBinding_IDeployerService" contract="DeployerServiceClient.IDeployerService"
                    name="CustomBinding_IDeployerService" />
            </client>
        </system.serviceModel>
    </configuration>
    

     
    When using the performance counter with "Reliability and Performance Monitor" the graph dips from 600 to zero after a very short period of time. The trouble shooting indicates that is a configuration issue but we have not been able to solve it. Can you please help?

    Kind Regards
    Cecilia
    Sunday, June 28, 2009 11:42 PM

Answers

  • The issue proved to be caused by Win Vista. When running on XP or Win Server 2008 the performance is fine.

    Regards
    Cecilia
    • Marked as answer by Goldielocks Wednesday, July 1, 2009 1:33 AM
    Wednesday, July 1, 2009 1:33 AM