ClickHouse / ClickHouse/clickhouse-java

Block in NonBlockingInputStream

未关闭
#2,297 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
bug client-v1 enhancement
主要语言
Java
星标
1.6k
派生
636
平均合并
2 天 23 小时
30 天内合并 PR
29

描述

![Image](https://github.com/user-attachments/assets/4f8a9c5d-5ab7-4b99-84b4-0d02281d623b)

![Image](https://github.com/user-attachments/assets/dd02be80-b7ec-4789-b138-bb695248f8ba)

https://github.com/ClickHouse/clickhouse-java/blob/5758ec51f944dc1daaac4a85084346ee5f8e93bb/clickhouse-data/src/main/java/com/clickhouse/data/stream/NonBlockingInputStream.java

NonBlockingInputStream has a busy loop in it, which consumes 100% CPU while it waits for data from server. Not only does it block the NonBlockingInputStream, but also it does it in a resource intensive way.

### Describe the solution you'd like
Either add Thread.sleep(1) there or a more configurable wait strategy.

### Describe the alternatives you've considered
One can also change queue implementation from AdaptiveQueue to some other queue which supports blocking waiting. But it contradicts the expected non blocking behavior of this class anyway.

### Additional context
I am attaching a profile of my application collected by async profiler. One can see that about 86% of cpu time is spent in this place.

贡献指南

打开贡献指南

调研方向

首先阅读 clickhouse-data/src/main/java/com/clickhouse/data/stream/NonBlockingInputStream.java,重点关注等待服务器数据的 busy loop 以及与 AdaptiveQueue 的交互。在保持该类非阻塞行为的同时,对比短暂 sleep 和可配置的等待策略。完成的标准是:stream 在等待数据时不再消耗过多 CPU。

由索引模型根据 Issue 内容生成。

评估

技术栈
java
领域
performance
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
冷清
描述清晰度
基本清楚
新手友好度
55/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。