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

Timeouts #86

Merged
merged 1 commit into from
Jun 27, 2023
Merged

Timeouts #86

merged 1 commit into from
Jun 27, 2023

Conversation

polytypic
Copy link
Collaborator

@polytypic polytypic commented Jun 7, 2023

Based on a scheduler independent domain-local-timeout mechanism for setting timeouts, i.e. callback to be called after specified amount of time, this PR adds an optional timeoutf argument to specify a timeout in seconds for potentially blocking operations.

@polytypic polytypic force-pushed the timeout branch 5 times, most recently from 88be16c to 11050ca Compare June 7, 2023 11:44
@polytypic polytypic linked an issue Jun 7, 2023 that may be closed by this pull request
@polytypic polytypic changed the title WIP: Timeouts Timeouts Jun 7, 2023
@polytypic polytypic force-pushed the timeout branch 15 times, most recently from 7faa03c to 8ebe4eb Compare June 13, 2023 13:11
@polytypic polytypic force-pushed the timeout branch 8 times, most recently from 3c21e18 to 9f98d45 Compare June 27, 2023 11:51
@polytypic polytypic marked this pull request as ready for review June 27, 2023 11:52
@polytypic
Copy link
Collaborator Author

polytypic commented Jun 27, 2023

Benchmarks seem to indicate minor acceptable overhead due to optionally setting up the timeouts:

Benchmark 1: kcas-main/_build/default/test/kcas_data/hashtbl_bench.exe 1 1_000_000 1000 90
  Time (mean ± σ):      34.2 ms ±   0.2 ms    [User: 33.0 ms, System: 0.9 ms]
  Range (min … max):    34.0 ms …  34.9 ms    85 runs
 
Benchmark 2: kcas-this/_build/default/test/kcas_data/hashtbl_bench.exe 1 1_000_000 1000 90
  Time (mean ± σ):      34.7 ms ±   0.3 ms    [User: 33.4 ms, System: 0.9 ms]
  Range (min … max):    34.4 ms …  37.1 ms    84 runs
 
  Warning: The first benchmarking run for this command was significantly slower than the rest (35.7 ms). This could be caused by (filesystem) caches that were not filled until after the first run. You are already using the '--warmup' option which helps to fill these caches before the actual benchmark. You can either try to increase the warmup count further or re-run this benchmark on a quiet system in case it was a random outlier. Alternatively, consider using the '--prepare' option to clear the caches before each timing run.
 
Summary
  kcas-main/_build/default/test/kcas_data/hashtbl_bench.exe 1 1_000_000 1000 90 ran
    1.01 ± 0.01 times faster than kcas-this/_build/default/test/kcas_data/hashtbl_bench.exe 1 1_000_000 1000 90


Benchmark 1: kcas-main/_build/default/test/kcas_data/hashtbl_bench.exe 2 1_000_000 1000 90
  Time (mean ± σ):      22.5 ms ±   0.4 ms    [User: 40.9 ms, System: 1.2 ms]
  Range (min … max):    22.3 ms …  26.7 ms    130 runs
 
  Warning: Statistical outliers were detected. Consider re-running this benchmark on a quiet system without any interferences from other programs. It might help to use the '--warmup' or '--prepare' options.
 
Benchmark 2: kcas-this/_build/default/test/kcas_data/hashtbl_bench.exe 2 1_000_000 1000 90
  Time (mean ± σ):      22.7 ms ±   0.1 ms    [User: 41.2 ms, System: 1.2 ms]
  Range (min … max):    22.6 ms …  23.3 ms    128 runs
 
Summary
  kcas-main/_build/default/test/kcas_data/hashtbl_bench.exe 2 1_000_000 1000 90 ran
    1.01 ± 0.02 times faster than kcas-this/_build/default/test/kcas_data/hashtbl_bench.exe 2 1_000_000 1000 90


Benchmark 1: kcas-main/_build/default/test/kcas_data/hashtbl_bench.exe 4 1_000_000 1000 90
  Time (mean ± σ):      15.0 ms ±   0.5 ms    [User: 48.4 ms, System: 1.9 ms]
  Range (min … max):    14.5 ms …  21.0 ms    206 runs
 
  Warning: Statistical outliers were detected. Consider re-running this benchmark on a quiet system without any interferences from other programs. It might help to use the '--warmup' or '--prepare' options.
 
Benchmark 2: kcas-this/_build/default/test/kcas_data/hashtbl_bench.exe 4 1_000_000 1000 90
  Time (mean ± σ):      14.6 ms ±   0.3 ms    [User: 46.4 ms, System: 2.0 ms]
  Range (min … max):    14.2 ms …  16.9 ms    205 runs
 
  Warning: Statistical outliers were detected. Consider re-running this benchmark on a quiet system without any interferences from other programs. It might help to use the '--warmup' or '--prepare' options.
 
Summary
  kcas-this/_build/default/test/kcas_data/hashtbl_bench.exe 4 1_000_000 1000 90 ran
    1.03 ± 0.04 times faster than kcas-main/_build/default/test/kcas_data/hashtbl_bench.exe 4 1_000_000 1000 90


Benchmark 1: kcas-main/_build/default/test/kcas_data/hashtbl_bench.exe 1 1_000_000 1000 10
  Time (mean ± σ):     184.9 ms ±   1.3 ms    [User: 183.5 ms, System: 1.0 ms]
  Range (min … max):   181.9 ms … 185.8 ms    16 runs
 
  Warning: Statistical outliers were detected. Consider re-running this benchmark on a quiet system without any interferences from other programs. It might help to use the '--warmup' or '--prepare' options.
 
Benchmark 2: kcas-this/_build/default/test/kcas_data/hashtbl_bench.exe 1 1_000_000 1000 10
  Time (mean ± σ):     189.0 ms ±   1.9 ms    [User: 187.5 ms, System: 1.1 ms]
  Range (min … max):   186.7 ms … 192.7 ms    15 runs
 
Summary
  kcas-main/_build/default/test/kcas_data/hashtbl_bench.exe 1 1_000_000 1000 10 ran
    1.02 ± 0.01 times faster than kcas-this/_build/default/test/kcas_data/hashtbl_bench.exe 1 1_000_000 1000 10


Benchmark 1: kcas-main/_build/default/test/kcas_data/hashtbl_bench.exe 2 1_000_000 1000 10
  Time (mean ± σ):     117.7 ms ±   0.6 ms    [User: 230.2 ms, System: 1.5 ms]
  Range (min … max):   117.4 ms … 119.5 ms    25 runs
 
  Warning: Statistical outliers were detected. Consider re-running this benchmark on a quiet system without any interferences from other programs. It might help to use the '--warmup' or '--prepare' options.
 
Benchmark 2: kcas-this/_build/default/test/kcas_data/hashtbl_bench.exe 2 1_000_000 1000 10
  Time (mean ± σ):     120.0 ms ±   0.9 ms    [User: 234.7 ms, System: 1.6 ms]
  Range (min … max):   119.0 ms … 123.8 ms    24 runs
 
  Warning: Statistical outliers were detected. Consider re-running this benchmark on a quiet system without any interferences from other programs. It might help to use the '--warmup' or '--prepare' options.
 
Summary
  kcas-main/_build/default/test/kcas_data/hashtbl_bench.exe 2 1_000_000 1000 10 ran
    1.02 ± 0.01 times faster than kcas-this/_build/default/test/kcas_data/hashtbl_bench.exe 2 1_000_000 1000 10


Benchmark 1: kcas-main/_build/default/test/kcas_data/hashtbl_bench.exe 4 1_000_000 1000 10
  Time (mean ± σ):      74.2 ms ±   0.6 ms    [User: 282.8 ms, System: 2.4 ms]
  Range (min … max):    73.4 ms …  76.1 ms    39 runs
 
Benchmark 2: kcas-this/_build/default/test/kcas_data/hashtbl_bench.exe 4 1_000_000 1000 10
  Time (mean ± σ):      68.7 ms ±   0.6 ms    [User: 259.8 ms, System: 2.5 ms]
  Range (min … max):    68.0 ms …  72.0 ms    43 runs
 
Summary
  kcas-this/_build/default/test/kcas_data/hashtbl_bench.exe 4 1_000_000 1000 10 ran
    1.08 ± 0.01 times faster than kcas-main/_build/default/test/kcas_data/hashtbl_bench.exe 4 1_000_000 1000 10


Benchmark 1: kcas-main/_build/default/test/kcas/xt_benchmark.exe 1 10000
  Time (mean ± σ):       6.9 ms ±   0.3 ms    [User: 5.9 ms, System: 0.6 ms]
  Range (min … max):     6.7 ms …  10.8 ms    437 runs
 
  Warning: Statistical outliers were detected. Consider re-running this benchmark on a quiet system without any interferences from other programs. It might help to use the '--warmup' or '--prepare' options.
 
Benchmark 2: kcas-this/_build/default/test/kcas/xt_benchmark.exe 1 10000
  Time (mean ± σ):       7.2 ms ±   0.1 ms    [User: 6.2 ms, System: 0.7 ms]
  Range (min … max):     7.1 ms …   8.1 ms    418 runs
 
  Warning: Statistical outliers were detected. Consider re-running this benchmark on a quiet system without any interferences from other programs. It might help to use the '--warmup' or '--prepare' options.
 
