feat(config): replace hardcoded thread defaults with dynamic CPU detection - #1242
feat(config): replace hardcoded thread defaults with dynamic CPU detection#1242glottologist wants to merge 6 commits into
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (4)
💤 Files with no reviewable changes (2)
📝 WalkthroughWalkthroughReplace hardcoded thread/concurrency defaults with dynamic CPU-based calculations; remove explicit CPU packing and VDF thread-limit entries from TOML templates so runtime defaults apply; add helper functions and tests for thread-count behavior and adjust serde defaults for VDF config. ChangesConfig runtime and templates
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
Implement Dynamic Thread Detection for VdfNodeConfig and LocalPackingConfig — Design PlanMode: Feature Problem Statement
Architecture & ApproachShared helper function. A single pure function This mirrors the existing Serde integration. Config templates updated. Mainnet and testnet TOML templates drop the explicit Test configs adapt. ComponentsModified
No external dependencies added
Trade-offs
Out of Scope
Verification
|
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
docker/agent_cluster/configs/irys-1.toml (1)
59-61:⚠️ Potential issue | 🟡 MinorAdd explicit
cpu_packing_concurrencylimits back to the fixture TOMLs—no compose-side CPU caps are present.The three-node cluster in
docker/agent_cluster/docker-compose.yamlruns without per-container CPU limits (nocpus,cpuset, orcpu_quotadirectives). Withcpu_packing_concurrencyremoved from the configs, each node will default toavailable_parallelism() - 4and can oversubscribe the host.Restore explicit low concurrency values in
[packing.local](e.g.,cpu_packing_concurrency = 1or2) for the agent cluster and data-sync fixture TOMLs to prevent resource contention during testing on shared hosts. Alternatively, add CPU limits to each service in the compose manifests.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@docker/agent_cluster/configs/irys-1.toml` around lines 59 - 61, The [packing.local] section removed cpu_packing_concurrency which lets each node default to available_parallelism()-4 and can oversubscribe hosts; restore an explicit low limit (e.g., add cpu_packing_concurrency = 1 or 2) inside the [packing.local] table in this TOML (and the other agent-cluster and data-sync fixture TOMLs) to cap packing concurrency, or alternatively add per-service CPU limits in the docker-compose manifests; update the cpu_packing_concurrency setting for the relevant fixture configs and ensure the same low value is applied across the three-node cluster to prevent resource contention.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@crates/types/src/config/node.rs`:
- Around line 1013-1014: Take a single dynamic snapshot of
default_thread_count(4) in each NodeConfig builder and reuse it for both packing
and VDF concurrency fields instead of calling default_thread_count(4) twice;
e.g. in NodeConfig::testing_with_signer and NodeConfig::testnet compute let
thread_count = u16::try_from(default_thread_count(4)).unwrap_or(u16::MAX) (or
keep the intermediate usize and convert once) and assign that value to
cpu_packing_concurrency and cpu_vdf_concurrency (and the other duplicated sites
at the referenced locations) to remove duplicate conversion logic and keep the
defaults aligned.
---
Outside diff comments:
In `@docker/agent_cluster/configs/irys-1.toml`:
- Around line 59-61: The [packing.local] section removed cpu_packing_concurrency
which lets each node default to available_parallelism()-4 and can oversubscribe
hosts; restore an explicit low limit (e.g., add cpu_packing_concurrency = 1 or
2) inside the [packing.local] table in this TOML (and the other agent-cluster
and data-sync fixture TOMLs) to cap packing concurrency, or alternatively add
per-service CPU limits in the docker-compose manifests; update the
cpu_packing_concurrency setting for the relevant fixture configs and ensure the
same low value is applied across the three-node cluster to prevent resource
contention.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: c0debc11-b2b0-4b32-b9f7-8bfaf16981fa
📒 Files selected for processing (12)
crates/config/templates/mainnet_config.tomlcrates/config/templates/testnet_config.tomlcrates/types/src/config/mod.rscrates/types/src/config/node.rsdocker/agent_cluster/configs/irys-1.tomldocker/agent_cluster/configs/irys-2.tomldocker/agent_cluster/configs/irys-3.tomldocker/configs/irys-1.tomldocker/configs/irys-2.tomldocker/tests/data-sync/configs/irys-1.tomldocker/tests/data-sync/configs/irys-2.tomldocker/tests/data-sync/configs/irys-3.toml
💤 Files with no reviewable changes (5)
- docker/configs/irys-2.toml
- docker/configs/irys-1.toml
- crates/config/templates/mainnet_config.toml
- crates/config/templates/testnet_config.toml
- crates/types/src/config/mod.rs
|
Benchmark results: https://irys-xyz.github.io/irys/dev/bench/1242%2Fmerge/index.html |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@docker/tests/data-sync/configs/irys-2.toml`:
- Line 61: Add an inline comment next to the cpu_packing_concurrency = 2 setting
explaining why this Docker test fixture pins CPU packing to 2 (e.g., to keep
deterministic CI behavior, avoid oversubscription on small test runners, or to
match downstream service limits) so future maintainers understand why it
overrides the new dynamic defaults; update the irys-2.toml entry for
cpu_packing_concurrency with a concise one-line rationale referencing
CI/determinism or hardware constraints.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 99819455-8cbd-4dea-8d70-8a87357aa1f5
📒 Files selected for processing (6)
docker/agent_cluster/configs/irys-1.tomldocker/agent_cluster/configs/irys-2.tomldocker/agent_cluster/configs/irys-3.tomldocker/tests/data-sync/configs/irys-1.tomldocker/tests/data-sync/configs/irys-2.tomldocker/tests/data-sync/configs/irys-3.toml
9919948 to
f8c67ab
Compare
Summary
Before:
cpu_packing_concurrencyandparallel_verification_thread_limitwere hardcoded to fixed values (2 and 4 respectively), with TODO comments noting they should derive from CPU count. Operators on machines with more or fewer cores than expected got suboptimal defaults. TheVdfNodeConfigstruct required an explicit[vdf]section in TOML — omitting it caused deserialisation failure.After:
Both fields default to
max(1, available_cpus - 4)at runtime viastd::thread::available_parallelism(). The[vdf]section andcpu_packing_concurrencyfield are now optional in TOML configs, falling back to the dynamic default when omitted.Changes
Core helpers (
crates/types/src/config/node.rs)thread_count_with_reserve(available, reserved)— pure function:available.saturating_sub(reserved).max(1)default_thread_count(reserved)— wrapper that readsavailable_parallelism()and delegates to the pure functionLocalPackingConfig::default()to usedefault_thread_count(4)forcpu_packing_concurrencyVdfNodeConfig::default()to usedefault_thread_count(4)forparallel_verification_thread_limit#[serde(default)]at struct level onVdfNodeConfigso the entire[vdf]section becomes optionaltesting_with_signer()andtestnet()constructors to use the dynamic helperConfig templates
cpu_packing_concurrency = 4frommainnet_config.tomlandtestnet_config.toml[vdf]/parallel_verification_thread_limit = 4sections from both templatesDocker configs (8 files)
cpu_packing_concurrencyandparallel_verification_thread_limitfrom all docker config files underdocker/configs/,docker/agent_cluster/configs/, anddocker/tests/data-sync/configs/Tests
thread_count_with_reserve: always >= 1, correct subtraction, floor at 1[vdf]section deserialisation (onlycore_pinningpresent)config/mod.rsto omit the now-optional fieldsTechnical Notes
thread_count_with_reservefunction is separated from the system call wrapper to enable property-based testing without mocking.Testing
[vdf]section deserialisation regression testcargo xtask checkcompiles cleanlyRelated
Summary by CodeRabbit
Enhancements
Chores