Skip to content

Commit 00bf4a1

Browse files
committed
Merge bitcoin/bitcoin#26684: bench: add readblock benchmark
1c4b9cb bench: add readblock benchmark (Andrew Toth) Pull request description: Requested in bitcoin/bitcoin#13151 (comment). See bitcoin/bitcoin#26415 and bitcoin/bitcoin#21319. Benchmarking shows a >50x increase in speed on both nvme and spinning disk. Benchmark results: | ns/op | op/s | err% | ins/op | cyc/op | IPC | bra/op | miss% | total | benchmark |--------------------:|--------------------:|--------:|----------------:|----------------:|-------:|---------------:|--------:|----------:|:---------- | 5,377,375.00 | 185.96 | 0.2% | 60,125,513.00 | 11,633,676.00 | 5.168 | 3,588,800.00 | 0.4% | 0.09 | `ReadBlockFromDiskTest` | ns/op | op/s | err% | ins/op | cyc/op | IPC | bra/op | miss% | total | benchmark |--------------------:|--------------------:|--------:|----------------:|----------------:|-------:|---------------:|--------:|----------:|:---------- | 89,945.58 | 11,117.83 | 0.7% | 12,743.90 | 64,530.33 | 0.197 | 2,595.20 | 0.2% | 0.01 | `ReadRawBlockFromDiskTest` ACKs for top commit: maflcko: lgtm ACK 1c4b9cb achow101: ACK 1c4b9cb TheCharlatan: ACK 1c4b9cb Tree-SHA512: 71dbcd6c7e2be97eb3001e35d0a95ef8e0c9b10dc9193025c7f8e11a09017fa2fbf89489b686353cd88fb409fb729fe2c4a25c567d2988f64c9c164ab09fba9f
2 parents 2652506 + 1c4b9cb commit 00bf4a1

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

src/Makefile.bench.include

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ bench_bench_bitcoin_SOURCES = \
4646
bench/poly1305.cpp \
4747
bench/pool.cpp \
4848
bench/prevector.cpp \
49+
bench/readblock.cpp \
4950
bench/rollingbloom.cpp \
5051
bench/rpc_blockchain.cpp \
5152
bench/rpc_mempool.cpp \

src/bench/readblock.cpp

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Copyright (c) 2023 The Bitcoin Core developers
2+
// Distributed under the MIT software license, see the accompanying
3+
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4+
5+
#include <bench/bench.h>
6+
#include <bench/data.h>
7+
8+
#include <consensus/validation.h>
9+
#include <node/blockstorage.h>
10+
#include <streams.h>
11+
#include <test/util/setup_common.h>
12+
#include <util/chaintype.h>
13+
#include <validation.h>
14+
15+
static FlatFilePos WriteBlockToDisk(ChainstateManager& chainman)
16+
{
17+
DataStream stream{benchmark::data::block413567};
18+
CBlock block;
19+
stream >> TX_WITH_WITNESS(block);
20+
21+
return chainman.m_blockman.SaveBlockToDisk(block, 0, nullptr);
22+
}
23+
24+
static void ReadBlockFromDiskTest(benchmark::Bench& bench)
25+
{
26+
const auto testing_setup{MakeNoLogFileContext<const TestingSetup>(ChainType::MAIN)};
27+
ChainstateManager& chainman{*testing_setup->m_node.chainman};
28+
29+
CBlock block;
30+
const auto pos{WriteBlockToDisk(chainman)};
31+
32+
bench.run([&] {
33+
const auto success{chainman.m_blockman.ReadBlockFromDisk(block, pos)};
34+
assert(success);
35+
});
36+
}
37+
38+
static void ReadRawBlockFromDiskTest(benchmark::Bench& bench)
39+
{
40+
const auto testing_setup{MakeNoLogFileContext<const TestingSetup>(ChainType::MAIN)};
41+
ChainstateManager& chainman{*testing_setup->m_node.chainman};
42+
43+
std::vector<uint8_t> block_data;
44+
const auto pos{WriteBlockToDisk(chainman)};
45+
46+
bench.run([&] {
47+
const auto success{chainman.m_blockman.ReadRawBlockFromDisk(block_data, pos)};
48+
assert(success);
49+
});
50+
}
51+
52+
BENCHMARK(ReadBlockFromDiskTest, benchmark::PriorityLevel::HIGH);
53+
BENCHMARK(ReadRawBlockFromDiskTest, benchmark::PriorityLevel::HIGH);

0 commit comments

Comments
 (0)