49be753850
Block processing consists of:
* saving block/transactions to the DB
* executing blocks/transactions
* processing notifications/saving AERs
* updating MPT
* atomically updating Blockchain state
Of these the first one is completely independent of others, it can be done in
a separate routine easily. The third one technically depends on the second,
it just doesn't have data until something is executed. At the same time it
doesn't affect future executions in any way, so we can offload
AER/notification processing to separate goroutine (while the main thread
proceeds with other transactions).
MPT update depends on all executions, so it can't be offloaded, but it can be
done concurrently to AER processing. And only the last thing actually needs
all previous ones to be finished, so it's a natural synchronization point.
So we spawn two additional routines and let the main one execute transactions
and update MPT as fast as it can. While technically all of these routines
could share single DAO (they are working with different KV sets) benchmarking
shows that using separate DAOs and then persisting them to lower one actually
works about 7-8%% better. At the same time we can simplify DAOs used, Cached
one is only relevant for AER processing because it caches NEP-17 tracking
data, everything else can do just fine with Simple.
The change was tested for performance with neo-bench (single node, 10 workers,
LevelDB) on two machines and block dump processing (RC4 testnet up to 50825
with VerifyBlocks set to false) on i7-8565U. neo-bench creates huge blocks
with lots of transactions while RC4 dump mostly consists of empty blocks.
Reference results (
|
||
---|---|---|
.. | ||
block | ||
blockchainer | ||
chaindump | ||
dao | ||
fee | ||
interop | ||
mempool | ||
mempoolevent | ||
mpt | ||
native | ||
state | ||
stateroot | ||
storage | ||
test_data | ||
transaction | ||
blockchain.go | ||
blockchain_test.go | ||
doc.go | ||
helper_test.go | ||
interop_system.go | ||
interop_system_test.go | ||
interops.go | ||
interops_test.go | ||
native_contract_test.go | ||
native_designate_test.go | ||
native_gas_test.go | ||
native_ledger_test.go | ||
native_management_test.go | ||
native_neo_test.go | ||
native_notary_test.go | ||
native_oracle_test.go | ||
native_policy_test.go | ||
nonnative_name_service_test.go | ||
notary_test.go | ||
oracle_test.go | ||
prometheus.go | ||
stateroot_test.go | ||
util.go | ||
util_test.go |