I'm having some problems with RPC performance with Bitcoin Core v0.17.1 .
My wallet is a reasonable size, with around 100K addresses and 400K transactions, at first I though it was related to this, but even basic RPC calls that do not use the wallet are taking a very long time:
root@no:~# date; time bitcoin-cli uptime; date
Wed 19 Jun 13:55:13 EDT 2019
2606
real 0m26.249s
user 0m0.000s
sys 0m0.000s
Wed 19 Jun 13:55:39 EDT 2019
It seems that the time is all taken before the call is actually processed. In debug.log, I see this for example:
2019-06-19T17:55:39Z ThreadRPCServer method=uptime
So, the LogPrint in the parse function was not reached until the very end of the 26 second processing time, confirming that it's not the uptime function itself that takes the time, but something that happens before this.
I currently have 4 RPC threads enabled. top shows that one of them is generally busy with 100% CPU use (a single core). Once one finishes, the next one will use 100% CPU, so it would seem that only one request at a time is actually processed despite the 4 threads, although this is hard to verify. strace shows that threads are normally waiting for a futex when they are not using the CPU:
root@no:~# strace -p 22451
strace: Process 22451 attached
futex(0x555b6d8b6260, FUTEX_WAKE_PRIVATE, 1) = 1
write(8, "\1\0\0\0\0\0\0\0",
= 8
futex(0x555b6f63b000, FUTEX_WAKE_PRIVATE, 1) = 1
write(1, "2019-06-19T20:33:27Z ThreadRPCSe"..., 71) = 71
write(4, "2019-06-19T20:33:27Z ThreadRPCSe"..., 71) = 71
futex(0x555b6d8b6260, FUTEX_WAIT_PRIVATE, 2, NULL) = 0
futex(0x555b6d8b6260, FUTEX_WAIT_PRIVATE, 2, NULL) = -1 EAGAIN (Resource temporarily unavailable)
futex(0x555b6d8b6260, FUTEX_WAIT_PRIVATE, 2, NULL) = 0
futex(0x555b6d8b6260, FUTEX_WAKE_PRIVATE, 1) = 1
futex(0x555b6d8b6260, FUTEX_WAIT_PRIVATE, 2, NULL) = 0
futex(0x555b6d8b6260, FUTEX_WAKE_PRIVATE, 1) = 1
write(8, "\1\0\0\0\0\0\0\0",
= 8
write(1, "2019-06-19T20:33:42Z ThreadRPCSe"..., 75) = 75
write(4, "2019-06-19T20:33:42Z ThreadRPCSe"..., 75) = 75
futex(0x555b6d8b6260, FUTEX_WAIT_PRIVATE, 2, NULL) = 0
futex(0x555b6d8b6260, FUTEX_WAIT_PRIVATE, 2, NULL) = 0
futex(0x555b6d8b6260, FUTEX_WAIT_PRIVATE, 2, NULL) = -1 EAGAIN (Resource temporarily unavailable)
futex(0x555b6d8b6260, FUTEX_WAKE_PRIVATE, 1) = 1
futex(0x555b6d8b6260, FUTEX_WAIT_PRIVATE, 2, NULL) = 0
futex(0x555b6d8b6260, FUTEX_WAIT_PRIVATE, 2, NULL) = 0
futex(0x555b6d8b6260, FUTEX_WAKE_PRIVATE, 1) = 1
write(8, "\1\0\0\0\0\0\0\0",
= 8
futex(0x555b6f63b000, FUTEX_WAKE_PRIVATE, 1) = 1
write(1, "2019-06-19T20:33:43Z ThreadRPCSe"..., 75) = 75
write(4, "2019-06-19T20:33:43Z ThreadRPCSe"..., 75) = 75
futex(0x555b6d8b6260, FUTEX_WAIT_PRIVATE, 2, NULL) = 0
futex(0x555b6d8b6260, FUTEX_WAIT_PRIVATE, 2, NULL) = 0
futex(0x555b6d8b6260, FUTEX_WAKE_PRIVATE, 1) = 1
futex(0x555b6d8b6260, FUTEX_WAIT_PRIVATE, 2, NULL^Cstrace: Process 22451 detached
Timing is a little hard to judge, but watching top at the same time seems to bear out that each httpworker is stuck in a futex until it grabs the CPU, writes the log entry, and processes a request, then it stops in a futex again.
The RPC sever is fairly busy, here is the call breakdown over a typical 60-minute period:
root@no:~# grep 2019-06-19T19 debug.log | grep ThreadRPC | cut -d '=' -f 2 | cut -d ' ' -f 1 | sort | uniq -c
662 getbalance
997 getblockcount
3646 getreceivedbyaddress
876 gettransaction
254 getwalletinfo
107 listsinceblock
5 sendfrom
4 settxfee
So, just under 2 RPC calls per second on average.
I'm not sure how to determine if the slowness is based on the wallet size, the overall RPC volume, or some other factor, but it seems like at least the 4 threads should be able to work in parallel rather than in sequence as they currently seem to.
I've attempted increasing rpcthreads to 64, but this just results in 63 idle httpworker threads and one active using 100% of one core.
Anybody have any suggestions?