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

Default rpcthreads value (4) is too small #29386

Closed
1 task done
dpc opened this issue Feb 5, 2024 · 1 comment · Fixed by #31215
Closed
1 task done

Default rpcthreads value (4) is too small #29386

dpc opened this issue Feb 5, 2024 · 1 comment · Fixed by #31215

Comments

@dpc
Copy link

dpc commented Feb 5, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Current behaviour

I keep having to increase rpcthreads about everywhere I'm using bitcoind because without it it's not very robust/performant.

Pasting verbatim my comment in bdk that just hit the same issue:

From a perspective of most workloads e.g. asking for blockchain data, bitcoind (and electrs) acts very much like database software, e.g. posgresql. Postgresql is an interesting case because it utilizes process-based model - meaning it will spawn not just a thread, but a whole process for every client connection - waaay heavier than just a thread.

Even for that heavy model, the recommendations will be to limit it around around 500.

It takes many threads to saturate modern IO device. Just an example from a yt video I had on hand benchamarking filesystems. Each bar is number of workers. And these are dedicated IO-generating workers, generating heavy load in a tight loop. So in this benchmark, it will take like 4 workers. Possibly one worker is even more threads. But an rpc thread in bitcoind by necessity will be spending lots of time reading things and writing stuff to a tcp connection, doing some checks, re-encodings and what not. To actually get a maximum IO performance there will need to be a lot of them. I'd say 64 per core.

On my mostly idle laptop at this very moment there are 2k threads running:

image

On a modern Linux a thread is just a stack, which due to CoW optimizations will really amount to 1 or 2 pages (4K page size) of physically used memory plus a tiny (1K?) amount to track it all in the kernel.

There's really not much to save on thread counts in a grand scheme of things.

Personally, I like to run as lots and lots of tests in parallel, especially any sort of integration and e2e tests, which tend to have lots of dead time - waiting for stuff (like disk and network IO - latency-bound things). The usual limit to this is the available memory. Additional benefit is also that it tends to expose problems more often, as all operations tend to have more ... timing jitter.

So I'm really surprised that the default in bitcoind is 4. That's too little even for an old generation raspberry pi.

I just noticed the comment in the code:

For each thread a thread stack needs to be allocated. By default on Linux,
threads take up 8MiB for the thread stack on a 64-bit system, and 4MiB in a
32-bit system.

Only 8MiB of Virtual Memory is allocated, which doesn't really mean anything. Due to CoW mechanism, only the parts of stack that are being used will be allocated as Physical Memory which is the one that actually matters.

Expected behaviour

NA

Steps to reproduce

NA

Relevant log output

NA

How did you obtain Bitcoin Core

Other

What version of Bitcoin Core are you using?

na

Operating system and version

na

Machine specifications

Linux

@vasild
Copy link
Contributor

vasild commented Nov 4, 2024

See #31215

achow101 added a commit that referenced this issue Dec 30, 2024
…queue

e56fc7c rpc: increase the defaults for -rpcthreads and -rpcworkqueue (Vasil Dimov)

Pull request description:

  `rpcthreads` was introduced with a default of 4 in 2013 in 21eb5ad

  `rpcworkqueue` was introduced with a default of 16 in 2015 in 40b556d

  Resolves: #29386

  ---

  Just bump the ancient default values. There is no perfect default that would fit everybody. This could lead to https://bikeshed.com/

ACKs for top commit:
  achow101:
    ACK e56fc7c
  andrewtoth:
    ACK e56fc7c
  storopoli:
    ACK e56fc7c
  tdb3:
    ACK e56fc7c

Tree-SHA512: ba3ea7392fda57950daa6b4c4d38ecdef9eebe5e786824d25f8b5cea03e760ffff7f77f3acd8eb6c6178b1e92b282e02cabb940ed7222eec7f73efdb819eef06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants