kaspanet / rusty-kaspa

Kaspa full-node and related libraries in the Rust programming language. This is a stable version at the initial rollout phases.
ISC License
371 stars 118 forks source link

Bounding node RAM -- implementing a cache policy which tracks dynamic data sizes #351

Closed michaelsutton closed 6 months ago

michaelsutton commented 6 months ago

The current cache implementation bounds the number of cached elements by unit count. This works perfectly for constant-size elements, however when dealing with data with varying size (e.g., headers, ghostdag data, relations etc) it suffers from a size-estimation tradeoff -- on the one hand you want to estimate a unit size by its average case so that you allocate enough units for normal node operation, and on the other hand doing so might overfill the RAM when abnormal data arrives.

This pull-request implements a cache policy which includes a tracked mode which tracks dynamic data sizes. This way cache allocations can be monitored accurately resulting in tight management of resources also under abnormal conditions. The cache can now define a hard-bound limit in bytes and inserted/removed elements are tracked in real-time by their actual runtime memory requirements.

Remaining tasks:

coderofstuff commented 6 months ago

Fixes https://github.com/kaspanet/rusty-kaspa/issues/352