0

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);
}

And this was twice as fast , 3 million records in a minute then I figured out I'm testing it wrong, However how do i use a client and what method 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.");
}

How do I procced? Obviously I'm doing smth/multiple things wrong. If i try to do smth like this

 await foreach (var line in client.GetAsync(""))

I get a "does not contain extension definition for getasyncenumarator

Guru Stron
  • 102,774
  • 10
  • 95
  • 132
AntiMatter
  • 13
  • 5
  • Your use case isn't clear to me. When you say "_each line as it is being recieved_", does that mean you expect the API to send each line one at a time? If so, your API code doesn't seem to do that. Actually, I'm a bit confused about your API code anyway, as the API call itself calls a `MakeHttpCall` method that you didn't show, and then you have an isolated piece of code that reads a CSV file, and saves the first line and that line split into a variable. It ignores the rest of the file and doesn't do anything with the line it read. Please clarify your question – Avrohom Yisroel Nov 20 '22 at 20:28
  • Yeah I dont know what to do with the line, how to i return the values to the Ui? I do want the api to send each line at at time to the frontend and im unsure how to do it – AntiMatter Nov 21 '22 at 10:49
  • What do you mean by "one at a time"? You can read the whole file in one go, why would you want to send the lines out individually? – Avrohom Yisroel Nov 21 '22 at 13:57
  • @AvrohomYisroel im doing a grpc comparison with webapi, streaming the data as it comes in. Anyways changed the question – AntiMatter Nov 22 '22 at 11:51
  • The best way is to read into a buffer that take current content of receive data. Than read only line at a time from buffer. Remove line from buffer as you proceed. Check if buffer contains a return. When you do not have a return in the buffer read the http connection and append to current buffer. – jdweng Nov 22 '22 at 12:00
  • Can you show code example? – AntiMatter Nov 22 '22 at 12:45

0 Answers0