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

Memory leaks in long-running processes #5981

Open
mfornos opened this issue Sep 16, 2024 · 3 comments
Open

Memory leaks in long-running processes #5981

mfornos opened this issue Sep 16, 2024 · 3 comments
Labels
P2 - Medium Important but not urgent. Enhances functionality and value, scheduled after higher priorities. Performance Optimizations to boost SDK speed, reduce latency, and enhance memory efficiency.

Comments

@mfornos
Copy link
Contributor

mfornos commented Sep 16, 2024

It's known that using the Polkadot.js API library in long-running processes, such as on a Node.js backend, results in increasing memory consumption until the process crashes due to memory leaks.

Below is a summary of the major memory leaks and how to fix them:

  1. Well-known memory leak in @polkadot/rpc-core storage cache:
    Memory leak in ApiPromise timers #5674 (comment)
    Patch: Link

  2. Function memoization used across the library via the memo utility:

    export function memo <T> (instanceId: string, inner: Function): Memoized<ObsFn<T>> {

    Further investigation is needed to identify the leaky usage. As a quick fix, patch the memoize function in @polkadot/util:
    Patch: Link

  3. LRU cache in @polkadot/rpc-provider:
    The custom LRU cache implementation is not being properly evicted. Supposedly fixed in Fix LRUCache memory leak. #4520, but it still leaks in long-running processes. As a workaround, disable the cache:
    Patch: Link

Applying these patches will significantly reduce memory consumption and help maintain a stable footprint for your Node.js long-running processes using Polkadot.js.

We would like to investigate these issues in more detail, but due to other priorities, we currently don't have the time.

@TarikGul
Copy link
Member

Thanks for all the info above, that is super helpful!

cc: @filvecchiato (Since he has been working closely with performance issues in sidecar and PJS recently).

I think this is definitely something we can tackle very soon and get to the bottom of.

@TarikGul
Copy link
Member

rel: #5997

Progress has been made and is released in 14.1.1, but there is definitely more work to be done.

@TarikGul TarikGul added P2 - Medium Important but not urgent. Enhances functionality and value, scheduled after higher priorities. Performance Optimizations to boost SDK speed, reduce latency, and enhance memory efficiency. labels Oct 29, 2024
@shunjizhan
Copy link
Contributor

It would be nice to have some config to control cache size, which benefits long running apps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P2 - Medium Important but not urgent. Enhances functionality and value, scheduled after higher priorities. Performance Optimizations to boost SDK speed, reduce latency, and enhance memory efficiency.
Projects
Development

No branches or pull requests

3 participants