Skip to content

Made HttpClient static and reordered requests to assume happy path first.

Ghost User requested to merge 626-HttpRepoPerformance into master

Results from this MR:

100 Requests 200 Requests 500 Requests 3 Requests*
CurrentAvg 259 ms 258 ms 267 ms 432 ms
NewAvg 40 ms 43 ms Exception** 192 ms
Improvement % 84.56% 83.33% ? 55.56%

*The 3 requests is the most realistic scenario. And this also includes the HttpPackageRepository instantiation and not only checking the version as the hundreds of requests, which is fairer, as the HttpClient is moved to be instantiated statically. ** Using this new implementation, I was simply not able to check 500 times as fast as possible towards http://packages.opentap.io due to a WebException where the repo was not answering. I'm guessing that this is due to too much load on the webserver with 500 requests:

TestMethod used to test this (adjust times and move stopwatch.Restart(); for different tests):

        [Test]
        public void TestVersion()
        {
            List<long> timings = new List<long>();
            int times = 500;
            Stopwatch stopwatch = Stopwatch.StartNew();
            for (int i = 0; i < times; i++)
            {
                var type = PackageRepositoryHelpers.DetermineRepositoryType("http://packages.opentap.io");
                if (type is HttpPackageRepository packageRepository)
                {
                    stopwatch.Restart();
                    Console.WriteLine(packageRepository.Version);
                    var time = stopwatch.ElapsedMilliseconds;
                    timings.Add(time);
                }

            }
            Console.WriteLine($"Average: {timings.Sum() / times}");
        }

Closes #626 (closed)

Merge request reports