MgSam
MgSam

Reputation: 12803

WCF Service Slow - Options?

I have a WCF Service that is returning JSON data. It has to be able to return 10000-50000 objects. I've done some timing and it takes less than 10 milliseconds for the body of the method the service is calling to complete, yet the client experiences a delay of 5 seconds or more to get the response. For development purposes both the client and server are on the same machine, so network latency is not a factor.

My feeling is that the serialization of the CLR objects into JSON is what's taking all the time. I've considered GZiping the response, but I think that might actually make it slower since the network bandwidth is not an issue. I've also considered using JSON.NET instead of the built-in serialization, but I haven't found any recent end-to-end information on how to do that so I haven't been able to get it working, and I'm not sure how much speed up it might provide.

Is there anything else I should look into to make this faster?

Upvotes: 2

Views: 373

Answers (2)

kellyb
kellyb

Reputation: 1371

I would recommend having a look at the trace as vibhu stated and I wouldn't be too quick to rule out network bandwidth as a possible bottleneck. In my experience, especially for large messages, serialization overhead and network transmission make up a significant percentage of the overall operation's response time. Play around with different bindings - such as named pipes. Try calling the service in-process. Try serializing one of the messages to disk and deserializing it back into memory and wrap a stopwatch timer around it. These are poor-man tools for getting a feel for the serialization cost. [dotTrace] is a quality commerical profiler that will tell you alot about where the time is being spent.

Lastly, in our tests, GZip will up your CPU usage, but have a marginal impact on response time in exchange for significantly smaller network transmissions. In the end it was significantly faster for us and I would recommend it to anyone that's not CPU bound. But if your problem is serialization cost and not network transmission, then this most likely won't address your immediate issue. Having said that, it's probably just a good idea for general scalability if your CPU's have the spare ticks.

Hope that helps...

Upvotes: 0

vibhu
vibhu

Reputation: 1695

Enable tracing with switch value All. It should reveal something helpful.

<system.diagnostics>
 <sources>
  <source name="System.ServiceModel" switchValue="All" >
    <listeners>
      <add name="xml"
         type="System.Diagnostics.XmlWriterTraceListener"
         initializeData="C:\UserTraces.svclog" />
    </listeners>
  </source>
 </sources>
 <trace autoflush="true" />
</system.diagnostics>

Upvotes: 2

Related Questions