Skip to content

Conversation

@ptiurin
Copy link
Contributor

@ptiurin ptiurin commented Nov 5, 2025

This pull request significantly improves the streaming query result processing pipeline for large datasets, focusing on efficient memory usage, proper backpressure handling, and robust performance. It also introduces comprehensive integration and performance tests to benchmark and validate the new streaming behavior against traditional result fetching.

Streaming and Backpressure Improvements:

  • Refactored the ServerSideStream class in src/statement/stream/serverSideStream.ts to implement a pending rows buffer, limit memory usage with a maxPendingRows threshold, and properly pause/resume the streaming interface to handle backpressure. The stream now pushes data downstream as consumers are ready, preventing memory buildup and ensuring efficient processing. Also, improved error handling and resource cleanup during stream destruction.

  • Optimized the normalizeResponseRowStreaming function in src/statement/normalizeResponse.ts for performance by replacing Array.map with a manual for-loop and pre-allocated result array, reducing overhead for large datasets.

Testing and Validation:

  • Added a new integration test suite in test/integration/v2/performance.test.ts to compare performance and correctness between normal (fetchResult) and streaming (streamResult) executions across various dataset sizes, including pipeline processing scenarios. The tests ensure that streaming is not more than 10% slower than normal execution and that both methods yield identical results.

Before (testing 1000000 rows with different data types):
memory_log_2025-11-18T09-12-08-820Z_plot

After (memory now is stable over a long time with no large spikes):
memory_log_2025-11-17T17-29-57-273Z_plot

@ptiurin ptiurin force-pushed the fix-streaming-with-backpressure branch 12 times, most recently from dd90aee to 6922e13 Compare November 14, 2025 17:12
@ptiurin ptiurin force-pushed the fix-streaming-with-backpressure branch from edbe6c7 to 91b3e62 Compare November 17, 2025 16:17
@ptiurin ptiurin marked this pull request as ready for review November 18, 2025 09:15
@ptiurin ptiurin requested a review from a team as a code owner November 18, 2025 09:15
@ptiurin ptiurin force-pushed the fix-streaming-with-backpressure branch from fb48d23 to 131b8c8 Compare November 18, 2025 17:13
@ptiurin ptiurin force-pushed the fix-streaming-with-backpressure branch from 131b8c8 to a499607 Compare November 18, 2025 17:20
@sonarqubecloud
Copy link

@ptiurin ptiurin merged commit 9f3eb53 into main Nov 19, 2025
4 checks passed
@ptiurin ptiurin deleted the fix-streaming-with-backpressure branch November 19, 2025 09:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants