Ask a questionAsk a question
 

QuestionStill about slow initialization time in WCF

  • Tuesday, March 25, 2008 11:35 AMLuis Miguel AbreuMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

     

    A few days ago I was having problems with client WCF initialization time. I though I had solved the problem by removing the automatic proxy detection option but it seems like there are still some computers where the 1st call takes way to much time (and in those cases, the proxy configuration options are ok). So, I've profiled the application and I've noticed that it takes most of the time on the RealProxy.PrivateInvoke method:

     

    42,92% Authenticate - 8113 ms - 1 call - Mercados.WinForms.Security.MercadosUserManager.Authenticate(String, String)   (from Mercados.WinForms.Security.IUserManager)
      18,39% PrivateInvoke - 3477 ms - 1 call - System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData &, Int32)
      13,80% ChannelFactory<TChannel>..ctor - 2608 ms - 1 call - System.ServiceModel.ChannelFactory<TChannel>..ctor(String)
      10,19% CreateChannel - 1926 ms - 1 call - System.ServiceModel.ChannelFactory<TChannel>.CreateChannel()
      0,39% Dispose - 74 ms - 1 call - System.ServiceModel.ChannelFactory.Dispose()   (from System.IDisposable)
      0,00% ObtemRoles - 0 ms - 1 call - Mercados.WinForms.Security.MercadosUserManager.ObtemRoles(TipoUtilizador)
      0,00% get_Credentials - 0 ms - 2 calls - System.ServiceModel.ChannelFactory.get_Credentials()
      0,00% Compare - 0 ms - 1 call - System.String.Compare(String, String)
      0,00% SetThreadPrincipal - 0 ms - 1 call - System.AppDomain.SetThreadPrincipal(IPrincipal)
      0,00% get_CurrentDomain - 0 ms - 1 call - System.AppDomain.get_CurrentDomain()
      0,00% UserMercados..ctor - 0 ms - 1 call - Mercados.WinForms.Security.UserMercados..ctor(Utilizador, IList<String>)
      0,00% get_UserName - 0 ms - 2 calls - System.ServiceModel.Description.ClientCredentials.get_UserName()
      0,00% set_Password - 0 ms - 1 call - System.ServiceModel.Security.UserNamePasswordClientCredential.set_Password(String)
      0,00% get_Password - 0 ms - 1 call - SRA.MercadosOO.Utilizador.get_Password()
      0,00% set_UserName - 0 ms - 1 call - System.ServiceModel.Security.UserNamePasswordClientCredential.set_UserName(String)
      0,00% get_TipoUtilizador - 0 ms - 1 call - SRA.MercadosOO.Utilizador.get_TipoUtilizador()

    As you can see, the authenticate call ends up creating a WCF proxy for making the service call. In this case, it took 8 seconds which is way too much for making a call to a service which on another machinw which sits on the same LAN as the client. do notice that there are other machines which are also on the same LAN and it takes more than 30 seconds to perform the same call.

     

    Can anyone give me any tips on how to solve this problem? Is this a jit problem? I've also used netmon and I've noticed that communication between the client and server machine  will only take about 300-400ms. So the problem seems to be with 1.) code jitting or 2.) server discoverability

     

    Any clues on how to debug this?

     

    thanks.

All Replies

  • Tuesday, March 25, 2008 11:49 AMDan RigsbyMVP, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    The first call is always going to take longer since it is setting up the channels (you could call Open directly so the first call itself is a bit faster).  8 seconds is a long time though.  What kind of encryption or authentication are you using?  If you are using certificates or something that uses asymeteric encryption, there may not be a whole lot more you can do.  Most of these algorithms do use asymeteric keys to negotiate symetric keys so that subequent calls are faster.  But that initial handshake and setting up the securiy channels can be costly.
  • Tuesday, March 25, 2008 11:56 AMLuis Miguel AbreuMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

     

    hello Dan.

     

    well, the service is using basic binding and we're using SSL. The security mode is set to TransportWithMessageCredential and we're using a custom ASP.NET membership provider for authenticating the user.

     

    what bothers me is that by using netmon and sniffing the packets and filtering by client and server, we can see that the handshake is not slow. after discovering the server, communication is really fast, but I'm not sure on what's going on before the client communicates with the server. If 8 seconds is slow, then what can we say about another machine which is on the same LAN and takes about 30 seoncs for performing the same stuff? I'm not sure on what else I can do to debug this problem...

  • Tuesday, March 25, 2008 6:21 PMPablo CibraroMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Hi Luis,

     

    The bottleneck can also be in the custom ASP.NET membership, have checked how much time that code takes to validate the user ?.

     

    Regards,

    Pablo.

     

  • Tuesday, March 25, 2008 11:17 PMLuis Miguel AbreuMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

     

    Hello Pablo.

     

    well, I really didn't do that because I've enabled IIS logging and WCF tracing and according to my data, the server is taking about 300ms returning a response back to the client. I've even used netmon and it also confirms this. the server is not the problem. it really lies on the client and I'm not sure on what is wrong here...I mean, I though it could be server discoverability but I've even used an IP address, and it simply takes lots of timefor the 1st call to proceed...

  • Thursday, March 27, 2008 2:55 PMPablo CibraroMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Ok, it makes sense. I am not sure if the problem can be in the SSL handshake, have you tried to reproduce the problem with a different binding, for instance, basicHttpBinding ?. I am just guessing ...

     

    Regards,

    Pablo.

     

  • Thursday, March 27, 2008 3:01 PMLuis Miguel AbreuMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Hello again.

     

    Yes, I've tried that...no differences though.

    The only thing I've done that has improved the speed is casting the channel to ICommunicationObject and calling Open explicitly over it...even though this has improved the speed, I still think that it's slow.

  • Friday, March 28, 2008 1:49 PMPablo CibraroMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Luis, a last try to discard any problem with the channel layer of WCF Smile. If you use a normal asmx web service from the client machines where you have the problem, do you know if the problem is still reproduced ?. If the same happens with asmx, probably the problem can be something outside of WCF (It sounds strange that nobody complains about this before).

     

    Thanks

    Pablo. 

     

  • Thursday, April 10, 2008 11:13 PManandinnz Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    I have been having the same issue with a WPF application using WCF hosted service on IIS (BasicHttpBinding), on initialization, only on certain computers, that the intialization of the proxy is very slow 15-25 seconds. It only happens in few computers, on a most of them it is just about 100 milliseconds. All computers are running on the LAN itself The proxy configuration options seem ok and the computer where it is slow is running using administrative priveleges.

    Was there any resolution to your issue? Any ideas?

     

     

     

  • Thursday, April 10, 2008 11:59 PMISSY.SAM Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

     

    I once read that client serializes data in intialization, and to improve this is generating the serialized data before communicating with the service, i'm just guessing .. see this How to: Improve the Startup Time of WCF Client Applications using the XmlSerializer
  • Wednesday, August 06, 2008 10:07 AMjaziz Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    I am also facing the same issue. Anybody got a solution?

     

  • Sunday, November 16, 2008 7:56 PMmohit.raghav Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    any solutions???
  • Monday, March 23, 2009 8:00 PMRudsen Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    we have the same problems
    .NET Developer
  • Monday, July 27, 2009 6:08 AMleorajiv Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Is there anybody who can give a good answer to this.
    The first time i call a service it takes 2 seconds and in all the later calls the time is reduced to some milliseconds.
    Actually when my WPF application starts, it takes around 10 seconds out of which there are 3 service calls taking around 6 seconds.
    My actual code takes 4 secs to execute which is evident at the 2nd and the 3rd attempts to start the windows app.
    I have to improve performance of my application anyhow and if i could even gain 1 second for each of the calls i would gain 3 seconds.
    Can any body help with this.
    Is there any good way to better the first call performance.
  • Monday, July 27, 2009 9:56 AMRudsen Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Try to disable the proxy detection on the client in web.config (in the binding useDefaultWebProxy="false")
    .NET Developer