Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Pause pruning while snapshotting #11178

Merged
merged 19 commits into from
Oct 24, 2019
Merged

Pause pruning while snapshotting #11178

merged 19 commits into from
Oct 24, 2019

Conversation

dvdplm
Copy link
Collaborator

@dvdplm dvdplm commented Oct 17, 2019

This PR pauses pruning while a snapshot is under way. It is very similar to previous attempts that was closed due to the problem with increased memory consumption. While this PR improves the situation slightly as it allows pruning to continue until the block we're snapshotting at, the objection is still valid: if this lands taking a snapshot will cause the memory limits set by the user to be ignored while a snapshot happens.

The default values for pruning-history and pruning-memory are 64 blocks and 32Mb respectively. At the time of writing, producing a snapshot on mainnet takes more than 10h on a fast machine and up to 25h on common hardware. This means that full non-archive nodes need to be configured to run with significantly higher values for --pruning-history or --pruning-memory. Empirically, values above 4000 blocks / 600Mb might work, but these numbers vary significantly depending on the hardware available and the load the machine is under otherwise.
There is obviously no incentive for a node operator to run such a configuration only to enable snapshots for new users.

The consequence is a dearth of recent snapshots available to new users trying to warp-sync, and a lot of wasted resources for full nodes attempting, and failing, to create snapshots.

Pausing pruning is bad. Keeping things as they are is also bad.

Here's a list of alternatives explored:

  • Disable the node while snapshotting: no new blocks are imported, hence no pruning and the pruning memory stays stable. Turning off people's nodes for 20h seems like a bad idea.
  • Don't create snapshots by default on non-archive nodes, i.e. make --no-periodic-snapshot the default. This will likely leave very few snapshot producing nodes available and lead to increased centralization. This is in a sense the current situation as no node running with a default config can produce snapshots.
  • Make deep changes to the state trie to track the block number that last modified each node and teach the pruning algorithm to keep state that is needed for the current snapshot. This is non-trivial and even if attempted will not provide a timely resolution to the immediate issue of snapshot availability.
  • Make a copy of the data needed for the snapshot into a new rocksdb database and make a snapshot of that instead. This would likely require a very large chunk of disk space be fairly involved.
  • Abandon warp-sync and until an alternative is available users must slow-sync their nodes.

Measuring the impact of pausing pruning is not straight forward. The time to take a snapshot varies significantly in between runs and from host to host. The pruneable set, frozen in this PR, increases RAM usage between 500 - 1800Mb, e.g.:

// journal mem usage: 1 852Mb (at this point my node lost all peers and stopped importing blocks, which stops pruning attempts)
2019-10-19 11:26:19  Verifier #7 TRACE pruning  Pruning is freezed at era 8767200; earliest era=8767200, latest era=8770464, journal_size=1966523469, mem_used=1942266864. Not pruning.
…
2019-10-19 16:15:42  Periodic Snapshot DEBUG snapshot  Took a snapshot of 71000605 accounts
2019-10-19 16:15:42  Periodic Snapshot INFO snapshot  produced 3638 state chunks and 97 block chunks.
2019-10-19 16:15:42  Periodic Snapshot TRACE snapshot  (defer) Unfreezing pruning, setting snapshotting_at back to 0
2019-10-19 16:15:42  Periodic Snapshot INFO snapshot::service  Finished taking snapshot at #8767200, in 58180.542310568s

The important code change here is this, the rest is mostly cosmetics.

@dvdplm dvdplm self-assigned this Oct 17, 2019
@dvdplm dvdplm added the A3-inprogress ⏳ Pull request is in progress. No review needed at this stage. label Oct 17, 2019
@ordian ordian added this to the 2.7 milestone Oct 18, 2019
@ordian ordian added the M4-core ⛓ Core client code / Rust. label Oct 18, 2019
ethcore/snapshot/src/service.rs Outdated Show resolved Hide resolved
ethcore/snapshot/src/service.rs Outdated Show resolved Hide resolved
ethcore/snapshot/src/service.rs Outdated Show resolved Hide resolved
ethcore/snapshot/src/service.rs Outdated Show resolved Hide resolved
parity/run.rs Outdated Show resolved Hide resolved
ethcore/snapshot/src/watcher.rs Outdated Show resolved Hide resolved
ethcore/snapshot/src/watcher.rs Outdated Show resolved Hide resolved
pub struct Progress {
/// Number of accounts processed so far
pub accounts: AtomicUsize,
accounts: AtomicUsize,
Copy link
Contributor

Choose a reason for hiding this comment

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

with this many fields, it's almost certainly better to use a single parking lot mutex wrapping a single struct containing all this data. maybe beyond the scope

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good idea, I'll make the change in a diff PR as it gets a bit noisy.

@arkpar
Copy link
Collaborator

arkpar commented Oct 21, 2019

Make a copy of the data needed for the snapshot into a new rocksdb database and make a snapshot of that instead. This would likely require a very large chunk of disk space be fairly involved.

That was one of the goals for parity-db.
The canonical state stored not in the trie, but directly in the database will take a fraction of the space. It will also help greatly with query performance.

@dvdplm
Copy link
Collaborator Author

dvdplm commented Oct 22, 2019

@rphmeier @arkpar thank you for your input. I'll collect a few more opinions but for the time being I think pausing pruning is the least worst choice we have for the short term.
Hopefully it'll give us enough time to plan the next steps, parity-db or other.

Cut down on the logging noise
@dvdplm dvdplm marked this pull request as ready for review October 23, 2019 10:41
Copy link
Contributor

@ngotchac ngotchac left a comment

Choose a reason for hiding this comment

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

LGTM other than a few questions.

ethcore/types/src/snapshot.rs Show resolved Hide resolved
ethcore/src/client/client.rs Outdated Show resolved Hide resolved
ethcore/src/client/client.rs Show resolved Hide resolved
* master:
  Type annotation for next_key() matching of json filter options (#11192)
  Crypto primitives removed from ethkey (#11174)
  Made ecrecover implementation trait public (#11188)
  Remove unused macro_use. (#11191)
  [dependencies]: jsonrpc `14.0.1` (#11183)
  [receipt]: add `sender` & `receiver` to `RichReceipts` (#11179)
  [dependencies] bump rand 0.7 (#11022)
  [ethcore/builtin]: do not panic in blake2pricer on short input (#11180)
  TxPermissions ver 3: gas price & data (#11170)
  [ethash] chainspec validate `ecip1017EraRounds` non-zero (#11123)
  util Host: fix a double Read Lock bug in fn Host::session_readable() (#11175)
  ethcore client: fix a double Read Lock bug in fn Client::logs() (#11172)
  Aura: Report malice on sibling blocks from the same validator (#11160)
@dvdplm dvdplm added A0-pleasereview 🤓 Pull request needs code review. and removed A3-inprogress ⏳ Pull request is in progress. No review needed at this stage. labels Oct 24, 2019
@ordian ordian added A8-looksgood 🦄 Pull request is reviewed well. and removed A0-pleasereview 🤓 Pull request needs code review. labels Oct 24, 2019
@dvdplm dvdplm added B0-patch-stable 🕷 Pull request should also be back-ported to the stable branch. B1-patch-beta 🕷🕷 labels Oct 24, 2019
@dvdplm dvdplm merged commit ffeaee7 into master Oct 24, 2019
@dvdplm dvdplm deleted the dp/fix/debug-snapshot-start branch October 24, 2019 14:46
dvdplm added a commit that referenced this pull request Oct 24, 2019
* master:
  Pause pruning while snapshotting (#11178)
  Type annotation for next_key() matching of json filter options (#11192)
  Crypto primitives removed from ethkey (#11174)
  Made ecrecover implementation trait public (#11188)
  Remove unused macro_use. (#11191)
  [dependencies]: jsonrpc `14.0.1` (#11183)
  [receipt]: add `sender` & `receiver` to `RichReceipts` (#11179)
  [dependencies] bump rand 0.7 (#11022)
  [ethcore/builtin]: do not panic in blake2pricer on short input (#11180)
  TxPermissions ver 3: gas price & data (#11170)
  [ethash] chainspec validate `ecip1017EraRounds` non-zero (#11123)
  util Host: fix a double Read Lock bug in fn Host::session_readable() (#11175)
  ethcore client: fix a double Read Lock bug in fn Client::logs() (#11172)
  Aura: Report malice on sibling blocks from the same validator (#11160)
dvdplm added a commit that referenced this pull request Oct 28, 2019
* master:
  [informant]: `MillisecondDuration` -> `as_millis()` (#11211)
  Step duration map configuration parameter ported from the POA Network fork (#10902)
  Upgrade jsonrpc to latest (#11206)
  [export hardcoded sync]: use debug for `H256` (#11204)
  Pause pruning while snapshotting (#11178)
This was referenced Nov 5, 2019
dvdplm added a commit that referenced this pull request Nov 6, 2019
* master: (21 commits)
  ropsten #6631425 foundation #8798209 (#11201)
  Update list of bootnodes for xDai chain (#11236)
  ethcore/res: add mordor testnet configuration (#11200)
  [chain specs]: activate `Istanbul` on mainnet (#11228)
  [builtin]: support `multiple prices and activations` in chain spec (#11039)
  Insert explicit warning into the panic hook (#11225)
  Snapshot restoration overhaul (#11219)
  Fix docker centos build (#11226)
  retry on gitlab system failures (#11222)
  Update bootnodes. (#11203)
  Use provided usd-per-eth value if an endpoint is specified (#11209)
  Use a lock instead of atomics for snapshot Progress (#11197)
  [informant]: `MillisecondDuration` -> `as_millis()` (#11211)
  Step duration map configuration parameter ported from the POA Network fork (#10902)
  Upgrade jsonrpc to latest (#11206)
  [export hardcoded sync]: use debug for `H256` (#11204)
  Pause pruning while snapshotting (#11178)
  Type annotation for next_key() matching of json filter options (#11192)
  Crypto primitives removed from ethkey (#11174)
  Made ecrecover implementation trait public (#11188)
  ...
niklasad1 pushed a commit that referenced this pull request Nov 7, 2019
* WIP. Typos and logging.

* Format todos

* Pause pruning while a snapshot is under way
Logs, docs and todos

* Allocate memory for the full chunk

* Name snapshotting threads

* Ensure `taking_snapshot` is set to false whenever and however `take_snapshot`returns
Rename `take_at` to `request_snapshot_at`
Cleanup

* Let "in_progress" deletion fail
Fix tests

* Just use an atomic

* Review grumbles

* Finish the sentence

* Resolve a few todos and clarify comments.

* Calculate progress rate since last update

* Lockfile

* Fix tests

* typo

* Reinstate default snapshotting frequency
Cut down on the logging noise

* address grumble

* Log memory use with `journal_size()` and explain why.
s3krit pushed a commit that referenced this pull request Nov 11, 2019
* [CI] check evmbin build (#11096)
* Correct EIP-712 encoding (#11092)
* [client]: Fix for incorrectly dropped consensus messages (#11082) (#11086)
* Update hardcoded headers (foundation, classic, kovan, xdai, ewc, ...) (#11053)
* Add cargo-remote dir to .gitignore (?)
* Update light client headers: ropsten 6631425 foundation 8798209 (#11201)
* Update list of bootnodes for xDai chain (#11236)
* ethcore/res: add mordor testnet configuration (#11200)
* [chain specs]: activate Istanbul on mainnet (#11228)
* [builtin]: support multiple prices and activations in chain spec (#11039)
* [receipt]: add sender & receiver to RichReceipts (#11179)
* [ethcore/builtin]: do not panic in blake2pricer on short input (#11180)
* Made ecrecover implementation trait public (#11188)
* Fix docker centos build (#11226)
* Update MIX bootnodes. (#11203)
* Insert explicit warning into the panic hook (#11225)
* Use provided usd-per-eth value if an endpoint is specified (#11209)
* Cleanup stratum a bit (#11161)
* Add Constantinople EIPs to the dev (instant_seal) config (#10809) (already backported)
* util Host: fix a double Read Lock bug in fn Host::session_readable() (#11175)
* ethcore client: fix a double Read Lock bug in fn Client::logs() (#11172)
* Type annotation for next_key() matching of json filter options (#11192)
* Upgrade jsonrpc to latest (#11206)
* [dependencies]: jsonrpc 14.0.1 (#11183)
* Upgrade to jsonrpc v14 (#11151)
* Switching sccache from local to Redis (#10971)
* Snapshot restoration overhaul (#11219)
* Add new line after writing block to hex file. (#10984)
* Pause pruning while snapshotting (#11178)
* Change how RPCs eth_call and eth_estimateGas handle "Pending" (#11127)
* Fix block detail updating (#11015)
* Make InstantSeal Instant again #11186
* Filter out some bad ropsten warp snapshots (#11247)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A8-looksgood 🦄 Pull request is reviewed well. B0-patch-stable 🕷 Pull request should also be back-ported to the stable branch. M4-core ⛓ Core client code / Rust.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants