Friday, September 6, 2013

Slow serialization of WCF response using DataContractSerializer

Slow serialization of WCF response using DataContractSerializer

I have a WCF service that performs a search and returns a list of
reasonably complex objects to the client. This is an EAV system, so each
entity that is returned has a list of values attached that varies in size
depending on the entity blueprint.
In my test search, I have confirmed through logging that the actual search
takes under a second to complete in almost every case. The very last thing
I do before returning the response to the client is log that processing
has finished.
Unfortunately the client does not receive the response until 15-20 seconds
after I have finished with it. The total response size is about 250kb, so
pretty small. This is being transmitted via LAN at the minute and I have
tried disabling the firewall and antivirus to make sure neither is
interfering.
I noticed, however, that if the response was considerably smaller, for
instance by removing the fields attached to each entity, that the response
came through a lot faster. I also tried stepping through a locally hosted
(IIS) copy of the service, and after passing the final return statement it
still took another 15 seconds to reach the local client application.
I am using basicHttpBinding as the service will be consumed by both .Net
and PHP clients.
Now then, can anyone suggest a way I can confirm that this is indeed the
case? And how might I fix the cripplingly slow serialization times?
Edit:
To clarify, I have marked each class with the [DataContract] attribute and
each property with [DataMember] - WCF is handling the serialization when I
return the data. In this case it is a List of type Entity (a custom class
that contains a list of values.
Edit 2:
I've tested the speed of DataContractSerializer and it took about 15
seconds to write a list of 65 returned entities to a simple memory stream.
This seems ridiculous, and I'm not sure what has changed to make it so
painfully slow.

No comments:

Post a Comment