Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-53623

Use a static variable for CancelationToken::Uncancellable()

    • Type: Icon: Task Task
    • Resolution: Won't Do
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • Service Arch 2021-03-22

      We create a new CancelationToken for each call to CancelationToken::uncancelable() here. Unfortunately, this makes each invocation take more time than is necessary. We should shift the function to construct an uncancelable state once and reuse it for each invocation.

      Benchmark without static variable
      2021-01-06 21:27:03
      Running install/bin/cancelation_bm
      Run on (16 X 2299.97 MHz CPU s)
      CPU Caches:
        L1 Data 32K (x8)
        L1 Instruction 32K (x8)
        L2 Unified 256K (x8)
        L3 Unified 46080K (x1)
      Load Average: 0.29, 0.42, 0.34
      --------------------------------------------------------------------------------------
      Benchmark                                            Time             CPU   Iterations
      --------------------------------------------------------------------------------------
      BM_create_single_token_from_source                14.1 ns         14.1 ns     49630229
      BM_uncancelable_token_ctor                         172 ns          172 ns      4077472
      BM_cancel_tokens_from_single_source/1             1507 ns         1509 ns       464189
      BM_cancel_tokens_from_single_source/10            1998 ns         2000 ns       350055
      BM_cancel_tokens_from_single_source/100           6985 ns         6982 ns       100347
      BM_cancel_tokens_from_single_source/1000         59314 ns        59304 ns        11813
      BM_cancel_tokens_from_single_source/10000       864175 ns       863888 ns          915
      BM_cancel_tokens_from_single_source/100000     9274757 ns      9270859 ns           73
      BM_cancel_tokens_from_single_source/1000000  127268434 ns    127259349 ns            6
      BM_check_if_token_from_source_canceled           0.371 ns        0.371 ns   1000000000
      BM_cancelation_source_from_token_ctor              934 ns          934 ns      1161130
      BM_cancelation_source_default_ctor                 187 ns          187 ns      3745716
      BM_ranged_depth_cancelation_hierarchy/1           1788 ns         1789 ns       391206
      BM_ranged_depth_cancelation_hierarchy/10          4735 ns         4736 ns       148036
      BM_ranged_depth_cancelation_hierarchy/100        36921 ns        36914 ns        18951
      BM_ranged_depth_cancelation_hierarchy/1000      497926 ns       497745 ns         1405
      
      Benchmark with static variable
      2021-01-06 21:23:52
      Running install/bin/cancelation_bm
      Run on (16 X 2299.97 MHz CPU s)
      CPU Caches:
        L1 Data 32K (x8)
        L1 Instruction 32K (x8)
        L2 Unified 256K (x8)
        L3 Unified 46080K (x1)
      Load Average: 0.88, 0.43, 0.32
      --------------------------------------------------------------------------------------
      Benchmark                                            Time             CPU   Iterations
      --------------------------------------------------------------------------------------
      BM_create_single_token_from_source                14.1 ns         14.1 ns     49627405
      BM_uncancelable_token_ctor                        14.1 ns         14.1 ns     49631845
      BM_cancel_tokens_from_single_source/1             1494 ns         1496 ns       468025
      BM_cancel_tokens_from_single_source/10            1985 ns         1988 ns       352574
      BM_cancel_tokens_from_single_source/100           6950 ns         6957 ns       100612
      BM_cancel_tokens_from_single_source/1000         59051 ns        59100 ns        11844
      BM_cancel_tokens_from_single_source/10000       843504 ns       843279 ns          928
      BM_cancel_tokens_from_single_source/100000     9178104 ns      9178246 ns           78
      BM_cancel_tokens_from_single_source/1000000  126632492 ns    126614691 ns            6
      BM_check_if_token_from_source_canceled           0.371 ns        0.371 ns   1000000000
      BM_cancelation_source_from_token_ctor              928 ns          928 ns      1161740
      BM_cancelation_source_default_ctor                 190 ns          190 ns      3683515
      BM_ranged_depth_cancelation_hierarchy/1           1771 ns         1773 ns       394449
      BM_ranged_depth_cancelation_hierarchy/10          4707 ns         4709 ns       148645
      BM_ranged_depth_cancelation_hierarchy/100        38334 ns        38387 ns        18246
      BM_ranged_depth_cancelation_hierarchy/1000      478853 ns       478903 ns         1462
      

            Assignee:
            tyler.seip@mongodb.com Tyler Seip (Inactive)
            Reporter:
            ben.caimano@mongodb.com Benjamin Caimano (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: