-
Notifications
You must be signed in to change notification settings - Fork 418
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
Actually wait for threads in RPC. #233
Merged
Merged
Conversation
This file contains 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
This change implements non-blocking cleanup of threads. It achieves it by cleaning up periodically based on thread ID, that gets sent from dead thread over a channel. Aside from internal locks in the channel, there are no other locks. The cleanup also happens only after a new connection is accepted, but hopefully won't be an issue, unless there are many connections that die and then nothing connects for a long time. A final cleanup happens when the thread is finishing.
Many thanks! |
shesek
added a commit
to shesek/electrs
that referenced
this pull request
Mar 18, 2024
Changes were taken from the latest romanz/electrs rpc.rs implementation prior to the major refactoring in v0.9.0 that significantly diverged from our fork (https://github.com/romanz/electrs/blob/af6ff09a275ec12b6fd0d6a101637f4710902a3c/src/rpc.rs). The relevant changes include (not a complete list): romanz#284 romanz#233 romanz@a3bfdda romanz#195 romanz#523 (only post-v0.9 change, a very minor one) This fixes a memory leak that could be reproduced using the following script, which opens and closes 500k connections with a concurrency of 20: $ seq 1 500000 | xargs -I {} -n 1 -P 20 sh -c 'echo '\''{"id":{},"method":"server.version","params":[]}'\''| nc 127.0.0.1 50001 -v -N' Before the fixes, memory usage would continue to grow the more connections are made, up to 35MB for 500k connections. After the fixes, memory usage is steady at around 25MB and doesn't grow with more connections.
shesek
added a commit
to shesek/electrs
that referenced
this pull request
Mar 18, 2024
Changes were taken from the latest romanz/electrs rpc.rs implementation prior to the major refactoring in v0.9.0 that significantly diverged the codebases (https://github.com/romanz/electrs/blob/af6ff09a275ec12b6fd0d6a101637f4710902a3c/src/rpc.rs). The relevant changes include (not a complete list): romanz#284 romanz#233 romanz@a3bfdda romanz#195 romanz#523 (only post-v0.9 change, a very minor one) This fixes a memory leak that could be reproduced using the following script, which opens and closes 500k connections with a concurrency of 20: $ seq 1 500000 | xargs -I {} -n 1 -P 20 sh -c 'echo '\''{"id":{},"method":"server.version","params":[]}'\''| nc 127.0.0.1 50001 -v -N' Before the fixes, memory usage would continue to grow the more connections are made, up to 35MB for 500k connections. After the fixes, memory usage is steady at around 25MB and doesn't grow with more connections.
shesek
added a commit
to shesek/electrs
that referenced
this pull request
Mar 18, 2024
Changes were taken from the latest romanz/electrs rpc.rs implementation prior to the major refactoring in v0.9.0 that significantly diverged the codebases (https://github.com/romanz/electrs/blob/af6ff09a275ec12b6fd0d6a101637f4710902a3c/src/rpc.rs). The relevant changes include (not a complete list): romanz#284 romanz#233 romanz@a3bfdda romanz#195 romanz#523 (only post-v0.9 change, a very minor one) This fixes a memory leak that could be reproduced using the following script, which opens and closes 500k connections with a concurrency of 20: $ seq 1 500000 | xargs -I {} -n 1 -P 20 sh -c 'echo '\''{"id":{},"method":"server.version","params":[]}'\''| nc 127.0.0.1 50001 -v -N' Before the fixes, memory usage would continue to grow the more connections are made, to around 35MB for 500k connections. After the fixes, memory usage is steady at around 25MB and doesn't grow with more connections.
shesek
added a commit
to shesek/electrs
that referenced
this pull request
Mar 25, 2024
Changes were taken from the latest romanz/electrs rpc.rs implementation prior to the major refactoring in v0.9.0 that significantly diverged the codebases (https://github.com/romanz/electrs/blob/af6ff09a275ec12b6fd0d6a101637f4710902a3c/src/rpc.rs). The relevant changes include (not a complete list): romanz#284 romanz#233 romanz@a3bfdda romanz#195 romanz#523 (only post-v0.9 change, a very minor one) This fixes a memory leak that could be reproduced using the following script, which opens and closes 500k connections with a concurrency of 20: $ seq 1 500000 | xargs -I {} -n 1 -P 20 sh -c 'echo '\''{"id":{},"method":"server.version","params":[]}'\''| nc 127.0.0.1 50001 -v -N' Before the fixes, memory usage would continue to grow the more connections are made, to around 35MB for 500k connections. After the fixes, memory usage is steady at around 25MB and doesn't grow with more connections.
philippem
pushed a commit
to philippem/electrs
that referenced
this pull request
May 16, 2024
Changes were taken from the latest romanz/electrs rpc.rs implementation prior to the major refactoring in v0.9.0 that significantly diverged the codebases (https://github.com/romanz/electrs/blob/af6ff09a275ec12b6fd0d6a101637f4710902a3c/src/rpc.rs). The relevant changes include (not a complete list): romanz#284 romanz#233 romanz@a3bfdda romanz#195 romanz#523 (only post-v0.9 change, a very minor one) This fixes a memory leak that could be reproduced using the following script, which opens and closes 500k connections with a concurrency of 20: $ seq 1 500000 | xargs -I {} -n 1 -P 20 sh -c 'echo '\''{"id":{},"method":"server.version","params":[]}'\''| nc 127.0.0.1 50001 -v -N' Before the fixes, memory usage would continue to grow the more connections are made, to around 35MB for 500k connections. After the fixes, memory usage is steady at around 25MB and doesn't grow with more connections.
philippem
pushed a commit
to philippem/electrs
that referenced
this pull request
May 16, 2024
Changes were taken from the latest romanz/electrs rpc.rs implementation prior to the major refactoring in v0.9.0 that significantly diverged the codebases (https://github.com/romanz/electrs/blob/af6ff09a275ec12b6fd0d6a101637f4710902a3c/src/rpc.rs). The relevant changes include (not a complete list): romanz#284 romanz#233 romanz@a3bfdda romanz#195 romanz#523 (only post-v0.9 change, a very minor one) This fixes a memory leak that could be reproduced using the following script, which opens and closes 500k connections with a concurrency of 20: $ seq 1 500000 | xargs -I {} -n 1 -P 20 sh -c 'echo '\''{"id":{},"method":"server.version","params":[]}'\''| nc 127.0.0.1 50001 -v -N' Before the fixes, memory usage would continue to grow the more connections are made, to around 35MB for 500k connections. After the fixes, memory usage is steady at around 25MB and doesn't grow with more connections.
shesek
added a commit
to Blockstream/electrs
that referenced
this pull request
May 17, 2024
Changes were taken from the latest romanz/electrs rpc.rs implementation prior to the major refactoring in v0.9.0 that significantly diverged the codebases (https://github.com/romanz/electrs/blob/af6ff09a275ec12b6fd0d6a101637f4710902a3c/src/rpc.rs). The relevant changes include (not a complete list): romanz#284 romanz#233 romanz@a3bfdda romanz#195 romanz#523 (only post-v0.9 change, a very minor one) This fixes a memory leak that could be reproduced using the following script, which opens and closes 500k connections with a concurrency of 20: $ seq 1 500000 | xargs -I {} -n 1 -P 20 sh -c 'echo '\''{"id":{},"method":"server.version","params":[]}'\''| nc 127.0.0.1 50001 -v -N' Before the fixes, memory usage would continue to grow the more connections are made, to around 35MB for 500k connections. After the fixes, memory usage is steady at around 25MB and doesn't grow with more connections.
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.
Important: untested suggestion of how to solve the problem!
This change implements non-blocking cleanup of threads. It achieves it
by cleaning up periodically based on thread ID, that gets sent from dead
thread over a channel. Aside from internal locks in the channel, there
are no other locks. The cleanup also happens only after a new connection
is accepted, but hopefully won't be an issue, unless there are many
connections that die and then nothing connects for a long time. A final
cleanup happens when the thread is finishing.