influxdata / influxdata/influxdb-client-python

Performance bottleneck in FluxCsvParser when parsing large CSV payloads (10MB+)

Abierto
#691 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

bug
Lenguaje dominante
Python
Estrellas
793
Forks
186
Merge medio
3 h 2 min
PR fusionados (30 d)
1

Descripción

### Specifications

* Client Version: 1.48.0
* InfluxDB Version: 2.7
* Platform: macos

### Code sample to reproduce problem

```python
```
import influxdb_client
client = influxdb_client.InfluxDBClient(
url="http://localhost:8086",
token="TOKEN",
org="organization",
)
query_api = client.query_api()
query = 'from(bucket: "sensors") |> range(start: 2025-04-13T14:18:11.036Z, stop: 2025-04-13T14:33:11.036Z)'
result = query_api.query(org="matna", query=query)

### Expected behavior

runtime of this query must be same as ui influx

### Actual behavior

runtime this code is not same order

### Additional info

Hi InfluxDB team,

I've encountered a significant performance bottleneck in the FluxCsvParser class within the InfluxDB Python client when working with larger datasets.

🐞 Issue Description
When querying data (~10MB in size), the network call returns results in under 20 ms, which is excellent. However, the CSV parsing step takes over 5 seconds to complete. This introduces an unacceptable latency for high-throughput or low-latency use cases.

In contrast, using the Go client for the same query and dataset, the full query—including parsing—is completed in under 200 ms. This makes the Python client around 25x slower just in the parsing stage.

📈 Performance Benchmark
Data size: ~10MB (Flux CSV)

Query response time (network): < 20 ms

Parsing time (Python client): > 5000 ms

Parsing time (Go client): < 200 ms

🔍 Root Cause
Profiling indicates that the performance degradation is centered in the FluxCsvParser implementation. The current parsing logic in Python seems to be inefficient for large responses due to overhead in string parsing, tokenization, and possibly memory management.

💡 Suggested Improvement
To address this, I suggest reviewing the implementation of FluxCsvParser—specifically around how it handles tokenization, buffering, and line-by-line parsing. Additionally, performance could be dramatically improved by offloading the CSV parsing to a C extension (e.g., using cffi, cython, or ctypes) or integrating an existing optimized parser like libcsv or simdjson.

This would help close the gap with the Go client's performance while maintaining compatibility with the current interface.
✅ Request
Could the maintainers review the FluxCsvParser code path, especially in generate function?

Is there openness to rewriting this part as a performance-critical native extension, or at least modularizing it for optional native acceleration?

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Comienza localizando la implementación de FluxCsvParser y su función generate; después, perfila el análisis por separado de la solicitud de red usando una respuesta Flux CSV de aproximadamente 10MB. Compara el tiempo de análisis de Python con el resultado reportado del Go-client e identifica los costes de tokenización, almacenamiento en búfer o procesamiento de líneas. Se considerará terminado cuando se haya medido una mejora del análisis, se conserve la interfaz actual del cliente y se documente la comparación de rendimiento.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
python
Área
performance
Tipo de issue
Error
Dificultad
5/5
Tiempo estimado
Más de una semana
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
25/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.