-
Notifications
You must be signed in to change notification settings - Fork 5k
HttpClient Performance Slow Compared to .NET 4.7 #23255
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Frankly, I am surprised that you could do 10000 requests with this code. I've tried something similar and got the same error as this person. Going back to performance, I've tried testing AspNet Core 2.0's REST performance using a DotNet Core 2.0 console application (yes, I know that there are tools for that) and the client ended up being the bottleneck for my little test. I was expecting to be able to create more requests than the server can respond to. If I create too many requests at the same time, I get the linked error on the client. If I create them sequentially in several threads, the client's process has a much higher CPU usage than the server. |
@MarinAtanasov I was initially receiving that error as well. Setting |
Considering that there are tools which can measure upwards of a million requests per second (written in other languages), what are the max requests per second which can be achieved through a .Net Core 2.0 client and how much CPU/memory would it consume? @narciero, from your test it would seem that you cannot do more than two thousand requests / second. Am I missing something obvious here? |
@MarinAtanasov its important to note that i tested using |
The performance will depend on may factors - like using keep-alive, DNS, etc. I don't have any benchmarks for .net framework yet but it is on TODO list. |
Yes, this is very much on our list for ManagedHandler. We plan to compare Windows vs. Linux vs. Desktop vs. other platforms vs. old HttpClientHandler. Given that it is on our backlog and the data above is not complete and will need to be re-measured anyway, I don't think we need this issue opened. Closing (let me know if you think it is wrong). |
Do all similar objects suffer from this or is it just HttpClient? |
This particular issue lacks details and deeper analysis. The results are a bit suspicious and were not attempted to reproduce by anyone else. There is a suspicion that the compared platforms don't use the same settings under the hood (e.g. |
I am not sure how it is compared to .NET Framework, but we definitely know that HttpClient in .NET Core is incredibly slow and heavy. That is proven by the fact that we can expect performance improvements up to 1000% (x10) in .NET Core 2.1. Source: .NET Core 2.1 Roadmap. @TechnikEmpire, if you are using microservices, expect this to be a bottleneck. We had a framework performance comparison for one of our microservices where .NET Core had about 50% of the performance of Node or Go. We should get our hands on .NET Core 2.1 sometime during the summer. Until then, I do not know if there are any fast alternatives to using HttpClient. |
@MarinAtanasov I'm using the client to handle the upstream side of a local transparent filtering proxy and yeah it shows. I guess I'll just target .net full for now to avoid the issue. |
@MarinAtanasov do you have any evidence that HttpClient in .NET Core is incredibly slow and heavy? Are you measuring Windows or Linux? @TechnikEmpire if you have a specific code which shows performance difference between .NET Framework and .NET Core - especially on Windows, we would be very interested in getting our hands on it. Is it something you could share as a perf test? |
@karelz I'll see if I can't whip up a test case. I test my proxy code by running an external Apache tool to measure latency and throughput so I'm wondering if you'll accept such a test case. |
That may be ok @TechnikEmpire as well as the original post simply measured total time to completion. |
@TechnikEmpire ideally I would like to see an app with workload which we can measure with our tools on our side. If you have recommendations for existing tools, we're all ears of course. It would be just unfortunate if the workload is tied to them. |
Ok thanks I'll see what I can do. I've written a couple of projects heavily relying on http client (one a crawler and one a proxy) and the performance of both wasn't stellar but that's anecdotal of course. Will let you know if I can out something together I just have a few things on my plate atm. |
We are migrating a .net application (4.5 under windows) to dotnet core and we also noticed that Our application is using a lot of microservices, we'll have to wait for this issue to be addressed (hopefully in dot net core 2.1) before moving forward. |
@soualid you can try 2.1 right now. It has the new networking stack mentioned above, which is faster, esp. on Linux.
|
We just tried and we can confirm that .NET Core 2.1 Preview 1 is way more performant than 2.0 under linux using docker containers, it now takes around 90ms for Congrats, we are now eagerly waiting for the 2.1 GA version. :-) |
It can't come too soon, in my experience so far, .net core performance is unacceptable for production use, compared even to .net framework, Let's not bother comparing it to Node, Java, Python, etc, where it gets it's ars soundly handed to itself repeatedly. |
@BKlippel Can you share the data you're basing that on? Have you tried using .Net Core 2.1 RC1 to see if it's an improvement? |
not sure what you have in there but this might be the reason for increased total run time. this is the only part not adding up to individual request processing times. |
HttpClient is very slow, some open source projects based on the underlying httpClient are being criticized. such as the project https://github.com/ThreeMammals/Ocelot its performance is much lower than project https://github.com/Kong/kong In order to get performance as well as some other reason people have to give up using .Net core. |
@sgf, you've been going around commenting on a variety of issues, making broad negative claims about performance, with nothing to substantiate those claims. If you're hitting a performance issue, please open a new issue that includes a repro of the problem and specifics about what the exact problem is. |
Ohhh snap got called out sup dog |
Thank you for your reminder. But isn't the issue used to give feedback? The purpose of replying to some issues is simply to let the community administrator not easily ignore some of the user's problems. At the same time, I have encountered similar problems. People often spend a lot of time discussing in a issue, but it is easily closed by community administrators. |
Some words are not very good, but there are such things happening around me (for example, the people around me have been transferred from .net to java/go/rust in recent years. There are many reasons for this because the ecology of .net is not good enough, or Performance is not high enough). As an ordinary .net developer, I am a little anxious, and I hope that .net is getting better and better. |
As someone who lives in .net land both at work and at home, if you're getting generally bad performance with .net, its your programming skills, not the platform. |
I agree that the skill is indeed one aspect. A friend of mine submitted his project BeetleX to TechEmpower . He thinks it may be mainly a performance issue with CLR, SQLDriver and Socket. |
Means nothing. I'd like to see the results of a performance profiler hooked directly up to tests against the project in question. As is, the stuff you've linked means nothing. Unless you're going to submit a PR or learn the basics of programming, please stop making noise on repositories that thousands of people are following. |
got it |
I'm using Refit in WPF app. I ported it to .NET Core (3.1 now) and HTTP requests cause major UI slowdowns/freezes ( I send them inside WPF commands). Refit uses HttpClient under the hood so this might be related... Initially, I thought it's WPF problem but after removing HTTP call it came back to normal. |
It's possible it's using it "incorrectly". If it's creating and disposing a |
@stephentoub That was it! I was creating and disposing my API client (which wraps Refit) on every access. I didn't know it makes any difference in .NET Core 😮 . Thanks a lot 😄 it works fine now just like it did before. |
@bugproof, great, glad you got it sorted out. |
I have conducted a basic performance test of
HttpClient
in .NET Core 2.0 versusHttpClient
in .NET Framework 4.7 and have noticed a gap in performance. The .NET Framework 4.7HttpClient/WebClient
outperforms .NET Core'sHttpClient
by ~1.5-2x in terms of how long it takes to complete a batch of n requests.Testing
The test is a console app (run in release mode on Windows 7 16GB 3.5GHz) with identical code for .NET Core/Framework that follows this sequence:
I am testing against a basic python server that is well under capacity to rule out any server side bottlenecks. The server returns a simple JSON response containing an
id
field which is used to validate the HttpClient responses.JSON deserialization / response validation is NOT included in performance stats.
Results
These are average statistics (in milliseconds) of 5 separate runs of 10,000 requests each. It is worth mentioning that the actual time spent on each request was much less with .NET Core's HttpClient, it's just that the batch of requests takes longer to complete as a whole vs .NET Framework.
The text was updated successfully, but these errors were encountered: