b9be892bf9
Persist by its definition doesn't change MemCachedStore visible state, all KV
pairs that were acessible via it before Persist remain accessible after
Persist. The only thing it does is flushing of the current set of KV pairs
from memory to peristent store. To do that it needs read-only access to the
current KV pair set, but technically it then replaces maps, so we have to use
full write lock which makes MemCachedStore inaccessible for the duration of
Persist. And Persist can take a lot of time, it's about disk access for
regular DBs.
What we do here is we create new in-memory maps for MemCachedStore before
flushing old ones to the persistent store. Then a fake persistent store is
created which actually is a MemCachedStore with old maps, so it has exactly
the same visible state. This Store is never accessed for writes, so we can
read it without taking any internal locks and at the same time we no longer
need write locks for original MemCachedStore, we're not using it. All of this
makes it possible to use MemCachedStore as normally reads are handled going
down to whatever level is needed and writes are handled by new maps. So while
Persist for (*Blockchain).dao does its most time-consuming work we can process
other blocks (reading data for transactions and persisting storeBlock caches
to (*Blockchain).dao).
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 62800
with VerifyBlocks set to false) on i7-8565U.
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 |