Enhance netutils and network modules for performance and stability#6
Open
mikecovlee wants to merge 3 commits into
Open
Enhance netutils and network modules for performance and stability#6mikecovlee wants to merge 3 commits into
mikecovlee wants to merge 3 commits into
Conversation
…ility - Bump server version from 2.2 to 2.3 in netutils.ecs. - Introduce new polling sleep durations for worker fibers to manage backpressure. - Replace bare fiber.yield() calls with fiber.sleep_for() for better control over idle states. - Enhance logging for slave worker availability and connection issues. - Implement graduated wait strategy in network.cpp to reduce busy-waiting and improve responsiveness. - Ensure compatibility with CovScript SDK version 260701 or higher. - Add functions for optimal scheduling and resource management in http_server class. - Refactor shutdown procedures to ensure graceful termination of async jobs.
There was a problem hiding this comment.
Pull request overview
This PR updates the network C++ extension and the netutils CovScript module to reduce idle CPU usage and improve shutdown stability by introducing graduated waiting (spin-then-sleep), adding new build-time tuning knobs, and aligning documentation/versioning with the new behavior.
Changes:
- Implemented graduated waiting in
network.cpp(yieldfor a bounded number of spins, thensleep_for) and applied similar wait/backpressure tweaks innetutilsworker loops. - Added new CMake/README configuration options (
NETWORK_WAIT_SLEEP_MS,NETWORK_FAST_SPIN_COUNT) and updated related documentation. - Updated package versions and regenerated compiled artifacts (
.csp,.csym), plus minor maintenance adjustments.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| README.md | Updates versions and documents new CMake tuning options (and should document the new minimum SDK ABI requirement). |
| network.cpp | Adds graduated wait logic, introduces cs_runtime_sleep_for, and enforces a minimum CovScript SDK ABI version. |
| NETUTILS.md | Updates NetUtils protocol/docs for new worker behavior, shutdown semantics, and defaults. |
| netutils.ecs | Core behavioral changes to event loop, worker backpressure, shutdown re-entrancy handling, and new tuning constants. |
| netutils.csym | Regenerated bytecode module reflecting netutils.ecs changes. |
| netutils.csp | Regenerated compiled package reflecting netutils.ecs changes. |
| docs/async-architecture.md | Documents the new graduated waiting strategy and updated fiber wait behavior. |
| csbuild/network.json | Bumps network package version metadata. |
| csbuild/netutils.json | Bumps netutils package version metadata. |
| CNI_API.md | Updates API docs to reflect graduated wait behavior in safe_shutdown. |
| CMakeLists.txt | Adds new cache options and compile definitions for wait tuning. |
| argparse.csp | Regenerated artifact (timestamp-only change). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Updated README.md to specify the required ABI version for Covariant Script. - Modified netutils.csp and netutils.ecs to enhance shutdown logic in the http_server class, ensuring a full shutdown when all workers terminate unexpectedly. - Adjusted comments for clarity regarding the shutdown process. - Updated netutils.csym to reflect changes in the code structure. - Improved spin-wait logic in network.cpp to prevent overflow and ensure efficient operation.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces several improvements and behavioral changes to the network and netutils modules, focusing on more efficient wait strategies, configuration flexibility, and documentation updates. The most significant changes include the implementation of graduated waiting (spin-then-sleep) in fiber-based event loops, new CMake options to tune wait behavior, and updates to documentation and default parameters to reflect these changes.
Event loop and wait strategy improvements:
Introduced a graduated wait mechanism in fiber environments: the system now performs a configurable number of fast spins (
yieldwithout sleep) before escalating to a short sleep, reducing CPU usage during idle periods. This is reflected in both the implementation and documentation (wait_impl, drain loops, and related fiber code). [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11]All event loop worker fibers in
netutils.cspnow usefiber.sleep_for(IDLE_POLL_MS)instead offiber.yield()when idle, further reducing unnecessary CPU usage. [1] [2] [3] [4]Configuration and tuning:
Added new CMake options
NETWORK_WAIT_SLEEP_MSandNETWORK_FAST_SPIN_COUNTto control the sleep duration and spin count in the graduated wait logic. These are now passed as compile definitions and documented in the README. [1] [2] [3]Updated default values and parameters in
netutils:worker_countfrom 64 to 32 for better resource usage.IDLE_POLL_MS,FAST_POLL_MS, andERROR_RECOVERY_MSfor improved code clarity and maintainability.Documentation and version updates:
network1.38.0_v6.6 andnetutils2.3 in all relevant files. [1] [2] [3] [4] [5] [6]Minor code maintenance:
netutils.cspto useop_callinstead ofcallfor lambda structs, aligning with updated CovScript conventions. [1] [2] [3]safe_shutdownfailures. [1] [2]These changes collectively improve the efficiency, configurability, and clarity of the network stack and its documentation.