All lessons · CKB node, RPC and indexer · Start here · Glossary
Reuse one CkbRpcClient across a loop instead of building one per itemWorkingFrom one fix
From one fix · Check: right · Checked 2026-11-19
Constructing a ckb_sdk CkbRpcClient (CkbRpcClient::with_builder) loads the TLS root store, about 6 ms of CPU each time. In Fiber's watchtower, building one per watched channel made a round over 11,496 channels take 93 to 115 s; building one client before the loop and passing &CkbRpcClient cut it to 5 to 7 s.
Why it matters: Building a new ckb_sdk CkbRpcClient for every item reloads the TLS root store each time, about 6 ms of CPU per item. Over 11,496 watched channels that stretched one watchtower round from 5 to 7 s to 93 to 115 s.
Pattern
let ckb_client = CkbRpcClient::with_builder(&rpc_url, |builder| { builder.timeout(CKB_RPC_TIMEOUT).no_proxy() }) (built once, before the for loop over watched channels)Taken from the commit, shortened.
- Concepts
- Network and RPC reliability
- Evidence
- From one fix: from one project, checked against its commit
- First seen
- 2026-11-03
- Last changed
- 2026-11-03
- Last checked
- 2026-11-19
- Check against the commit
- right: the lesson follows from its commit and still holds in the code today
Sources (1)
- 2026-11-03 · nervosnetwork/fiber · more from this project
More about CKB node, RPC and indexer
- get_live_cell may return "unknown" rather than "dead" for a spent output
- get_transaction returns an object with a null transaction for rejected and unknown txs
- send_transaction error -1111 (PoolRejectedRBF) is a conflict, not "already in pool"
Do you maintain a project this lesson came from? Confirm or correct it
Cite this lesson
LusoCryptoLabs, "Reuse one CkbRpcClient across a loop instead of building one per item", CKB lessons, https://pulse.lusocryptolabs.com/learned/node/reuse-one-ckbrpcclient-across-a-loop-instead-of-building-one, CC BY 4.0, last changed 2026-11-03.