JSON Serialization Slow

I have a very simple ASP.NET WebAPI endpoint that calls one call in our database and returns these strings as JSON. The response size is about 180 KB (180 entries).

When I deploy this project on Azure, this call takes about 100 ms, which is good, but only in the first minutes, and then it gradually slows down to 24 seconds.

In the following code, I serialize the object manually, instead of just returning the modal text directly (using the Webapi JSON serializer, which is the same one) to figure out where the time is being spent.

[HttpGet]
[Route("{stuffId}/toys")]
[ResponseType(typeof(IQueryable<FooModel>))]
public HttpResponseMessage GetStuff(int stuffId)
{
    var stuff = QueryProcessor.Execute(new GetStuffByIdQuery
    {
        StuffId = stuffId,
    });

    var mappedResult = stuff.Map();

    var response = Request.CreateResponse(HttpStatusCode.OK);

    var json = JsonConvert.SerializeObject(mappedResult);

    response.Content = new StringContent(json, Encoding.UTF8, "application/json");

    return response;
}

And what I realized is amazing, time is wasted on the Serialization method.

var json = JsonConvert.SerializeObject(mappedResult);

, , - Azure, , , , .

, ?

+4
1

, , , - .map, .

- , , .

, ResourceManager .

+1

Source: https://habr.com/ru/post/1662947/


All Articles