Hello.
I’m struggling with the slow speed when querying data in FluuxDB.
When querying the same range of data, WebUI takes approximately 100 ms, while Python API takes 6000 ms.
The image above compares the query rate via Python API with the query rate via WebUI.
As you can see, the script used is the same.
I don’t know how to quickly query through API.
I used the same script that is displayed in the UI, but I have no idea why the speed difference occurs.
Please help me.
Thank you.
python code ====================================================
import time
import mysql.connector
import pickle
import binascii
from influxdb_client import InfluxDBClient, Point, WritePrecision, WriteOptions
from influxdb_client.client.write_api import ASYNCHRONOUS
import numpy as np
from datetime import datetime
import sys
import random
from dateutil.parser import parse as parse_date
from influxdb_client.client.query_api import QueryApi
InfluxDB settings
influx_config = {
‘url’: ‘http://localhost:8086’,
‘token’: ‘n3MAF8LJlj9sofV7IkoZHEcWsMVOMkgN5gQqX7_JfhuKcRDE0pG6z_qVxP_orGITjTo2ekZvLx_5qRrcKb1fFg==’,
‘org’: ‘TestORG’,
‘bucket’: ‘T001’
}
def read_influxdb2():
client = InfluxDBClient(**influx_config)
query_api = client.query_api()
start_time = time.time() # Record start time
query = f'from(bucket: "T001")' \
f'|> range(start: -24h)' \
f'|> filter(fn: (r) => r["_measurement"] == "my_measurement")' \
f'|> aggregateWindow(every: 100ms, fn: mean, createEmpty: false)' \
f'|> yield(name: "mean")'
result = query_api.query(query)
end_time = time.time() # Record end time
elapsed_time = end_time - start_time # Calculate elapsed time
print(f'Reading took {elapsed_time * 1000} milliseconds')
print(result)
print('@@@@@@@@@ Read Complete @@@@@@@@@')