Poor performance when using HttpContent.ReadAsAsync<T> for JSON payloads

Topics: ASP.NET Web API, General
Oct 21, 2014 at 10:18 PM
Edited Oct 21, 2014 at 10:20 PM
Hi,

I have been doing some performance analysis for the APIs we are building which are heavily based on ASP.NET Web API and HttpClient and I noticed very high CPU usage mainly around serialisation and deserialisation of JSON payloads. This by itself not a biggie until I discovered if I use ReadAsStringAsync and then deserialise, performance is much better.

I have documented my observations here and got in touch with James Newton King, author of Json.NET.

Should I raise a bug in Microsoft connect or this level of engagement is enough? Also wondering what your thoughts are - does this make any sense? I could be doing something completely wrong.

Thanks
Ali
Developer
Oct 21, 2014 at 10:24 PM
Hi aliostad,

My guess is that your issue might have already been solved by the following fix which was made very recently. Check it out and let us know if you have any more questions:

Issue:
http://aspnetwebstack.codeplex.com/workitem/2092

Commit:
http://aspnetwebstack.codeplex.com/SourceControl/changeset/a0eb22a4b74bee7c9e909839ffb6497a0d05315c

If you cannot take this fix, probably you can try the workaround where you cache the Json formatter and use it explicitly when doing a ReadAsAsync with your HttpClient.

Thanks,
Kiran
Oct 21, 2014 at 11:21 PM
Thanks.

It makes sense and seems to be the same problem.
Developer
Oct 21, 2014 at 11:29 PM
Cool...Thanks! for reporting the issue and the detailed analysis...
Jul 18 at 10:59 AM
Edited Jul 18 at 10:59 AM
Thanks Guys.

It fixed one our performance issue