Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement file descriptor budget pool #284

Merged
merged 16 commits into from
Oct 29, 2023

Conversation

biryukovmaxim
Copy link
Collaborator

In this commit, a file descriptor budget pool has been implemented for better allocation of file descriptors. The feature has been added in a new library named "fd_budget_pool".

The implementation uses atomic operations to keep track of acquired file descriptors and ensures that the total number of acquired descriptors never exceeds a system-specific limit. A FDGuard structure was introduced to automatically release the acquired file descriptors when they are no longer in use. The ordering of atomic operations is marked as 'to do' for later optimization considerations. The get_limit function will check the system and determine the maximum allowable file descriptors.

Additionally, tests are written to confirm the correct functioning of the feature. Changes have also been made to Cargo files to include the new library and its dependencies. The ultimate goal of this feature is to prevent system-level issues arising from exhausting file descriptors.

@biryukovmaxim biryukovmaxim force-pushed the fd-budget branch 5 times, most recently from 3fea046 to 5aa7068 Compare September 28, 2023 12:49
@biryukovmaxim biryukovmaxim force-pushed the fd-budget branch 3 times, most recently from bc83246 to 1df6fd7 Compare October 13, 2023 01:37
utils/src/fd_budget.rs Outdated Show resolved Hide resolved
consensus/src/consensus/factory.rs Outdated Show resolved Hide resolved
consensus/src/consensus/factory.rs Show resolved Hide resolved
utils/src/fd_budget.rs Outdated Show resolved Hide resolved
kaspad/src/main.rs Outdated Show resolved Hide resolved
@someone235 someone235 changed the title "Implement file descriptor budget pool" Implement file descriptor budget pool Oct 25, 2023
In this commit, a file descriptor budget pool has been implemented for better allocation of file descriptors. The feature has been added in a new library named "fd_budget_pool".

The implementation uses atomic operations to keep track of acquired file descriptors and ensures that the total number of acquired descriptors never exceeds a system-specific limit. A FDGuard structure was introduced to automatically release the acquired file descriptors when they are no longer in use. The ordering of atomic operations is marked as 'to do' for later optimization considerations. The get_limit function will check the system and determine the maximum allowable file descriptors.

Additionally, tests are written to confirm the correct functioning of the feature. Changes have also been made to Cargo files to include the new library and its dependencies. The ultimate goal of this feature is to prevent system-level issues arising from exhausting file descriptors.
Moved the 'fd_budget_pool' module into the 'utils' module as 'fd_budget'. This was done to consolidate all utility functions into one module to make the codebase cleaner and easier to maintain. This commit involves removal of 'fd_budget_pool' from the workspace and updated the 'Cargo.toml' and 'lib.rs' files accordingly. The code was also refactored to improve error handling.
Many database interfaces were changed to support setting a file descriptor limit upon creation of the DB. This allows better allocation of the total file descriptor budget across the multiple databases instantiated across the system. A utility function was also added to the utils crate to manage the allocation of file descriptors. This will lead to a more stable system under high load and better use of system resources.
The 'rlimit' dependency was added in the Cargo.toml file under the condition that the target architecture is not 'wasm32'. This is to ensure that appropriate resource limits can be set for the given non-wasm32 targets.
Added a 'drop(lt)' function to the 'test_db_relations_store()' function in relations.rs. The function 'lt' was previously created but never used. The new 'drop(lt)' ensures that 'lt' is cleared from memory when it is no longer needed, optimizing the performance and memory usage.
This commit introduces a cleanup phase by clearing services in both core and task runtime. This is done to ensure that all services are dropped and properly disposed of after being used. For the task runtime, this cleanup happens after the async-runtime worker stops. For the core, cleanup occurs once it's shut down. This step further advances the robustness of our termination handling.
The function 'get_limit' in the file 'fd_budget.rs' has been renamed to 'limit' to reflect its getter style and improve the code readability. This change affects the references to 'get_limit' from 'mempool_benchmarks.rs' and 'main.rs' files as well, which are updated accordingly. Additionally, updated the 'fd_total_budget' calculation in 'main.rs' to subtract 32 instead of 64.
The test function in fd_budget.rs was renamed from 'it_works' to 'test_acquire_and_release_guards'. This change was made to better describe the function's purpose and operations. The refined name illustrates that this function tests both the acquisition and release of guards, hence providing clarity to the code.
Modified the fd_budget.rs file to return a fallback value of 512 for unsupported operating systems rather than panicking. This improvement provides better stability for the application when running in different environments.
    Adjusted fd_budget allocation within multiple files to enhance resource utilization across various components of the application. The changes include dividing fd_total_budget equally among active and staging consensuses and assigning fd_budget based on the given limit values in each module. These modifications were implemented to ensure more efficient and fair distribution of resources, and to prevent potential resource allocation issues for unsupported operating systems.
kaspad/src/main.rs Outdated Show resolved Hide resolved
The import statement for the fd_budget module was refactored across multiple files for better readability. Instead of directly importing the limit function, the whole fd_budget module is being imported, and calls to limit function are then prefixed with 'fd_budget::'. This provides clearer code structure and facilitates easier tracking of module usage."
@someone235 someone235 merged commit ae7dae3 into kaspanet:master Oct 29, 2023
6 checks passed
smartgoo pushed a commit to smartgoo/rusty-kaspa that referenced this pull request Jun 18, 2024
* "Implement file descriptor budget pool"

In this commit, a file descriptor budget pool has been implemented for better allocation of file descriptors. The feature has been added in a new library named "fd_budget_pool".

The implementation uses atomic operations to keep track of acquired file descriptors and ensures that the total number of acquired descriptors never exceeds a system-specific limit. A FDGuard structure was introduced to automatically release the acquired file descriptors when they are no longer in use. The ordering of atomic operations is marked as 'to do' for later optimization considerations. The get_limit function will check the system and determine the maximum allowable file descriptors.

Additionally, tests are written to confirm the correct functioning of the feature. Changes have also been made to Cargo files to include the new library and its dependencies. The ultimate goal of this feature is to prevent system-level issues arising from exhausting file descriptors.

* "Move fd_budget_pool to utils module"

Moved the 'fd_budget_pool' module into the 'utils' module as 'fd_budget'. This was done to consolidate all utility functions into one module to make the codebase cleaner and easier to maintain. This commit involves removal of 'fd_budget_pool' from the workspace and updated the 'Cargo.toml' and 'lib.rs' files accordingly. The code was also refactored to improve error handling.

* Optimize file descriptor usage across databases.

Many database interfaces were changed to support setting a file descriptor limit upon creation of the DB. This allows better allocation of the total file descriptor budget across the multiple databases instantiated across the system. A utility function was also added to the utils crate to manage the allocation of file descriptors. This will lead to a more stable system under high load and better use of system resources.

* Add 'rlimit' dependency for non-wasm32 targets

The 'rlimit' dependency was added in the Cargo.toml file under the condition that the target architecture is not 'wasm32'. This is to ensure that appropriate resource limits can be set for the given non-wasm32 targets.

* Adjust test_db_relations_store to include drop operation

Added a 'drop(lt)' function to the 'test_db_relations_store()' function in relations.rs. The function 'lt' was previously created but never used. The new 'drop(lt)' ensures that 'lt' is cleared from memory when it is no longer needed, optimizing the performance and memory usage.

* decrease limit for daemon_sanity_test

* use constants defining db file limits

* add fd_total_budget to mempool benchmark

* Add cleanup step to core and task runtime

This commit introduces a cleanup phase by clearing services in both core and task runtime. This is done to ensure that all services are dropped and properly disposed of after being used. For the task runtime, this cleanup happens after the async-runtime worker stops. For the core, cleanup occurs once it's shut down. This step further advances the robustness of our termination handling.

* Refactor 'get_limit' function to 'limit' in 'fd_budget'

The function 'get_limit' in the file 'fd_budget.rs' has been renamed to 'limit' to reflect its getter style and improve the code readability. This change affects the references to 'get_limit' from 'mempool_benchmarks.rs' and 'main.rs' files as well, which are updated accordingly. Additionally, updated the 'fd_total_budget' calculation in 'main.rs' to subtract 32 instead of 64.

* Refactor fd_budget test function name

The test function in fd_budget.rs was renamed from 'it_works' to 'test_acquire_and_release_guards'. This change was made to better describe the function's purpose and operations. The refined name illustrates that this function tests both the acquisition and release of guards, hence providing clarity to the code.

* Make fd_total_budget field private

* Updated fd_budget for unsupported OS fallback

Modified the fd_budget.rs file to return a fallback value of 512 for unsupported operating systems rather than panicking. This improvement provides better stability for the application when running in different environments.

* Modify fd_budget for better resource allocation

    Adjusted fd_budget allocation within multiple files to enhance resource utilization across various components of the application. The changes include dividing fd_total_budget equally among active and staging consensuses and assigning fd_budget based on the given limit values in each module. These modifications were implemented to ensure more efficient and fair distribution of resources, and to prevent potential resource allocation issues for unsupported operating systems.

* "Refactor fd_budget import statement

The import statement for the fd_budget module was refactored across multiple files for better readability. Instead of directly importing the limit function, the whole fd_budget module is being imported, and calls to limit function are then prefixed with 'fd_budget::'. This provides clearer code structure and facilitates easier tracking of module usage."

* add positive check for fd_budget

---------

Co-authored-by: Ori Newman <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants