Mikel
Mikel

Reputation: 167

C# service performance issue with Json.NET and GC Wait

I have a windows service that do some business work. I profile it with dotTrace to find performance issue and have a picture like this: GC Wait 88%

It seems strange that GC Wait take 88% time, so I get closed look at some small interval and get: Thread stats

I found that during not bloking period, threads allocate object through JSON.Net deserilization and also this code blocked by GC:

    using (var response = await _httpClient.SendAsync(request, combinedTokenSource.Token))
    {
        response.EnsureSuccessStatusCode();
        if (response.Content == null)
            throw new InvalidOperationException("No HTTP response received.");

        using (var responseStream = await response.Content.ReadAsStreamAsync())
        {
            using (var textReader = new JsonTextReader(new StreamReader(responseStream)))
            {
                var results = new JsonSerializer().Deserialize<ElasticResponse>(textReader);
                return results;
            }
        }
    }

Did anyone have a similar problem? Or am I missing something?

Upvotes: 2

Views: 1039

Answers (2)

Mikel
Mikel

Reputation: 167

Finally i found that my app dosen't use "background server garbage collection" (microsoft says it is default in .net 4.5 - gc description). So I add to config:

   <runtime>  
      <gcServer enabled="true"/>  
   </runtime>

and it reduce GC Wait time to 8.5%, as a result I get 5x performance progress.

Upvotes: 3

Related Questions