Add blockpause setting #16761

pull emilengler wants to merge 2 commits into bitcoin:master from emilengler:2019-08-blockpause changing 4 files +29 −0
  1. emilengler commented at 7:47 PM on August 29, 2019: contributor

    What is this?

    This adds a feature to set a delay between the blocks at the initial download.

    Why?

    A few weeks ago I was downloading the blockchain on my systems drive (which is an SSD). I usually download the blockchain on an external drive which is an HDD. During the sync on my SSD my Computer was completely unusable because there were too many read and write operations. This PR adds a feature to throttle the block downlad to make the Computer usable during that time.

    Testing

    Just add a -blockpause=1000 to add a pause of ten seconds. The default is 0 miliseconds

    Notes

    This is being ignored if the regtest chain is in use

    Log

    Running ./bitcoind --blockpause=10000

    2019-08-29T19:42:43Z UpdateTip: new best=00000000faac558a7a5266c3c678e53b53b88a619b00dd825395b8e4ca44cdd9 height=9511 version=0x00000001 log2_work=45.215555 tx=9602 date='2009-04-02T02:23:37Z' progress=0.000022 cache=0.0MiB(1txo)
    2019-08-29T19:42:53Z UpdateTip: new best=000000009be075c2742955e8cad5aa09390e2e7feffdfecc371bdcae0fb60951 height=9512 version=0x00000001 log2_work=45.215707 tx=9603 date='2009-04-02T02:27:04Z' progress=0.000022 cache=0.0MiB(2txo)
    2019-08-29T19:43:03Z UpdateTip: new best=00000000c60596cdb860839242211d9a17ba734e397636135e7744303d189a0b height=9513 version=0x00000001 log2_work=45.215858 tx=9604 date='2009-04-02T01:41:48Z' progress=0.000022 cache=0.0MiB(3txo)
    2019-08-29T19:43:13Z UpdateTip: new best=0000000052ab68c20deabfd537a4f40ce88bbd29bdc91b86fb791a701a7af723 height=9514 version=0x00000001 log2_work=45.21601 tx=9605 date='2009-04-02T01:59:40Z' progress=0.000022 cache=0.0MiB(4txo)
    

    See timestamps

  2. trivial: Add blockpause 9f3767f28b
  3. laanwj commented at 7:52 PM on August 29, 2019: member

    Doesn't it help to set a lower par= value if the sync goes too fast? Or what about picking up one of the earlier PRs that reduced I/O priority? This seems kind of a kludge, tbh.

  4. jonasschnelli commented at 7:52 PM on August 29, 2019: contributor

    Concept ACK on a throttle function (unsure about pausing versus disable paralelism in verification).

    Relevant: #12965 (same goal, different approach)

  5. emilengler commented at 7:57 PM on August 29, 2019: contributor

    @laanwj IMO

           Set the number of script verification threads (-8 to 16, 0 = auto, <0 =
           leave that many cores free, default: 0)
    

    doesn't really indicate an I/O throttle if this is what you mean

  6. laanwj commented at 7:58 PM on August 29, 2019: member

    doesn't really indicate an I/O throttle if this is what you mean

    It's not, but by using less CPU power for verification, the consequence is that it'll go slower and automatically do less I/O as well.

  7. emilengler commented at 8:02 PM on August 29, 2019: contributor

    What is if you still have a powerful CPU (even with 1 thread) and a fast internet connection? Also I don't think -par was made to reduce the I/O speed, this is more a side-effect

  8. laanwj commented at 8:03 PM on August 29, 2019: member

    Neither is adding sleep between blocks! So, that's why I mentioned I/O throttling. Your OS has ways to do this that are actually throttling I/O.

  9. laanwj commented at 8:05 PM on August 29, 2019: member

    See e.g. #9245

  10. DrahtBot commented at 8:06 PM on August 29, 2019: member

    <!--e57a25ab6845829454e8d69fc972939a-->

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #16324 (Get cs_main out of the critical path in ProcessMessages by TheBlueMatt)
    • #16323 (Call ProcessNewBlock() asynchronously by TheBlueMatt)

    If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

  11. emilengler commented at 8:17 PM on August 29, 2019: contributor

    I definitely need to read myself into I/O throttling but as long as a thread sleeps, no I/O stuff is being done as well...

  12. laanwj renamed this:
    trivial: Add blockpause
    Add blockpause setting
    on Aug 29, 2019
  13. DrahtBot added the label Validation on Aug 29, 2019
  14. GChuf commented at 9:48 AM on August 30, 2019: contributor

    Not sure how the code works, but wouldn't it be better for the program to ignore that line of code when blockpause = 0? I'm thinking this should help, unless the program has to go through this extra if statement every time and not just once.

        if (Params().NetworkIDString() != "regtest" and blockpause != 0)
        {
            std::this_thread::sleep_for(std::chrono::milliseconds(blockpause));
        }
    
  15. in src/validation.cpp:3429 in 9f3767f28b outdated
    3425 | @@ -3426,6 +3426,11 @@ static FlatFilePos SaveBlockToDisk(const CBlock& block, int nHeight, const CChai
    3426 |  /** Store block on disk. If dbp is non-nullptr, the file is known to already reside on disk */
    3427 |  bool CChainState::AcceptBlock(const std::shared_ptr<const CBlock>& pblock, CValidationState& state, const CChainParams& chainparams, CBlockIndex** ppindex, bool fRequested, const FlatFilePos* dbp, bool* fNewBlock)
    3428 |  {
    3429 | +    // Ignore blockpause in regtest
    


    promag commented at 9:53 AM on August 30, 2019:

    Why?


    emilengler commented at 11:48 AM on August 30, 2019:

    Say you generate 100 blocks with 1000 blockpause. This would take 100 seconds and the program would hang up.


    mzumsande commented at 6:41 PM on August 31, 2019:

    That is not a valid concern imo, especially with the default value being 0. Regtest exists to test features on mainnet, and this would prevent testing of blockpause in functional tests for no pressing reason.


    emilengler commented at 7:45 PM on August 31, 2019:

    You're right but this feature was meant for the block download, not creation

  16. promag commented at 9:55 AM on August 30, 2019: member

    Approach NAK, cs_main is held while sleeping.

  17. emilengler commented at 11:49 AM on August 30, 2019: contributor

    @GChuf I also thought about it but I don’t think it actually makes a difference. Take a look at the output log for example

  18. GChuf commented at 3:00 PM on August 30, 2019: contributor

    @emilengler still, if we have the option to not include that operation every time a block is found, I think it's worth it, no matter if the difference is perceivable

  19. ariard commented at 3:09 PM on August 30, 2019: member

    Concept NACK, the problem you're describing is more an OS resource monitoring issue than a problem in Core. IMO complicating critical code paths with options should be really worth it.

    If you are using a Linux, have a look on man 7 cgroups, it provides fine-grained throttling policy to specify upper I/O rate limits on a device.

  20. emilengler commented at 3:58 PM on August 30, 2019: contributor

    @GChuf I still think checking for something every block takes longer than just executing a function

  21. GChuf commented at 5:57 PM on August 30, 2019: contributor

    @emilengler so it checks for regtest for every block as well? is there a way to check only once at the beginning?

  22. emilengler commented at 9:34 PM on August 30, 2019: contributor

    @GChuf Yes, in terms of not calling the function everytime

  23. Check a bool a8ea314f2a
  24. emilengler commented at 9:53 AM on August 31, 2019: contributor

    Done, forget to do the commit yesterday

  25. in src/validation.cpp:3431 in a8ea314f2a
    3425 | @@ -3426,6 +3426,12 @@ static FlatFilePos SaveBlockToDisk(const CBlock& block, int nHeight, const CChai
    3426 |  /** Store block on disk. If dbp is non-nullptr, the file is known to already reside on disk */
    3427 |  bool CChainState::AcceptBlock(const std::shared_ptr<const CBlock>& pblock, CValidationState& state, const CChainParams& chainparams, CBlockIndex** ppindex, bool fRequested, const FlatFilePos* dbp, bool* fNewBlock)
    3428 |  {
    3429 | +    // Ignore blockpause in regtest
    3430 | +    bool IsRegtest;
    3431 | +    if (!IsRegtest)
    


    promag commented at 9:58 AM on August 31, 2019:

    :eyes:

  26. promag commented at 10:02 AM on August 31, 2019: member

    Before going forward please reply/address to the above NACKS.

  27. sdaftuar commented at 2:48 PM on September 3, 2019: member

    Approach NACK for many of the reasons given above -- this is a kludge and not the best way to achieve the desired goal; we should have a high bar for complicating consensus code, and I think adding a spurious sleep to intentionally degrade performance does not meet that bar; and we should not expose confusing command line options to users.

    I haven't reviewed #9245 in any depth but the approach there seems much more reasonable for achieving the desired effect. Please consider picking that PR up if you'd like to improve the behavior here.

  28. emilengler commented at 3:58 PM on September 3, 2019: contributor

    Closed for the above reasons

  29. emilengler closed this on Sep 3, 2019

  30. emilengler deleted the branch on Sep 3, 2019
  31. MarcoFalke locked this on Dec 16, 2021

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-26 15:14 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me