ClickHouse / ClickHouse/clickhouse-java

Block in NonBlockingInputStream

Đang mở
#2,297 2 bình luận 0 reaction 0 người được giao Xem trên GitHub
bug client-v1 enhancement
Ngôn ngữ chính
Java
Star
1.6k
Fork
636
Merge trung bình
2 ngày 23 giờ
Pull request đã merge (30 ngày)
29

Mô tả

![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.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Hướng nghiên cứu

Bắt đầu bằng cách đọc clickhouse-data/src/main/java/com/clickhouse/data/stream/NonBlockingInputStream.java, tập trung vào busy loop chờ dữ liệu từ server và sự tương tác với AdaptiveQueue. So sánh việc sleep trong thời gian ngắn với một chiến lược chờ có thể cấu hình, đồng thời vẫn duy trì hành vi không blocking của class. Được xem là hoàn tất khi stream không còn tiêu thụ CPU quá mức trong lúc chờ dữ liệu.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
java
Lĩnh vực
performance
Loại issue
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Ít trao đổi
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
55/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.