influxdata / influxdata/influxdb-client-python
Performance bottleneck in FluxCsvParser when parsing large CSV payloads (10MB+)
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Python
- Star
- 793
- Fork
- 186
- Merge trung bình
- 3 giờ 2 phút
- Pull request đã merge (30 ngày)
- 1
Mô tả
### 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?
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu bằng cách xác định implementation của FluxCsvParser và hàm generate của nó, sau đó profile việc phân tích cú pháp riêng biệt với yêu cầu mạng bằng một phản hồi Flux CSV có kích thước khoảng 10MB. So sánh thời gian phân tích cú pháp của Python với kết quả Go-client đã được báo cáo và xác định chi phí của việc tokenization, buffering hoặc xử lý dòng. Công việc được xem là hoàn tất khi đã đo được sự cải thiện về hiệu năng phân tích cú pháp, vẫn giữ nguyên interface hiện tại của client và đã ghi lại tài liệu về so sánh hiệu năng.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- python
- Lĩnh vực
- performance
- Loại issue
- Lỗi
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 25/100