From 7daaae334e843471c347f12607a17472d817cb54 Mon Sep 17 00:00:00 2001 From: Alexey Golub Date: Sat, 30 Dec 2017 16:06:39 +0200 Subject: [PATCH] Improve network performance --- OsuHelper/Services/DataService.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/OsuHelper/Services/DataService.cs b/OsuHelper/Services/DataService.cs index 0a74db8..7837a77 100644 --- a/OsuHelper/Services/DataService.cs +++ b/OsuHelper/Services/DataService.cs @@ -31,8 +31,14 @@ public DataService(ISettingsService settingsService, ICacheService cacheService) _settingsService = settingsService; _cacheService = cacheService; + // Connection limit + ServicePointManager.DefaultConnectionLimit = 9999; + // Client - _httpClient = new HttpClient(); + var handler = new HttpClientHandler(); + if (handler.SupportsAutomaticDecompression) + handler.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate; + _httpClient = new HttpClient(handler, true); _httpClient.DefaultRequestHeaders.Add("User-Agent", "osu!helper (github.com/Tyrrrz/OsuHelper)"); // Rate limiting @@ -63,7 +69,7 @@ private async Task InternalSendRequestAsync(HttpRequestMess await MaintainRateLimitAsync(TimeSpan.FromMinutes(1.0 / 1200)); // Get response - var response = await _httpClient.SendAsync(request, HttpCompletionOption.ResponseContentRead); + var response = await _httpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead); // Check status code // We throw our own exception here because default one doesn't have status code