C
C#•3y ago
Kosta

Trying to compare grpc to minimal api performence- minimal much faster, Logic probably rotten

So i got this grpc client that streams data from a csv to a console and just prints it, in 1 minute it can do about 1.5mil records. On the other hand i got this minimal api, Now here begins the problem Im guessing I need to use httpclient to make the call inorder to compare? Because before i had this:
var client = new HttpClient()
; await foreach (var line in MakeHttpCall())
{
Console.WriteLine(line);
}
var client = new HttpClient()
; await foreach (var line in MakeHttpCall())
{
Console.WriteLine(line);
}
And this was twice as fast , 3 million records in a minute then i figured out im testing it wrong, However how do i use a client and what methode i need to invoke in the foreach?
async IAsyncEnumerable<string> MakeHttpCall()
{
var watch = System.Diagnostics.Stopwatch.StartNew();
int Count = 0;

using (var reader = new StreamReader(@"C:\Users\kosta\source\repos\gRPCDemoUsingNET6\gRPCDemoUsingNET6\Data\sales_records.csv"))
{
while (watch.Elapsed < TimeSpan.FromSeconds(60) && !reader.EndOfStream)
{
var line = reader.ReadLine();
var values = line.Split(';');
yield return line;
Count++;
}

}
watch.Stop();
Console.WriteLine($"Stream ended: Total Records:{Count.ToString()} in {watch.Elapsed.TotalMinutes} minutes and {watch.Elapsed.TotalSeconds} seconds.");
}
async IAsyncEnumerable<string> MakeHttpCall()
{
var watch = System.Diagnostics.Stopwatch.StartNew();
int Count = 0;

using (var reader = new StreamReader(@"C:\Users\kosta\source\repos\gRPCDemoUsingNET6\gRPCDemoUsingNET6\Data\sales_records.csv"))
{
while (watch.Elapsed < TimeSpan.FromSeconds(60) && !reader.EndOfStream)
{
var line = reader.ReadLine();
var values = line.Split(';');
yield return line;
Count++;
}

}
watch.Stop();
Console.WriteLine($"Stream ended: Total Records:{Count.ToString()} in {watch.Elapsed.TotalMinutes} minutes and {watch.Elapsed.TotalSeconds} seconds.");
}
How do i procced? obviously im doing smth/multiple things wrong. If i try to do smth like this
await foreach (var line in client.GetAsync(""))
await foreach (var line in client.GetAsync(""))
I get a "does not contain extension defenition for getasyncenumarator
4 Replies
Kosta
KostaOP•3y ago
Nobody got any idea guys? 😄
Anton
Anton•3y ago
foreach (var line in await client.GetAsync("")) maybe
Kosta
KostaOP•3y ago
Nop , same error ""does not contain extension defenition for getasyncenumarat"
Anton
Anton•3y ago
remove await before foreach that one work with IAsyncEnumerable while you just get a single message supposedly
Want results from more Discord servers?
Add your server