-
Notifications
You must be signed in to change notification settings - Fork 278
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
pool.js::getHost() is CPU hungry #220
Comments
Currently, pool::getHost() uses a fixed loop of 0-99 regardless of how many hosts it has in it's lists so it can use a percentage to factor in whether it should use an entry or not. Using network regtest and a single host of 127.0.0.1:14038, hsd burns a lot of CPU when refilling peers and this blocks incoming requests so much it times out. This is less noticeable the more hosts you have. Instead, calculate how many hosts we have in our list and then the percentage of each index for it. We can then iterate a much smmaller list using the same percentage calculations. This brings CPU utlisation on my NetBSD Xen DOMU on regtest with one host from 100% to 6% and connecting 4 to peers on testnet from 85% to 8%, allowing RPC commands to now work. Fixes handshake-org#220.
Definitions
SummaryIn it's current form, the Pool will continuously try to connect to peers when it does not A way to fix this problem is to use less iterations in It requires an IP address to get an entry into the Based on personal experience, I would never see more than ~25 iterations on Bitcoin mainnet Solutions
|
This is best observable on regtest where constant connections to 127.0.0.1:14038 are observed and always fail.
Near the top of the function we have this code:
All 100 iteratrions are made. This takes on average almost 2 seconds on my machine. Then multiply this by the need to fill 8 spots causes the CPU to peg 100% and many rpc calls then fail. My test case is wallet creation - generally the hsw rpc will timeout way before hsd actually logs the request to create it.
this.hosts.getHost() looks expensive to call 100 times. Maybe a better approach would be to have a function this.hosts.getRandomList(maxHosts) which does a similar job but just returns a list of a maximal number of hosts and iterate that rather than a forced 100 loop alll the time.
The text was updated successfully, but these errors were encountered: