skip to Main Content

I have a server running locally on my machine, and two different environments/projects, .Net8 (or any other .Net core version) and .Net Framework 4.8 performing post request on server with same parameters using Rest Sharp version 105.2.3.0
But response time is different in both cases. I have debugged external server too, it is responding in same time for both cases. But issue lies in .Net Core project. It is taking more time.

Code on both environments/projects:

var client = new RestClient("http://localhost:5005/predict");
var request = new RestRequest(Method.POST);
var imageToScore = "d:imagePath.jpg";
request.AddFile("image", imageToScore);


Stopwatch watch = new Stopwatch();
watch.Start();
IRestResponse response = client.Execute(request);
watch.Stop();
string msg = "Request response time " + (watch.ElapsedMilliseconds) + "milli seconds. ";
Console.WriteLine(msg);

.Net Framework 4.8 output window:

Request response time 348milli seconds. 
Request response time 301milli seconds.  

.Net Core output window:

Request response time 2387milli seconds. 
Request response time 2317milli seconds

Clear difference of around 2000ms is present.
Is there something I am missing in .Net Core configuration ? As I have created both new projects and just installed RestSharp in both & have not changed any settings or configurations for both of the projects

I have tried using HttpClient too but the response time is same.

2

Answers


  1. I’m not sure that it is the real reason, because there’s not enough data, but I had somewhat similar problem around .NET Core 3.0.

    Kestrel does not support sync reads/writes by default, if you try to write more than 32KB of data it will buffer to hard drive and then immediately asynchronously read it (you can track these with a profiler) which tremendously slows down the operation as data passing through hdd is expensive – (github issue). Solution is to go async and switch to ExecuteAsync() which you should be using in the first place, because network communication is inherently asynchronous operation.

    Login or Signup to reply.
  2. RestSharp versions earlier than v107 is not targeting .NET and .NET Core, only .NET Framework.

    Most certainly, using the latest RestSharp version and making async calls as pointed out in the first answer, will give better results.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search