Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[refactor] #2664: Introduce new wsv #4061

Merged
merged 6 commits into from Mar 21, 2024

Conversation

Erigara
Copy link
Contributor

@Erigara Erigara commented Nov 20, 2023

Description

Introduce new in memory storage for iroha.

New approach provide single writer, multiple readers where readers don't block writers and writer doesn't block readers.

Single writer seems reasonable restriction since only single block is processed at the same time.

Instead of single WorldStateView multiple transactions are now used.

Work is based on concread crate.

graph TD;
    WS-->WSV;
    WS-->WSB;
    WSB-->WST;

    WS["State"]
    WSV["StateView"]
    WSB["StateBlock"]
    WST["StateTransaction"]
  • State in-memory iroha storage
  • StateView read-only snapshot of state at some point in time
  • StateBlock aggregate state changes during block execution (need commit to take effect)
  • StateTransaction aggregate state changes during transaction execution (need commit to take effect)

Linked issue

Closes #2664

Benefits

  • Faster on large larger state
  • Readers and writer are independent

Benchmark results

Iroha tps benchmark was used. In this bechmark only small fraction of state is changed with single transaction (imo it's reasonable to expect that single transaction won't change whole state).

Genesis was generated with the following command:

cargo run --bin kagami genesis --domains 250 --accounts-per-domain 100 --assets-per-domain 100 > configs/peer/genesis.json 

This command creates genesis about 400 Mb in size.

Set the following config for clients/bench/config.json

{
    "peers": 1, // 4 -> 1 To speed up things
    "interval_us_per_tx": 0,
    "max_txs_per_block": 1024,
    "blocks": 15,
    "sample_size": 10,
    "genesis_max_retries": 1200 // Wait for large genesis to be committed
}

Than bench two times before and after changes in wsv.

export WSV_WASM_RUNTIME_CONFIG='{ "FUEL_LIMIT": 18446744073709551615, "MAX_MEMORY": 4294967295 }'
cd client
cargo run --release --example tps-oneshot

tps-oneshot results:

Before update: tps=3.3077273188803833
After update: tps=2339.2057925660447

To measure memory consumption heaptrack was used.

Allocation sizes and amounts:

Before:

before

After:

after

All relevant files: link.

TODO

  • [ ]: Create relevant issues
  • [ ]: Rename no longer relevant variable names, update docs, ...

@Erigara Erigara added iroha2-dev The re-implementation of a BFT hyperledger in RUST Refactor Improvement to overall code quality Optimization Something isn't working as well as it should labels Nov 20, 2023
@Erigara Erigara self-assigned this Nov 20, 2023
Cargo.toml Outdated Show resolved Hide resolved
@Erigara Erigara force-pushed the multi_version_wsv branch 2 times, most recently from 04fe423 to 3f3b0f2 Compare November 21, 2023 05:51
@mversic mversic self-assigned this Nov 21, 2023
@coveralls
Copy link
Collaborator

coveralls commented Nov 21, 2023

Pull Request Test Coverage Report for Build 7097081569

  • 1148 of 2221 (51.69%) changed or added relevant lines in 26 files are covered.
  • 6436 unchanged lines in 128 files lost coverage.
  • Overall coverage decreased (-3.0%) to 56.458%

Changes Missing Coverage Covered Lines Changed/Added Lines %
core/src/smartcontracts/isi/triggers/mod.rs 0 1 0.0%
core/src/smartcontracts/mod.rs 8 9 88.89%
config/src/iroha.rs 1 3 33.33%
core/src/tx.rs 12 15 80.0%
core/src/smartcontracts/isi/world.rs 0 4 0.0%
core/src/block.rs 38 43 88.37%
telemetry/derive/src/lib.rs 5 10 50.0%
cli/src/lib.rs 0 6 0.0%
core/src/gossiper.rs 0 7 0.0%
core/test_network/src/lib.rs 0 10 0.0%
Files with Coverage Reduction New Missed Lines %
config/base/derive/src/view.rs 1 99.37%
config/src/block_sync.rs 1 95.0%
config/src/network.rs 1 93.75%
config/src/torii.rs 1 95.45%
config/src/wasm.rs 1 87.5%
core/src/smartcontracts/isi/block.rs 1 87.5%
config/src/kura.rs 2 79.41%
config/src/lib.rs 2 0.0%
ffi/src/option.rs 2 71.43%
config/src/genesis.rs 3 72.92%
Totals Coverage Status
Change from base Build 5423219773: -3.0%
Covered Lines: 23311
Relevant Lines: 41289

💛 - Coveralls

@SamHSmith SamHSmith self-assigned this Nov 21, 2023
@Erigara Erigara force-pushed the multi_version_wsv branch 2 times, most recently from dc0cc41 to d4da9b7 Compare November 21, 2023 08:10
@DCNick3 DCNick3 self-assigned this Nov 22, 2023
tools/kagami/src/genesis.rs Outdated Show resolved Hide resolved
cli/src/lib.rs Outdated Show resolved Hide resolved
cli/src/torii/mod.rs Outdated Show resolved Hide resolved
core/src/block_sync.rs Outdated Show resolved Hide resolved
core/src/sumeragi/mod.rs Outdated Show resolved Hide resolved
core/src/wsv.rs Outdated Show resolved Hide resolved
core/src/wsv.rs Outdated Show resolved Hide resolved
core/src/wsv.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@SamHSmith SamHSmith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job.

@Erigara Erigara force-pushed the multi_version_wsv branch 2 times, most recently from 256bb41 to c148b7c Compare December 5, 2023 06:33
@Erigara Erigara marked this pull request as ready for review December 5, 2023 07:03
@DCNick3 DCNick3 assigned DCNick3 and unassigned DCNick3 Jan 10, 2024
cli/src/lib.rs Show resolved Hide resolved
cli/src/torii/routing.rs Outdated Show resolved Hide resolved
cli/src/torii/routing.rs Outdated Show resolved Hide resolved
config/src/iroha.rs Outdated Show resolved Hide resolved
config/src/state.rs Outdated Show resolved Hide resolved
core/src/state.rs Show resolved Hide resolved
core/src/state.rs Outdated Show resolved Hide resolved
core/src/state.rs Outdated Show resolved Hide resolved
core/src/state.rs Outdated Show resolved Hide resolved
core/src/state.rs Outdated Show resolved Hide resolved
@Arjentix
Copy link
Contributor

New approach provide single reader, multiple readers where readers don't block writers and writer doesn't block readers.

I believe somewhere should be writer instead of reader

core/src/sumeragi/main_loop.rs Outdated Show resolved Hide resolved
core/src/state.rs Show resolved Hide resolved
@s8sato s8sato self-assigned this Mar 14, 2024
core/src/sumeragi/main_loop.rs Show resolved Hide resolved
core/src/state.rs Show resolved Hide resolved
core/src/sumeragi/main_loop.rs Outdated Show resolved Hide resolved
@github-actions github-actions bot added the api-changes Changes in the API for client libraries label Mar 18, 2024
@coveralls
Copy link
Collaborator

coveralls commented Mar 18, 2024

Pull Request Test Coverage Report for Build 8360992827

Details

  • 1339 of 2233 (59.96%) changed or added relevant lines in 26 files are covered.
  • 4400 unchanged lines in 90 files lost coverage.
  • Overall coverage increased (+0.8%) to 57.616%

Changes Missing Coverage Covered Lines Changed/Added Lines %
core/src/tx.rs 12 15 80.0%
telemetry/derive/src/lib.rs 12 15 80.0%
core/src/smartcontracts/isi/world.rs 0 4 0.0%
cli/src/lib.rs 0 5 0.0%
core/src/block.rs 38 43 88.37%
core/src/smartcontracts/isi/triggers/mod.rs 0 5 0.0%
core/src/gossiper.rs 0 7 0.0%
torii/src/lib.rs 0 7 0.0%
core/test_network/src/lib.rs 0 10 0.0%
core/src/block_sync.rs 0 13 0.0%
Files with Coverage Reduction New Missed Lines %
primitives/src/conststr.rs 1 91.14%
ffi/derive/src/convert.rs 1 84.45%
primitives/src/lib.rs 1 0.0%
core/src/sumeragi/network_topology.rs 1 98.78%
telemetry/derive/src/lib.rs 1 64.86%
crypto/src/signature/bls/mod.rs 2 0.0%
config/src/snapshot.rs 3 78.57%
data_model/derive/src/has_origin.rs 3 95.16%
config/src/kura.rs 3 80.0%
primitives/src/addr.rs 3 64.04%
Totals Coverage Status
Change from base Build 7884695009: 0.8%
Covered Lines: 23071
Relevant Lines: 40043

💛 - Coveralls

@Erigara Erigara force-pushed the multi_version_wsv branch 2 times, most recently from fd14088 to ef79703 Compare March 19, 2024 09:03
Signed-off-by: Shanin Roman <shanin1000@yandex.ru>
Signed-off-by: Shanin Roman <shanin1000@yandex.ru>
Signed-off-by: Shanin Roman <shanin1000@yandex.ru>
Signed-off-by: Shanin Roman <shanin1000@yandex.ru>
s8sato
s8sato previously approved these changes Mar 20, 2024
Signed-off-by: Shanin Roman <shanin1000@yandex.ru>
…ng latest

Signed-off-by: Shanin Roman <shanin1000@yandex.ru>
Copy link
Contributor

@mversic mversic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since you found a way to eliminate View vs Snapshot, I have no other complaints here.
I think this change is amazing improvement

@Erigara Erigara merged commit 47f278d into hyperledger:iroha2-dev Mar 21, 2024
14 of 15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-changes Changes in the API for client libraries iroha2-dev The re-implementation of a BFT hyperledger in RUST Optimization Something isn't working as well as it should Refactor Improvement to overall code quality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants