Skip to content

Commit 2d68931

Browse files
committed
Revise benchmarks
1 parent 6c53ef1 commit 2d68931

File tree

12 files changed

+172
-153
lines changed

12 files changed

+172
-153
lines changed

bench/bench_accumulator.ml

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@ let run_one ~budgetf ~n_domains ?(n_ops = 180 * Util.iter_factor) () =
66

77
let t = Accumulator.make 0 in
88

9-
let n_ops_todo = Atomic.make n_ops |> Multicore_magic.copy_as_padded in
9+
let n_ops_todo = Countdown.create ~n_domains () in
1010

11-
let init _ = () in
12-
13-
let work _ () =
11+
let init _ = Countdown.non_atomic_set n_ops_todo n_ops in
12+
let work domain_index () =
1413
let rec work () =
15-
let n = Util.alloc n_ops_todo in
14+
let n = Countdown.alloc n_ops_todo ~domain_index ~batch:1000 in
1615
if n <> 0 then
1716
let rec loop n =
1817
if 0 < n then begin
@@ -27,16 +26,16 @@ let run_one ~budgetf ~n_domains ?(n_ops = 180 * Util.iter_factor) () =
2726
work ()
2827
in
2928

30-
let after () = Atomic.set n_ops_todo n_ops in
31-
3229
let config =
3330
Printf.sprintf "%d worker%s, 0%% reads" n_domains
3431
(if n_domains = 1 then "" else "s")
3532
in
3633

37-
Times.record ~budgetf ~n_domains ~init ~work ~after ()
34+
Times.record ~budgetf ~n_domains ~init ~work ()
3835
|> Times.to_thruput_metrics ~n:n_ops ~config ~singular:"operation"
3936

4037
let run_suite ~budgetf =
41-
[ 1; 2; 4 ]
42-
|> List.concat_map @@ fun n_domains -> run_one ~n_domains ~budgetf ()
38+
[ 1; 2; 4; 8 ]
39+
|> List.concat_map @@ fun n_domains ->
40+
if Domain.recommended_domain_count () < n_domains then []
41+
else run_one ~n_domains ~budgetf ()

bench/bench_dllist.ml

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,19 @@ let run_one ~budgetf ?(n_adders = 2) ?(n_takers = 2) ?(factor = 1)
2323

2424
let t = Dllist.create () in
2525

26-
let n_msgs_to_take = Atomic.make 0 |> Multicore_magic.copy_as_padded in
27-
let n_msgs_to_add = Atomic.make 0 |> Multicore_magic.copy_as_padded in
26+
let n_msgs_to_take = Countdown.create ~n_domains:n_takers () in
27+
let n_msgs_to_add = Countdown.create ~n_domains:n_adders () in
2828

2929
let init _ =
3030
assert (Dllist.is_empty t);
31-
Atomic.set n_msgs_to_take n_msgs;
32-
Atomic.set n_msgs_to_add n_msgs
31+
Countdown.non_atomic_set n_msgs_to_take n_msgs;
32+
Countdown.non_atomic_set n_msgs_to_add n_msgs
3333
in
3434
let work i () =
3535
if i < n_adders then
36+
let domain_index = i in
3637
let rec work () =
37-
let n = Util.alloc n_msgs_to_add in
38+
let n = Countdown.alloc n_msgs_to_add ~domain_index ~batch:1000 in
3839
if 0 < n then begin
3940
for i = 1 to n do
4041
Dllist.add_r i t |> ignore
@@ -44,12 +45,13 @@ let run_one ~budgetf ?(n_adders = 2) ?(n_takers = 2) ?(factor = 1)
4445
in
4546
work ()
4647
else
48+
let domain_index = i - n_adders in
4749
let rec work () =
48-
let n = Util.alloc n_msgs_to_take in
50+
let n = Countdown.alloc n_msgs_to_take ~domain_index ~batch:1000 in
4951
if n <> 0 then begin
5052
for _ = 1 to n do
5153
while Option.is_none (Dllist.take_opt_l t) do
52-
Domain.cpu_relax ()
54+
Backoff.once Backoff.default |> ignore
5355
done
5456
done;
5557
work ()
@@ -77,4 +79,5 @@ let run_suite ~budgetf =
7779
run_single ~budgetf ()
7880
@ (Util.cross [ 1; 2 ] [ 1; 2 ]
7981
|> List.concat_map @@ fun (n_adders, n_takers) ->
80-
run_one ~budgetf ~n_adders ~n_takers ())
82+
if Domain.recommended_domain_count () < n_adders + n_takers then []
83+
else run_one ~budgetf ~n_adders ~n_takers ())

bench/bench_hashtbl.ml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@ let run_one ~budgetf ~n_domains ?(n_ops = 40 * Util.iter_factor)
1818
Hashtbl.replace t i i
1919
done;
2020

21-
let n_ops_todo = Atomic.make 0 |> Multicore_magic.copy_as_padded in
21+
let n_ops_todo = Countdown.create ~n_domains () in
2222

2323
let init _ =
24-
Atomic.set n_ops_todo n_ops;
24+
Countdown.non_atomic_set n_ops_todo n_ops;
2525
Random.State.make_self_init ()
2626
in
2727

28-
let work _ state =
28+
let work domain_index state =
2929
let rec work () =
30-
let n = Util.alloc n_ops_todo in
30+
let n = Countdown.alloc n_ops_todo ~domain_index ~batch:1000 in
3131
if n <> 0 then
3232
let rec loop n =
3333
if 0 < n then
@@ -60,6 +60,7 @@ let run_one ~budgetf ~n_domains ?(n_ops = 40 * Util.iter_factor)
6060
|> Times.to_thruput_metrics ~n:n_ops ~singular:"operation" ~config
6161

6262
let run_suite ~budgetf =
63-
Util.cross [ 90; 50; 10 ] [ 1; 2; 4 ]
63+
Util.cross [ 90; 50; 10 ] [ 1; 2; 4; 8 ]
6464
|> List.concat_map @@ fun (percent_read, n_domains) ->
65-
run_one ~budgetf ~n_domains ~percent_read ()
65+
if Domain.recommended_domain_count () < n_domains then []
66+
else run_one ~budgetf ~n_domains ~percent_read ()

bench/bench_mvar.ml

Lines changed: 38 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,19 @@ let run_one ~budgetf ?(n_adders = 2) ?(blocking_add = false) ?(n_takers = 2)
77

88
let t = Mvar.create None in
99

10-
let n_msgs_to_take = Atomic.make n_msgs |> Multicore_magic.copy_as_padded in
11-
let n_msgs_to_add = Atomic.make n_msgs |> Multicore_magic.copy_as_padded in
10+
let n_msgs_to_take = Countdown.create ~n_domains:n_takers () in
11+
let n_msgs_to_add = Countdown.create ~n_domains:n_adders () in
1212

13-
let init _ = () in
13+
let init _ =
14+
Countdown.non_atomic_set n_msgs_to_take n_msgs;
15+
Countdown.non_atomic_set n_msgs_to_add n_msgs
16+
in
1417
let work i () =
1518
if i < n_adders then
19+
let domain_index = i in
1620
if blocking_add then
1721
let rec work () =
18-
let n = Util.alloc n_msgs_to_add in
22+
let n = Countdown.alloc n_msgs_to_add ~domain_index ~batch:1000 in
1923
if 0 < n then begin
2024
for i = 1 to n do
2125
Mvar.put t i
@@ -26,45 +30,43 @@ let run_one ~budgetf ?(n_adders = 2) ?(blocking_add = false) ?(n_takers = 2)
2630
work ()
2731
else
2832
let rec work () =
29-
let n = Util.alloc n_msgs_to_add in
33+
let n = Countdown.alloc n_msgs_to_add ~domain_index ~batch:1000 in
3034
if 0 < n then begin
3135
for i = 1 to n do
3236
while not (Mvar.try_put t i) do
33-
Domain.cpu_relax ()
37+
Backoff.once Backoff.default |> ignore
3438
done
3539
done;
3640
work ()
3741
end
3842
in
3943
work ()
40-
else if blocking_take then
41-
let rec work () =
42-
let n = Util.alloc n_msgs_to_take in
43-
if n <> 0 then begin
44-
for _ = 1 to n do
45-
ignore (Mvar.take t)
46-
done;
47-
work ()
48-
end
49-
in
50-
work ()
5144
else
52-
let rec work () =
53-
let n = Util.alloc n_msgs_to_take in
54-
if n <> 0 then begin
55-
for _ = 1 to n do
56-
while Option.is_none (Mvar.take_opt t) do
57-
Domain.cpu_relax ()
58-
done
59-
done;
60-
work ()
61-
end
62-
in
63-
work ()
64-
in
65-
let after () =
66-
Atomic.set n_msgs_to_take n_msgs;
67-
Atomic.set n_msgs_to_add n_msgs
45+
let domain_index = i - n_adders in
46+
if blocking_take then
47+
let rec work () =
48+
let n = Countdown.alloc n_msgs_to_take ~domain_index ~batch:1000 in
49+
if n <> 0 then begin
50+
for _ = 1 to n do
51+
ignore (Mvar.take t)
52+
done;
53+
work ()
54+
end
55+
in
56+
work ()
57+
else
58+
let rec work () =
59+
let n = Countdown.alloc n_msgs_to_take ~domain_index ~batch:1000 in
60+
if n <> 0 then begin
61+
for _ = 1 to n do
62+
while Option.is_none (Mvar.take_opt t) do
63+
Backoff.once Backoff.default |> ignore
64+
done
65+
done;
66+
work ()
67+
end
68+
in
69+
work ()
6870
in
6971

7072
let config =
@@ -79,7 +81,7 @@ let run_one ~budgetf ?(n_adders = 2) ?(blocking_add = false) ?(n_takers = 2)
7981
(format "taker" blocking_take n_takers)
8082
in
8183

82-
Times.record ~budgetf ~n_domains ~init ~work ~after ()
84+
Times.record ~budgetf ~n_domains ~init ~work ()
8385
|> Times.to_thruput_metrics ~n:n_msgs ~singular:"message" ~config
8486

8587
let run_suite ~budgetf =
@@ -88,4 +90,5 @@ let run_suite ~budgetf =
8890
(Util.cross [ 1; 2 ] [ false; true ])
8991
|> List.concat_map
9092
@@ fun ((n_adders, blocking_add), (n_takers, blocking_take)) ->
91-
run_one ~budgetf ~n_adders ~blocking_add ~n_takers ~blocking_take ()
93+
if Domain.recommended_domain_count () < n_adders + n_takers then []
94+
else run_one ~budgetf ~n_adders ~blocking_add ~n_takers ~blocking_take ()

bench/bench_parallel_cmp.ml

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ let run_one ~budgetf ~n_domains ?(n_ops = 50 * Util.iter_factor) () =
88
let b = Loc.make ~padded:true 52 in
99
let xs = Loc.make_array ~padded:true n_domains 0 in
1010

11-
let n_ops_todo = Atomic.make n_ops |> Multicore_magic.copy_as_padded in
11+
let n_ops_todo = Countdown.create ~n_domains () in
1212

13-
let init i = Array.unsafe_get xs i in
14-
15-
let work _ x =
13+
let init i =
14+
Countdown.non_atomic_set n_ops_todo n_ops;
15+
Array.unsafe_get xs i
16+
in
17+
let work domain_index x =
1618
let tx1 ~xt =
1719
let a = Xt.get ~xt a in
1820
let b = Xt.get ~xt b in
@@ -23,7 +25,7 @@ let run_one ~budgetf ~n_domains ?(n_ops = 50 * Util.iter_factor) () =
2325
Xt.set ~xt x (a + b)
2426
in
2527
let rec work () =
26-
let n = Util.alloc n_ops_todo in
28+
let n = Countdown.alloc n_ops_todo ~domain_index ~batch:1000 in
2729
if n <> 0 then begin
2830
for _ = 1 to n asr 1 do
2931
Xt.commit { tx = tx1 };
@@ -35,15 +37,15 @@ let run_one ~budgetf ~n_domains ?(n_ops = 50 * Util.iter_factor) () =
3537
work ()
3638
in
3739

38-
let after () = Atomic.set n_ops_todo n_ops in
39-
4040
let config =
4141
Printf.sprintf "%d worker%s" n_domains (if n_domains = 1 then "" else "s")
4242
in
4343

44-
Times.record ~budgetf ~n_domains ~init ~work ~after ()
44+
Times.record ~budgetf ~n_domains ~init ~work ()
4545
|> Times.to_thruput_metrics ~n:n_ops ~singular:"transaction" ~config
4646

4747
let run_suite ~budgetf =
4848
[ 1; 2; 4 ]
49-
|> List.concat_map @@ fun n_domains -> run_one ~budgetf ~n_domains ()
49+
|> List.concat_map @@ fun n_domains ->
50+
if Domain.recommended_domain_count () < n_domains then []
51+
else run_one ~budgetf ~n_domains ()

bench/bench_queue.ml

Lines changed: 36 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,19 @@ let run_one ~budgetf ?(n_adders = 2) ?(blocking_add = false) ?(n_takers = 2)
2121

2222
let t = Queue.create () in
2323

24-
let n_msgs_to_take = Atomic.make 0 |> Multicore_magic.copy_as_padded in
25-
let n_msgs_to_add = Atomic.make 0 |> Multicore_magic.copy_as_padded in
24+
let n_msgs_to_take = Countdown.create ~n_domains:n_takers () in
25+
let n_msgs_to_add = Countdown.create ~n_domains:n_adders () in
2626

2727
let init _ =
2828
assert (Queue.is_empty t);
29-
Atomic.set n_msgs_to_take n_msgs;
30-
Atomic.set n_msgs_to_add n_msgs
29+
Countdown.non_atomic_set n_msgs_to_take n_msgs;
30+
Countdown.non_atomic_set n_msgs_to_add n_msgs
3131
in
3232
let work i () =
3333
if i < n_adders then
34+
let domain_index = i in
3435
let rec work () =
35-
let n = Util.alloc n_msgs_to_add in
36+
let n = Countdown.alloc n_msgs_to_add ~domain_index ~batch:1000 in
3637
if 0 < n then begin
3738
for i = 1 to n do
3839
Queue.add i t
@@ -41,30 +42,32 @@ let run_one ~budgetf ?(n_adders = 2) ?(blocking_add = false) ?(n_takers = 2)
4142
end
4243
in
4344
work ()
44-
else if blocking_take then
45-
let rec work () =
46-
let n = Util.alloc n_msgs_to_take in
47-
if n <> 0 then begin
48-
for _ = 1 to n do
49-
ignore (Queue.take_blocking t)
50-
done;
51-
work ()
52-
end
53-
in
54-
work ()
5545
else
56-
let rec work () =
57-
let n = Util.alloc n_msgs_to_take in
58-
if n <> 0 then begin
59-
for _ = 1 to n do
60-
while Option.is_none (Queue.take_opt t) do
61-
Domain.cpu_relax ()
62-
done
63-
done;
64-
work ()
65-
end
66-
in
67-
work ()
46+
let domain_index = i - n_adders in
47+
if blocking_take then
48+
let rec work () =
49+
let n = Countdown.alloc n_msgs_to_take ~domain_index ~batch:1000 in
50+
if n <> 0 then begin
51+
for _ = 1 to n do
52+
ignore (Queue.take_blocking t)
53+
done;
54+
work ()
55+
end
56+
in
57+
work ()
58+
else
59+
let rec work () =
60+
let n = Countdown.alloc n_msgs_to_take ~domain_index ~batch:1000 in
61+
if n <> 0 then begin
62+
for _ = 1 to n do
63+
while Option.is_none (Queue.take_opt t) do
64+
Backoff.once Backoff.default |> ignore
65+
done
66+
done;
67+
work ()
68+
end
69+
in
70+
work ()
6871
in
6972

7073
let config =
@@ -85,8 +88,10 @@ let run_one ~budgetf ?(n_adders = 2) ?(blocking_add = false) ?(n_takers = 2)
8588
let run_suite ~budgetf =
8689
run_one_domain ~budgetf ()
8790
@ (Util.cross
88-
(Util.cross [ 1; 2 ] [ false ])
89-
(Util.cross [ 1; 2 ] [ false; true ])
91+
(Util.cross [ 1; 2; 4 ] [ false ])
92+
(Util.cross [ 1; 2; 4 ] [ false; true ])
9093
|> List.concat_map
9194
@@ fun ((n_adders, blocking_add), (n_takers, blocking_take)) ->
92-
run_one ~budgetf ~n_adders ~blocking_add ~n_takers ~blocking_take ())
95+
if Domain.recommended_domain_count () < n_adders + n_takers then []
96+
else run_one ~budgetf ~n_adders ~blocking_add ~n_takers ~blocking_take ()
97+
)

0 commit comments

Comments
 (0)