[Bug] BanyanDB stream query on a hot entity scans all its rows despite a small limit
Maintainer thường phản hồi trong vòng 1 ngày
@hanahmily đang làm issue này rồi.
Từ ngày 23/11/2026.
Đánh giá
Issue này chưa được đánh giá.
Mô tả
Search before asking
- I had searched in the issues and found no similar issues.
Apache SkyWalking Component
BanyanDB (apache/skywalking-banyandb)
What happened
On a Kubernetes cluster, a log query for a hot service gets slower as the time range grows, even with limit 20. From a 5-hour range up, it fails with query memory pool exhausted. A cold service with the same query stays at a few milliseconds whatever the range.
Environment:
- BanyanDB
8d577edf(2026-11-18, after apache/skywalking-banyandb#1483). It includes apache/skywalking-banyandb#1433, the fix for #14165. - Cluster mode on Kubernetes: 2 liaison, 2 hot, 2 warm and 1 cold data nodes. Data node limits: 4 CPU, 4 GiB memory. Per-query allowance: 96 MiB (
100663296bytes). - Group
sw_recordsLog, streamlog,shardNum: 2, 1-day segments. The entity isservice_id + service_instance_id.
Data distribution over the last hour: 90,381 rows across 22 services, very skewed.
| service | share | rows / hour |
|---|---|---|
| otel-demo::frontend-proxy | 48.5% | ~44,000 |
| otel-demo::product-catalog | 15.4% | ~14,000 |
| otel-demo::cart | 4.4% | ~4,000 |
| otel-demo::payment | 0.32% | ~290 |
| otel-demo::email | 0.16% | ~146 |
Query, shaped like OAP's log query: service_id = X, ORDER BY timestamp DESC, limit 20, projecting service_id, service_instance_id, timestamp, content_type, unique_id, endpoint_id, trace_id, content, tags. Each value is the p50 of 20 runs after 2 warm-up runs. These are client-side numbers through kubectl port-forward, so each one includes about 70 ms of network round trip (the "absent key" row is that floor).
| service | 1h | 2h | 3h | 4h | 5h | 6h | 24h |
|---|---|---|---|---|---|---|---|
| frontend-proxy (48%) | 215 ms | 409 ms | 669 ms | 966 ms | FAIL | FAIL | FAIL |
| product-catalog (15%) | 120 ms | 344 ms | 1,120 ms | ||||
| cart (4.4%) | 89 ms | 150 ms | 398 ms | ||||
| payment (0.32%) | 80 ms | 85 ms | 93 ms | ||||
| email (0.16%) | 79 ms | 81 ms | 84 ms | ||||
| absent key | 75 ms | 73 ms | 73 ms |
Every successful query returns exactly 20 rows. The cost follows how many rows the entity has in the range, not the limit. frontend-proxy fails between 4h (~176k rows) and 5h (~220k rows):
rpc error: code = ResourceExhausted desc = query memory pool exhausted: code: STATUS_RESOURCE_EXHAUSTED,
msg: execute the query plan for stream log: stream query on node data-hot-1:17912:
scan on node data-hot-1:17912 failed: code: STATUS_RESOURCE_EXHAUSTED,
msg: query memory pool exhausted: per_query_limit (limit 100663296 bytes, used 97115920, requested 4603598)
Server-side trace (trace: true, 3h range, limit 20):
| service | stream-grpc total | data-hot-0 | data-hot-1 | warm-0 / warm-1 |
|---|---|---|---|---|
| frontend-proxy | 432.3 ms | 11.9 ms (series matched=0) | 418.0 ms (series matched=1) | 10.3 ms |
| 7.2 ms | 4.3 ms (series matched=1) | 0.9 ms (series matched=0) | 0.1 ms |
The two queries differ by about 60 times on the server. Almost all of frontend-proxy's time is on data-hot-1.
Other variants we tried for frontend-proxy:
- With
orderByremoved, it still fails at 6h and 24h (used 100433919, requested 1220999). - With the projection cut to
service_id, timestamp, it still fails at 6h and 24h. So the memory is not driven by the projected columns; the time spent and the memory charged both follow the hot series' row count. - The 24h range also fails under every variant. Smaller services slow down in proportion: product-catalog takes 1.12 s at 24h, about 13 times email.
Because the hot entity is one series, the whole load lands on one shard and one node (hot-1) while hot-0 stays idle. Adding shards does not help this case.
What you expected to happen
A limit N query ordered by time should stop once it has the top N rows. Its latency and memory should stay close to the cold-service case, whatever the entity's data volume and the time range:
- Its memory charge should follow
offset + limitplus a bounded number of cursors, not the number of rows the series has in the range. - A hot service's 6h or 24h log query, a common OAP UI action, should not fail with RESOURCE_EXHAUSTED.
How to reproduce
- Use a stream with a low-cardinality entity (for example
sw_recordsLog/log), and write one entity at about 40k rows per hour (around 12 rows per second) for 6 hours or more. - Send
service_id = <hot>,ORDER BY timestamp DESC,limit 20for 1h, 2h, 4h, 5h and 6h ranges. - Latency grows with the range, and the query fails with
per_query_limitat around 200k matched rows under the 96 MiB per-query allowance. - Compare with a cold entity (around 150 rows per hour) and the same query: it stays at a few milliseconds on the server.
Anything else
This happens every time once the time range is past about 5h for frontend-proxy.
Relation to #14165: #14165 (fixed by apache/skywalking-banyandb#1433) made the lease refund a block's charge once its cursor is released and a batch's charge once the merge prunes it. The cluster runs a build with that fix, and the query still fails. So the refund is not enough here:
- The comment on
streamVecScaninbanyand/stream/query_vectorized.gosays the scan emits every matching row and does not stop atMaxElementSize; top-N is applied after the merge. That would explain why latency grows linearly (we see it from 1h to 4h): every block of the hot series in the range is decoded even when only 20 rows are kept. - We suspect the memory comes from how the parts are laid out. An
ORDER BY ts DESCmerge has to keep the current block of every part (and every segment) that overlaps the range. A hot series has large blocks (the failing request asked for ~4.6–6.5 MB for one block), so a dozen or so overlapping parts reach the 96 MiB allowance. We could not inspect the part layout on the data node, so this is not confirmed.
Possible directions:
- Use block metadata (
minTimestamp/maxTimestamp) to stop early: once N rows are held, skip blocks or parts whose time range cannot beat the current Nth row. - Read parts in time order for a single series instead of opening a cursor on every part at the same time.
Are you willing to submit a pull request to fix on your own?
- Yes I am willing to submit a pull request on my own!
Code of Conduct
- I agree to follow this project's Code of Conduct
- Ngôn ngữ chính
- Java
- Star
- 25k
- Fork
- 6.6k
- Merge trung bình
- 10 giờ 45 phút
- Pull request đã merge (30 ngày)
- 49
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
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.
Issue khác của apache/skywalking
-
[Bug] [BanyanDB] timestamp.ParseDuration silently drops everything after "d"Có thể đã có người làm @soujasK đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 83/100
apache/skywalking#14287 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[BanyanDB] Let trace queries exclude the raw span from resultsCó thể đã có người làm @hanahmily đã nhận hôm nay. Đang mởenhancement
apache/skywalking#14288 · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[BanyanDB] Data race and nil-pointer panic: measure write during standalone shutdown after segment closeCó thể đã có người làm @hanahmily đã nhận hôm nay. Đang mởbug
apache/skywalking#14285 · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 20/100
apache/skywalking#14283 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[BanyanDB] Store trace binary tags only in core storage, not in secondary index (sidx)Có thể đã có người làm @hanahmily đã nhận hôm nay. Đang mởenhancement
apache/skywalking#14282 · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của apache/skywalking
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
testng-team/testng#3672 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
eclipse-edc/IdentityHub#1296 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 80/100
cloudfoundry/uaa#4194 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
ui: 進捗状況線ダイアログが日本語表示で英語のままĐang mởarea: ui priority: medium
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 83/100
tetsuji16/microProject#1721 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 2 ngày