bench: enable wallet creation benchmarks on all platforms #30122

pull furszy wants to merge 1 commits into bitcoin:master from furszy:2024_bench_enable_wallet_create changing 1 files +5 −9
  1. furszy commented at 12:56 pm on May 16, 2024: member

    Simple fix for #29816.

    Since the wallet is appended to the global WalletContext during creation, merely calling reset() on the benchmark shared_pointer is insufficient to destruct the wallet. This no destruction of the wallet object results in keeping the db connection open, which was causes the fs::remove_all() failure on Windows.

  2. DrahtBot commented at 12:56 pm on May 16, 2024: contributor

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

    Code Coverage

    For detailed information about the code coverage, see the test coverage report.

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    ACK maflcko, hebasto, kevkevinpal

    If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

    Conflicts

    No conflicts as of last run.

  3. DrahtBot added the label Tests on May 16, 2024
  4. fanquake commented at 1:14 pm on May 16, 2024: member

    The native Windows CI (https://github.com/bitcoin/bitcoin/actions/runs/9112695910/job/25052498545?pr=30122#step:24:64) is failing with:

    0Run src\bench_bitcoin.exe -sanity-check
    1Running with -sanity-check option, output is being suppressed as benchmark results will be useless.
    2Error: Process completed with exit code 1.
    
  5. furszy force-pushed on May 16, 2024
  6. fanquake commented at 2:08 pm on May 16, 2024: member
    It’d be good if the commit message could explain why this is being done. It seems like the current approach is just to try and refactor away the Windows bug, even though it might not have been properly identified (prior to #29816 (comment)). However now that the bug might have been found, it’d be good to at least document what it is, and if possible, fix/workaround it in a more targetted way, rather than refactor code that is currently perfectly fine for all other platforms.
  7. furszy commented at 2:30 pm on May 16, 2024: member

    It’d be good if the commit message could explain why this is being done. It seems like the current approach is just to try and refactor away the Windows bug, even though it might not have been properly identified (prior to #29816 (comment)). However now that the bug might have been found, it’d be good to at least document what it is, and if possible, fix/workaround it in a more targetted way, rather than refactor code that is currently perfectly fine for all other platforms.

    Sure with a small nuance. This code is working fine for all other platforms but that does not mean the code is perfect. When I wrote this benchmark, I was probably more concerned about the number of files the benchmark could open in parallel than the delays/inaccuracies introduced by the, OS dependent, directory removal line. Essentially, we shouldn’t be removing a directory within the benchmarked code scope. But yeah, np on splitting this in two well described commits.

  8. furszy force-pushed on May 16, 2024
  9. hebasto commented at 3:51 pm on May 16, 2024: member
    Concept ACK.
  10. hebasto approved
  11. hebasto commented at 4:00 pm on May 16, 2024: member

    ACK 7323bf6a2ecc3a2f1e2fdebce53b961767b06e08.

    Maybe deduplicate code:

     0--- a/src/bench/wallet_create.cpp
     1+++ b/src/bench/wallet_create.cpp
     2@@ -35,8 +35,8 @@ static void WalletCreate(benchmark::Bench& bench, bool encrypted)
     3     std::vector<bilingual_str> warnings;
     4 
     5     int round = 0;
     6-    fs::path wallet_path = test_setup->m_path_root / strprintf("test_wallet%d_%d", round, random.rand32()).c_str();
     7     bench.run([&] {
     8+        auto wallet_path = test_setup->m_path_root / strprintf("test_wallet%d_%d", round++, random.rand32()).c_str();
     9         auto wallet = CreateWallet(context, wallet_path.utf8string(), /*load_on_start=*/std::nullopt, options, status, error_string, warnings);
    10         assert(status == DatabaseStatus::SUCCESS);
    11         assert(wallet != nullptr);
    12@@ -44,7 +44,6 @@ static void WalletCreate(benchmark::Bench& bench, bool encrypted)
    13         // Unload wallet and update wallet directory for the next round
    14         RemoveWallet(context, wallet, /*load_on_start=*/ std::nullopt);
    15         UnloadWallet(std::move(wallet));
    16-        wallet_path = test_setup->m_path_root / strprintf("test_wallet%d_%d", ++round, random.rand32()).c_str();
    17     });
    18 }
    19 
    

    ?

  12. furszy force-pushed on May 16, 2024
  13. furszy commented at 4:23 pm on May 16, 2024: member
    Applied, thanks @hebasto 👍🏼.
  14. hebasto approved
  15. hebasto commented at 7:19 pm on May 16, 2024: member
    re-ACK b6b2d822eb06d705e6ec4318211163e5862008a6.
  16. in src/bench/wallet_create.cpp:39 in b6b2d822eb outdated
    33@@ -34,16 +34,16 @@ static void WalletCreate(benchmark::Bench& bench, bool encrypted)
    34     bilingual_str error_string;
    35     std::vector<bilingual_str> warnings;
    36 
    37-    fs::path wallet_path = test_setup->m_path_root / strprintf("test_wallet_%d", random.rand32()).c_str();
    38+    int round = 0;
    39     bench.run([&] {
    40+        auto wallet_path = test_setup->m_path_root / strprintf("test_wallet%d_%d", round++, random.rand32()).c_str();
    


    maflcko commented at 2:54 pm on May 17, 2024:
    why is the random needed, when using a counter?

    furszy commented at 3:48 pm on May 17, 2024:
    No needed. I think I had the random path calculated outside of the loop before. With the current code, neither the counter nor the random is needed. Thanks.
  17. in src/bench/wallet_create.cpp:45 in b6b2d822eb outdated
    44 
    45-        // Cleanup
    46+        // Release wallet
    47         RemoveWallet(context, wallet, /*load_on_start=*/ std::nullopt);
    48         UnloadWallet(std::move(wallet));
    49-        fs::remove_all(wallet_path);
    


    maflcko commented at 2:57 pm on May 17, 2024:

    is it required to remove this remove_all call? I read the commit message:

    This approach will provide more accurate benchmark results, regardless of any delays the OS-dependent directory removal call could have.

    However, there is also a call to RemoveWallet, and UnloadWallet in this WalletCreate benchmark. The additional overhead of the remove_all should be fine? The benefit would be that the number of folders is kept constant and does not pile up as the bench runs, which could (in theory?) lead to issues when running for a long time?


    furszy commented at 3:40 pm on May 17, 2024:

    However, there is also a call to RemoveWallet, and UnloadWallet in this WalletCreate benchmark. The additional overhead of the remove_all should be fine? The benefit would be that the number of folders is kept constant and does not pile up as the bench runs, which could (in theory?) lead to issues when running for a long time?

    hmm, I don’t think they are comparable. The overhead of remove_all depend on external factors such us the OS and the hard drive. But agree that running this for a long time isn’t good neither. Seems that the best solution would be to create a mechanism to cleanup state in-between benchmark rounds in the framework. Will drop the second commit for now, np.

  18. in src/bench/wallet_create.cpp:39 in b6b2d822eb outdated
    33@@ -34,29 +34,25 @@ static void WalletCreate(benchmark::Bench& bench, bool encrypted)
    34     bilingual_str error_string;
    35     std::vector<bilingual_str> warnings;
    36 
    37-    fs::path wallet_path = test_setup->m_path_root / strprintf("test_wallet_%d", random.rand32()).c_str();
    38+    int round = 0;
    39     bench.run([&] {
    40+        auto wallet_path = test_setup->m_path_root / strprintf("test_wallet%d_%d", round++, random.rand32()).c_str();
    


    maflcko commented at 3:03 pm on May 17, 2024:
    while touching: Instead of c_str, could use PathFromString, because the c_str interface requires ascii-encoding, and ascii-encoded bytes are unchanged in unicode (via PathFromString).

    furszy commented at 3:48 pm on May 17, 2024:
    done
  19. furszy force-pushed on May 17, 2024
  20. in src/bench/wallet_create.cpp:37 in 7e30fdaa8f outdated
    33@@ -34,29 +34,25 @@ static void WalletCreate(benchmark::Bench& bench, bool encrypted)
    34     bilingual_str error_string;
    35     std::vector<bilingual_str> warnings;
    36 
    37-    fs::path wallet_path = test_setup->m_path_root / strprintf("test_wallet_%d", random.rand32()).c_str();
    38+    auto wallet_path = fs::PathToString(test_setup->m_path_root / fs::PathFromString(strprintf("test_wallet")));
    


    maflcko commented at 3:47 pm on May 17, 2024:
    0    auto wallet_path = fs::PathToString(test_setup->m_path_root / "test_wallet");
    

    nit: For pure ascii literals, it is not needed


    furszy commented at 3:50 pm on May 17, 2024:
    done. thanks
  21. maflcko approved
  22. maflcko commented at 3:47 pm on May 17, 2024: member
    utACK 7e30fdaa8fd7cc572505b7eac1b25f4ebe3b5443
  23. DrahtBot requested review from hebasto on May 17, 2024
  24. bench: bugfix, properly release wallet before erasing directory
    Since the wallet is appended to the global WalletContext during
    creation, merely calling 'reset()' on the benchmark shared_pointer
    is insufficient to destruct the wallet. This no destruction of the
    wallet results in the db connection remaining open, which was the
    cause of the 'fs::remove_all()' error in Windows.
    
    Co-Authored-By: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com>
    7c8abf3c20
  25. furszy force-pushed on May 17, 2024
  26. maflcko commented at 3:52 pm on May 17, 2024: member
    utACK 7c8abf3c2001152423da06d25f9f4906611685ea
  27. hebasto approved
  28. hebasto commented at 8:43 pm on May 17, 2024: member
    re-ACK 7c8abf3c2001152423da06d25f9f4906611685ea, I agree with changes since my recent review.
  29. kevkevinpal commented at 2:13 pm on May 25, 2024: contributor
    utACK 7c8abf3
  30. fanquake merged this on May 29, 2024
  31. fanquake closed this on May 29, 2024


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: 2024-06-29 07:13 UTC

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