influxdata / influxdb-client-csharp

InfluxDB 2.x C# Client
https://influxdata.github.io/influxdb-client-csharp/api/InfluxDB.Client.html
MIT License
360 stars 94 forks source link

DB response is fast,But translate to a List is not #328

Closed xujizhou closed 2 years ago

xujizhou commented 2 years ago

Proposal: DB response is fast,But translate to a List is not

Current behavior: The function i used

public Task<List<T>> QueryAsync<T>(string query, string org = null,CancellationToken cancellationToken = default)

I had a query,that response datas of 336000 rows,the query [took 3 seconds] Got

#datatype,string,long,dateTime:RFC3339,dateTime:RFC3339,dateTime:RFC3339,string,string,string,string,string,double
#group,false,false,true,true,false,true,true,true,true,true,false
#default,_result,,,,,,,,,,
,result,table,_time,Tag1,Tag2,Tag3,Tag4,_measurement,Field1
,,0,2022-06-01T16:00:00Z,1,2,3,4,test_measurement,0.18
..........

After that begin to translate to a List Use functions

public void ParseFluxResponse(Stream source, CancellationToken cancellable, IFluxResponseConsumer consumer)
{
    Arguments.CheckNotNull(source, "source");

    using var csv = new CsvReader(new StreamReader(source), CultureInfo.InvariantCulture);
    var state = new ParseFluxResponseState { csv = csv };

    while (csv.Read())
    {
        if (cancellable.IsCancellationRequested)
        {
            return;
        }

        foreach (var (table, record) in ParseNextFluxResponse(state))
            if (record == null)
            {
                consumer.Accept(state.tableIndex, table);
            }
            else
            {
                consumer.Accept(state.tableIndex - 1, record);
            }
    }
}

and

public async Task<List<T>> QueryAsync<T>(Query query, string org = null,CancellationToken cancellationToken = default)
{
    Arguments.CheckNotNull(query, nameof(query));

    var measurements = new List<T>();

    var consumer = new FluxResponseConsumerPoco<T>(poco => { 
        measurements.Add(poco); 
    }, Mapper);

    await QueryAsync(query, consumer, ErrorConsumer, EmptyAction, org, cancellationToken)
        .ConfigureAwait(false);

    return measurements;
}

The translation [took 9 seconds]

Desired behavior: Can the translation take less time?

Alternatives considered: For example use the mult-task

Use case: Improve efficiency and save time

bednar commented 2 years ago

Hi @xujizhou,

thanks for using our client.

Can you share your data? It will be easier to use to find a glitch...

Regards

bednar commented 2 years ago

This issue has been closed because it has not had recent activity. Please reopen if this issue is still important to you and you have additionally information.