Summary
  kcas-main/_build/default/test/kcas/xt_benchmark.exe 1 10000 ran
    1.05 ± 0.05 times faster than kcas-this/_build/default/test/kcas/xt_benchmark.exe 1 10000


Benchmark 1: kcas-main/_build/default/test/kcas/xt_benchmark.exe 2 10000
  Time (mean ± σ):      13.3 ms ±   0.1 ms    [User: 12.3 ms, System: 0.7 ms]
  Range (min … max):    13.1 ms …  13.6 ms    226 runs
 
Benchmark 2: kcas-this/_build/default/test/kcas/xt_benchmark.exe 2 10000
  Time (mean ± σ):      13.6 ms ±   0.1 ms    [User: 12.6 ms, System: 0.7 ms]
  Range (min … max):    13.4 ms …  14.4 ms    220 runs
 
  Warning: Statistical outliers were detected. Consider re-running this benchmark on a quiet system without any interferences from other programs. It might help to use the '--warmup' or '--prepare' options.
 
Summary
  kcas-main/_build/default/test/kcas/xt_benchmark.exe 2 10000 ran
    1.03 ± 0.01 times faster than kcas-this/_build/default/test/kcas/xt_benchmark.exe 2 10000


Benchmark 1: kcas-main/_build/default/test/kcas/xt_benchmark.exe 4 10000
  Time (mean ± σ):      22.3 ms ±   1.3 ms    [User: 21.3 ms, System: 0.7 ms]
  Range (min … max):    21.9 ms …  37.4 ms    135 runs
 
  Warning: Statistical outliers were detected. Consider re-running this benchmark on a quiet system without any interferences from other programs. It might help to use the '--warmup' or '--prepare' options.
 
Benchmark 2: kcas-this/_build/default/test/kcas/xt_benchmark.exe 4 10000
  Time (mean ± σ):      22.6 ms ±   0.1 ms    [User: 21.5 ms, System: 0.8 ms]
  Range (min … max):    22.4 ms …  22.9 ms    132 runs
 
Summary
  kcas-main/_build/default/test/kcas/xt_benchmark.exe 4 10000 ran
    1.01 ± 0.06 times faster than kcas-this/_build/default/test/kcas/xt_benchmark.exe 4 10000


Benchmark 1: kcas-main/_build/default/test/kcas/xt_parallel_cmp_bench.exe 100000
  Time (mean ± σ):      18.6 ms ±   2.0 ms    [User: 29.7 ms, System: 1.7 ms]
  Range (min … max):    16.9 ms …  27.1 ms    144 runs
 
  Warning: The first benchmarking run for this command was significantly slower than the rest (20.8 ms). This could be caused by (filesystem) caches that were not filled until after the first run. You are already using the '--warmup' option which helps to fill these caches before the actual benchmark. You can either try to increase the warmup count further or re-run this benchmark on a quiet system in case it was a random outlier. Alternatively, consider using the '--prepare' option to clear the caches before each timing run.
 
Benchmark 2: kcas-this/_build/default/test/kcas/xt_parallel_cmp_bench.exe 100000
  Time (mean ± σ):      19.5 ms ±   1.9 ms    [User: 31.4 ms, System: 1.7 ms]
  Range (min … max):    17.1 ms …  21.6 ms    171 runs
 
Summary
  kcas-main/_build/default/test/kcas/xt_parallel_cmp_bench.exe 100000 ran
    1.05 ± 0.15 times faster than kcas-this/_build/default/test/kcas/xt_parallel_cmp_bench.exe 100000


Benchmark 1: kcas-main/_build/default/test/kcas/xt_parallel_cmp_bench.exe 200000
  Time (mean ± σ):      34.3 ms ±   3.6 ms    [User: 56.8 ms, System: 2.2 ms]
  Range (min … max):    31.5 ms …  41.5 ms    75 runs
 
  Warning: The first benchmarking run for this command was significantly slower than the rest (39.5 ms). This could be caused by (filesystem) caches that were not filled until after the first run. You are already using the '--warmup' option which helps to fill these caches before the actual benchmark. You can either try to increase the warmup count further or re-run this benchmark on a quiet system in case it was a random outlier. Alternatively, consider using the '--prepare' option to clear the caches before each timing run.
 
Benchmark 2: kcas-this/_build/default/test/kcas/xt_parallel_cmp_bench.exe 200000
  Time (mean ± σ):      36.9 ms ±   3.8 ms    [User: 61.9 ms, System: 2.3 ms]
  Range (min … max):    32.3 ms …  40.6 ms    91 runs
 
  Warning: Statistical outliers were detected. Consider re-running this benchmark on a quiet system without any interferences from other programs. It might help to use the '--warmup' or '--prepare' options.
 
Summary
  kcas-main/_build/default/test/kcas/xt_parallel_cmp_bench.exe 200000 ran
    1.08 ± 0.16 times faster than kcas-this/_build/default/test/kcas/xt_parallel_cmp_bench.exe 200000


Benchmark 1: kcas-main/_build/default/test/kcas/xt_parallel_cmp_bench.exe 400000
  Time (mean ± σ):      68.4 ms ±   7.8 ms    [User: 116.7 ms, System: 3.4 ms]
  Range (min … max):    60.8 ms …  78.1 ms    48 runs
 
  Warning: Statistical outliers were detected. Consider re-running this benchmark on a quiet system without any interferences from other programs. It might help to use the '--warmup' or '--prepare' options.
 
Benchmark 2: kcas-this/_build/default/test/kcas/xt_parallel_cmp_bench.exe 400000
  Time (mean ± σ):      71.6 ms ±   7.5 ms    [User: 123.0 ms, System: 3.5 ms]
  Range (min … max):    62.2 ms …  78.5 ms    48 runs
 
  Warning: Statistical outliers were detected. Consider re-running this benchmark on a quiet system without any interferences from other programs. It might help to use the '--warmup' or '--prepare' options.
 
Summary
  kcas-main/_build/default/test/kcas/xt_parallel_cmp_bench.exe 400000 ran
    1.05 ± 0.16 times faster than kcas-this/_build/default/test/kcas/xt_parallel_cmp_bench.exe 400000


Benchmark 1: kcas-main/_build/default/test/kcas/benchmark.exe 1 10000
  Time (mean ± σ):       3.6 ms ±   0.1 ms    [User: 2.7 ms, System: 0.7 ms]
  Range (min … max):     3.5 ms …   4.6 ms    786 runs
 
  Warning: Statistical outliers were detected. Consider re-running this benchmark on a quiet system without any interferences from other programs. It might help to use the '--warmup' or '--prepare' options.
 
Benchmark 2: kcas-this/_build/default/test/kcas/benchmark.exe 1 10000
  Time (mean ± σ):       3.7 ms ±   0.0 ms    [User: 2.7 ms, System: 0.7 ms]
  Range (min … max):     3.6 ms …   4.2 ms    715 runs
 
  Warning: The first benchmarking run for this command was significantly slower than the rest (4.2 ms). This could be caused by (filesystem) caches that were not filled until after the first run. You are already using the '--warmup' option which helps to fill these caches before the actual benchmark. You can either try to increase the warmup count further or re-run this benchmark on a quiet system in case it was a random outlier. Alternatively, consider using the '--prepare' option to clear the caches before each timing run.
 
Summary
  kcas-main/_build/default/test/kcas/benchmark.exe 1 10000 ran
    1.02 ± 0.03 times faster than kcas-this/_build/default/test/kcas/benchmark.exe 1 10000


Benchmark 1: kcas-main/_build/default/test/kcas/benchmark.exe 2 10000
  Time (mean ± σ):       8.3 ms ±   0.5 ms    [User: 7.3 ms, System: 0.7 ms]
  Range (min … max):     8.1 ms …  15.7 ms    364 runs
 
  Warning: Statistical outliers were detected. Consider re-running this benchmark on a quiet system without any interferences from other programs. It might help to use the '--warmup' or '--prepare' options.
 
Benchmark 2: kcas-this/_build/default/test/kcas/benchmark.exe 2 10000
  Time (mean ± σ):       8.3 ms ±   0.0 ms    [User: 7.3 ms, System: 0.7 ms]
  Range (min … max):     8.2 ms …   8.6 ms    361 runs
 
  Warning: Statistical outliers were detected. Consider re-running this benchmark on a quiet system without any interferences from other programs. It might help to use the '--warmup' or '--prepare' options.
 
Summary
  kcas-main/_build/default/test/kcas/benchmark.exe 2 10000 ran
    1.00 ± 0.06 times faster than kcas-this/_build/default/test/kcas/benchmark.exe 2 10000


Benchmark 1: kcas-main/_build/default/test/kcas/benchmark.exe 4 10000
  Time (mean ± σ):      13.2 ms ±   0.0 ms    [User: 12.3 ms, System: 0.7 ms]
  Range (min … max):    13.1 ms …  13.5 ms    227 runs
 
  Warning: Statistical outliers were detected. Consider re-running this benchmark on a quiet system without any interferences from other programs. It might help to use the '--warmup' or '--prepare' options.
 
Benchmark 2: kcas-this/_build/default/test/kcas/benchmark.exe 4 10000
  Time (mean ± σ):      13.3 ms ±   0.0 ms    [User: 12.3 ms, System: 0.7 ms]
  Range (min … max):    13.2 ms …  13.6 ms    225 runs
 
  Warning: Statistical outliers were detected. Consider re-running this benchmark on a quiet system without any interferences from other programs. It might help to use the '--warmup' or '--prepare' options.
 
Summary
  kcas-main/_build/default/test/kcas/benchmark.exe 4 10000 ran
    1.01 ± 0.01 times faster than kcas-this/_build/default/test/kcas/benchmark.exe 4 10000


Benchmark 1: kcas-main/_build/default/test/kcas/benchmark.exe 1 200000
  Time (mean ± σ):      35.4 ms ±   0.3 ms    [User: 34.4 ms, System: 0.7 ms]
  Range (min … max):    34.9 ms …  36.0 ms    84 runs
 
Benchmark 2: kcas-this/_build/default/test/kcas/benchmark.exe 1 200000
  Time (mean ± σ):      35.6 ms ±   0.4 ms    [User: 34.4 ms, System: 0.8 ms]
  Range (min … max):    35.0 ms …  37.3 ms    84 runs
 
Summary
  kcas-main/_build/default/test/kcas/benchmark.exe 1 200000 ran
    1.00 ± 0.01 times faster than kcas-this/_build/default/test/kcas/benchmark.exe 1 200000


Benchmark 1: kcas-main/_build/default/test/kcas/benchmark.exe 2 200000
  Time (mean ± σ):     127.4 ms ±   0.5 ms    [User: 126.1 ms, System: 0.9 ms]
  Range (min … max):   126.7 ms … 128.3 ms    23 runs
 
Benchmark 2: kcas-this/_build/default/test/kcas/benchmark.exe 2 200000
  Time (mean ± σ):     126.6 ms ±   0.3 ms    [User: 125.2 ms, System: 1.0 ms]
  Range (min … max):   126.1 ms … 127.2 ms    23 runs
 
Summary
  kcas-this/_build/default/test/kcas/benchmark.exe 2 200000 ran
    1.01 ± 0.00 times faster than kcas-main/_build/default/test/kcas/benchmark.exe 2 200000


Benchmark 1: kcas-main/_build/default/test/kcas/benchmark.exe 4 200000
  Time (mean ± σ):     227.3 ms ±   0.2 ms    [User: 225.7 ms, System: 1.1 ms]
  Range (min … max):   227.0 ms … 227.5 ms    13 runs
 
Benchmark 2: kcas-this/_build/default/test/kcas/benchmark.exe 4 200000
  Time (mean ± σ):     227.4 ms ±   0.3 ms    [User: 225.8 ms, System: 1.1 ms]
  Range (min … max):   227.1 ms … 228.0 ms    13 runs
 
Summary
  kcas-main/_build/default/test/kcas/benchmark.exe 4 200000 ran
    1.00 ± 0.00 times faster than kcas-this/_build/default/test/kcas/benchmark.exe 4 200000

@polytypic polytypic force-pushed the timeout branch 13 times, most recently from be42de5 to 379d83c Compare June 27, 2023 16:53
Fun.protect ~finally @@ fun () ->
(match op ~timeoutf:0.1 x with
| () -> assert false
| exception Timeout.Timeout -> ());
Copy link
Collaborator Author

@polytypic polytypic Jun 27, 2023

Choose a reason for hiding this comment

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

I used Alcotest.check_raises here, but I saw the following error on CI

[exception] Stdlib.Queue.Empty
            Raised at Stdlib__Domain.join in file "domain.ml", line 258, characters 16-24
            Called from Stdlib__List.iter in file "list.ml", line 110, characters 12-15
            Called from Alcotest_engine__Core.Make.protect_test.(fun) in file "src/alcotest-engine/core.ml", line 181, characters 17-23
            Called from Alcotest_engine__Monad.Identity.catch in file "src/alcotest-engine/monad.ml", line 24, characters 31-35

which I assume comes from inside Alcotest, because Stdlib.Queue is not used anywhere in kcas.

See issue in alcotest.

@polytypic polytypic merged commit 8165087 into main Jun 27, 2023
@polytypic polytypic deleted the timeout branch June 27, 2023 17:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Consider timeouts
1 participant