This PR is not ready: I know univalue is handled in a separate repository, so I guess I have to split the PR up? Where should the univalue changes go to, into https://github.com/bitcoin-core/univalue or into https://github.com/jgarzik/univalue?
Anyways, here is some motivational data for the changes:
For my BitcoinUtxoVisualizer the limiting factor seems to be mostly bitcoind's JSON generation speed. Here are some optimizations that speed this up quite a bit for me. Here are some numbers:
./bench_bitcoin -filter=BlockToJsonVerbose
| ns/op | err% | bra/op | miss% | benchmarked commit |--------------------:|------:|---------------:|--------:|:---------- | 66,877,763.00 | 0.1% | 101,638,376.00 | 0.4% | 349f17e | 57,915,056.00 | 1.2% | 85,882,830.00 | 0.5% | 26fd10a | 36,585,334.00 | 1.6% | 50,966,277.00 | 0.4% | 93f8240 | 28,508,105.00 | 0.2% | 40,138,962.00 | 0.4% | 9b59b15
So the benchmark improves from 66.9ms to 28.5ms for me. I ran an a benchmark with bitcoind as well, with that protocol:
- start bitcoind, with this
bitcoin.conf:server=1 rest=1 rpcport=8332 rpcthreads=32 rpcworkqueue=64 txindex=1 dbcache=2000 - Wait until fully synced, and log message shows
loadblk thread exit, so that bitcoind is idle. - Run apache benchmark: 2000 requests, 12 parallel threads, fetching block nr. 600000:
ab -n 2000 -c 12 "http://127.0.0.1:8332/rest/block/00000000000000000007316856900e76b4f7a9139cfbfba89842c8d196cd5f91.json"
Results for master, 349f17e:
Concurrency Level: 12
Time taken for tests: 26.535 seconds
Complete requests: 2000
Failed requests: 0
Total transferred: 11192226000 bytes
HTML transferred: 11192124000 bytes
Requests per second: 75.37 [#/sec] (mean)
Time per request: 159.208 [ms] (mean)
Time per request: 13.267 [ms] (mean, across all concurrent requests)
Transfer rate: 411911.64 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.0 0 0
Processing: 93 158 15.0 156 283
Waiting: 91 154 14.8 152 280
Total: 93 158 15.0 156 283
Percentage of the requests served within a certain time (ms)
50% 156
66% 161
75% 164
80% 167
90% 174
95% 184
98% 200
99% 216
100% 283 (longest request)
Results for this PR, 9b59b15:
Concurrency Level: 12
Time taken for tests: 16.801 seconds
Complete requests: 2000
Failed requests: 0
Total transferred: 11192226000 bytes
HTML transferred: 11192124000 bytes
Requests per second: 119.04 [#/sec] (mean)
Time per request: 100.805 [ms] (mean)
Time per request: 8.400 [ms] (mean, across all concurrent requests)
Transfer rate: 650556.74 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.0 0 0
Processing: 38 100 19.1 98 211
Waiting: 36 98 19.0 96 208
Total: 38 100 19.1 98 211
Percentage of the requests served within a certain time (ms)
50% 98
66% 105
75% 110
80% 113
90% 123
95% 138
98% 155
99% 163
100% 211 (longest request)