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

Fix high memory usage of PeerManagerActor:: add_route_back #3508

Closed
pmnoxx opened this issue Oct 20, 2020 · 5 comments · Fixed by #3522
Closed

Fix high memory usage of PeerManagerActor:: add_route_back #3508

pmnoxx opened this issue Oct 20, 2020 · 5 comments · Fixed by #3522
Assignees

Comments

@pmnoxx
Copy link
Contributor

pmnoxx commented Oct 20, 2020

While investigating memory leaks in Rust code I noticed that memory usage by PeerManager keeps growing.
PeerManager leak is within: (rust)func chain/network/src/lib.rs <near_network::peer_manager::PeerManagerActor as actix::handler::Handler<near_network::types::RoutedMessageFrom>>::handle 5577784d767f: 38.31MiB/22467

After 8-10 hours I saw 22k allocations, which were 38mb total. All those allocations are caused by PeerManaagerActor::routing_table.add_route_back. ROUTE_BACK_CACHE_SIZE size is limited to 1m, which means that by the time it becomes full, it will use around 1.7gb of memory, which is suboptimal.

@pmnoxx pmnoxx self-assigned this Oct 20, 2020
@pmnoxx
Copy link
Contributor Author

pmnoxx commented Oct 20, 2020

@bowenwang1996 @SkidanovAlex Should we decrease ROUTE_BACK_CACHE_SIZE?

@bowenwang1996
Copy link
Collaborator

@mfornet is this expected?

@mfornet
Copy link
Member

mfornet commented Oct 20, 2020

@mfornet is this expected?

I don't doubt it.

We are currently relying in this cache for most of the routed messages!
We will stop overusing this cache after #3088 lands, but this is not in my scope right now. If this is high priority I can try to allocate some time to finish the PR. The core logic is implemented, but some effort is required to make it work with latest changes regarding upgradability.

In the short term, if this is a pressing issue, it should be safe to decrease the size of the cache temporarily, it is very likely that oldest entries are messages from peers that are currently disconnected.

@bowenwang1996
Copy link
Collaborator

bowenwang1996 commented Oct 20, 2020

Okay let's shrink the size to 100k then. @mfornet this shouldn't cause any performance issues right?

@mfornet
Copy link
Member

mfornet commented Oct 20, 2020

Okay let's shrink the size to 100k then. @mfornet this shouldn't cause any performance issues right?

No, it should be fine!

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 a pull request may close this issue.

3 participants