storage: zero-copy BidiReadObjectResponse parsing and off-loop CRC32C verification for async multi-range reads
維護者通常 1 天內回覆
@chandra-siri 已經在處理了。
開始於 2026年10月12日。
評估
這個 Issue 還沒有評估資料。
描述
Summary of the feature request
AsyncMultiRangeDownloader reads from Rapid (zonal) buckets over the BidiReadObject gRPC stream. Per process, throughput is bound by the asyncio event-loop thread: every 2 MiB BidiReadObjectResponse is processed on that thread, under the GIL, before the next message can be received, and all streams of a process queue behind it.
Profiling one process reading 16 streams at 2.0 GB/s (c4-standard-192, bucket in the same zone, py-spy on the loop thread) gives 318 ms of loop-thread time per GB:
| Step on the loop thread | ms per GB |
|---|---|
| gRPC receive copy | 123 |
BidiReadObjectResponse.deserialize (upb copies the payload: copy 1) |
69 |
checksummed_data.content (proto-plus returns a new bytes: copy 2) |
58 |
google_crc32c.value() inline |
38 |
| asyncio overhead | 30 |
Two of the three large items are avoidable:
- The payload is copied twice by the generated parser. A parser that reads the message in place over the
bytesobject gRPC hands to the deserializer can give the read path amemoryviewof the received message instead (257 us per 2 MiB message today, 5 us in place). - CRC32C verification runs on the loop thread even though
google-crc32calready releases the GIL for inputs of 1 MiB or more; hashing on a small worker pool overlaps it with the next receive.
Both need google_crc32c.value() to accept a memoryview; today it parses its argument with y# and raises TypeError: argument 1 must be read-only bytes-like object, so a view into the gRPC buffer cannot be verified without copying it back to bytes.
Proposed changes (three PRs, independent except that the parser depends on the google-crc32c release):
- #18626
google-crc32c:value()/extend()/Checksum.update()accept any contiguous bytes-like object; the GIL is released forbytes-owned memory of 1 MiB or more (abytesor amemoryviewof one). - #18627
google-cloud-storage: opt-in zero-copy parser,create_mrd(..., zero_copy=True)(orGOOGLE_CLOUD_STORAGE_ZERO_COPY_BIDI_READ=1); only active when the installedgoogle-crc32ccan hash amemoryview, otherwise the generated parser is used. With it on,buffer.write()receives a read-onlymemoryviewof the received message. - #18628
google-cloud-storage: chunks of 1 MiB or more are hashed on a 2-thread pool and written to their buffer only after the checksum matches, in arrival order; on by default,GOOGLE_CLOUD_STORAGE_CRC32C_OFFLOAD_MIN_BYTES=0restores inline verification.
fsspec/gcsfs is the main consumer of this path and would opt in; its sinks copy from the view into the caller's buffer.
Desired code experience
import io
from google.cloud.storage.asyncio.async_grpc_client import AsyncGrpcClient
from google.cloud.storage.asyncio.async_multi_range_downloader import AsyncMultiRangeDownloader
client = AsyncGrpcClient()
mrd = await AsyncMultiRangeDownloader.create_mrd(
client, "my-rapid-bucket", "my-object", zero_copy=True
)
buffers = [io.BytesIO() for _ in range(4)]
# buffer.write() receives memoryview chunks that alias the received gRPC
# message; BytesIO, binary files and bytearray sinks accept them unchanged.
await mrd.download_ranges([(i * 16 << 20, 16 << 20, buf) for i, buf in enumerate(buffers)])
Off-loop verification needs no code change; it applies to download_ranges with enable_checksum=True.
Expected results
Same machine and bucket, 16 streams per process, 4 x 16 MiB per download_ranges call into preallocated buffers, CRC32C verification on, aggregate GB/s:
| Processes | main |
zero-copy parser (#18627, median of 3 interleaved runs) | off-loop CRC32C (#18628, median of 9) |
|---|---|---|---|
| 1 | 1.55 | 2.62 | about 2.0 for both arms (unchanged) |
| 8 | 9.76 | 11.29 | 8.17 -> 9.59 (+17%, led in 7 of 9 paired runs) |
With all three changes together, one process goes from 1.6 to 3.5 GB/s and eight processes from 9.8 to 13.5 GB/s; loop-thread time per GB drops from 318 ms to 195 ms.
Environment: google-cloud-storage at 053dbc9872ad, google-crc32c 1.9.0 (main arm), grpcio 1.84.0, protobuf 7.36 (upb backend), Python 3.13, c4-standard-192 in us-central1-c.
- 主要語言
- Python
- 星號
- 5.4k
- 分支
- 1.8k
- 平均合併
- 2 天 7 小時
- 30 天內合併 PR
- 173
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
googleapis/google-cloud-python 的其他 Issue
-
firestore: field path with a quoted name ending in a backslash is misparsed可能已有人在做 @sebxt 於 25 天前認領。 未關閉
難度 2/5 1-3 小時 新手友好度 78/100
googleapis/google-cloud-python#18771 ·
維護者通常 1 天內回覆
-
api: spanner type: feature request
難度 2/5 1-3 小時 新手友好度 68/100
googleapis/google-cloud-python#18584 ·
維護者通常 1 天內回覆
-
auth: `impersonated_credentials` loses `subject` on copy, so `with_scopes()` and `with_quota_project()` turn off domain wide delegation可能已有人在做 @Om-singhaI 於 55 天前認領。 未關閉auth priority: p2 type: bug
難度 2/5 1-3 小時 新手友好度 88/100
googleapis/google-cloud-python#18428 ·
維護者通常 1 天內回覆
-
A client called `run_in_transaction` be stuck if Spanner is down可能已有人在做 @founderinaction 於 7 天前認領。 未關閉priority: p2 type: bug
難度 2/5 1-3 小時 新手友好度 72/100
googleapis/google-cloud-python#18375 · 1 則留言 ·
維護者通常 1 天內回覆
-
ci: enable --strict flag in presubmit twine_check可能重新可做 @ohmayr 於 44 天前認領,目前沒有進行中的 PR。 未關閉
難度 1/5 1 小時以內 新手友好度 76/100
googleapis/google-cloud-python#18339 · 1 則留言 · 已指派 1 人 ·
維護者通常 1 天內回覆
查看 googleapis/google-cloud-python 的全部 Issue
相似的 Issue
-
plot_graph crashes when a mesh node has no m2m edge可能已有人在做 @tygvi 今天認領。 未關閉
難度 2/5 1-3 小時 新手友好度 78/100
mllam/neural-lam#883 · 1 則留言 ·
維護者通常 2 天內回覆
-
enhancement possible-duplicate
難度 1/5 1-3 小時 新手友好度 78/100
AOSSIE-Org/PictoPy#1715 · 2 則留言 ·
維護者通常 6 天內回覆
-
SQLite connector omits generated columns from the catalog, and drops relationships sourced on them未關閉
難度 2/5 1-3 小時 新手友好度 72/100
NVIDIA/auto-ontology#511 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 72/100
ethereum/execution-specs#3996 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 62/100
cpp-best-practices/project_validator#267 ·
維護者通常 1 天內回覆