Skip to content

Commit 8669f5e

Browse files
committed
Experimental more incremental resize approach
1 parent 50d22cd commit 8669f5e

8 files changed

Lines changed: 786 additions & 0 deletions

File tree

bench/bench_ihtbl.ml

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
open Multicore_bench
2+
module Htbl = Picos_aux_ihtbl
3+
4+
module Key = struct
5+
type t = int
6+
7+
let equal = Int.equal
8+
let hash = Fun.id
9+
end
10+
11+
let run_one ~budgetf ~n_domains ?(n_ops = 400 * Util.iter_factor)
12+
?(n_keys = 1000) ~percent_mem ?(percent_add = (100 - percent_mem + 1) / 2)
13+
?(prepopulate = true) () =
14+
let limit_mem = percent_mem in
15+
let limit_add = percent_mem + percent_add in
16+
17+
assert (0 <= limit_mem && limit_mem <= 100);
18+
assert (limit_mem <= limit_add && limit_add <= 100);
19+
20+
let t = Htbl.create ~hashed_type:(module Key) () in
21+
22+
let n_ops = (100 + percent_mem) * n_ops / 100 in
23+
let n_ops = n_ops * n_domains in
24+
25+
let n_ops_todo = Countdown.create ~n_domains () in
26+
27+
let before () =
28+
Htbl.clear t;
29+
assert (Htbl.non_linearizable_length t = 0);
30+
Countdown.non_atomic_set n_ops_todo n_ops
31+
in
32+
let init i =
33+
let state = Random.State.make_self_init () in
34+
if prepopulate then begin
35+
let n = ((i + 1) * n_keys / n_domains) - (i * n_keys / n_domains) in
36+
for _ = 1 to n do
37+
let value = Random.State.bits state in
38+
let key = value mod n_keys in
39+
Htbl.try_add t key value |> ignore
40+
done
41+
end;
42+
state
43+
in
44+
let work domain_index state =
45+
let rec work () =
46+
let n = Countdown.alloc n_ops_todo ~domain_index ~batch:1000 in
47+
if n <> 0 then begin
48+
for _ = 1 to n do
49+
let value = Random.State.bits state in
50+
let op = (value asr 20) mod 100 in
51+
let key = value mod n_keys in
52+
if op < percent_mem then
53+
match Htbl.find_exn t key with _ -> () | exception Not_found -> ()
54+
else if op < limit_add then Htbl.try_add t key value |> ignore
55+
else
56+
match Htbl.remove_exn t key with
57+
| _ -> ()
58+
| exception Not_found -> ()
59+
done;
60+
work ()
61+
end
62+
in
63+
work ()
64+
in
65+
66+
let config =
67+
Printf.sprintf "%d worker%s, %d%% reads" n_domains
68+
(if n_domains = 1 then "" else "s")
69+
percent_mem
70+
in
71+
Times.record ~budgetf ~n_domains ~before ~init ~work ()
72+
|> Times.to_thruput_metrics ~n:n_ops ~singular:"operation" ~config
73+
74+
let run_fill1m ~budgetf ~n_domains () =
75+
let n_ops = 250_000 * n_domains in
76+
let t = Htbl.create ~hashed_type:(module Key) () in
77+
let before () =
78+
Htbl.clear t;
79+
assert (Htbl.non_linearizable_length t = 0)
80+
in
81+
let init i =
82+
let k0 = i * n_ops / n_domains in
83+
let k1 = ((i + 1) * n_ops / n_domains) - 1 in
84+
(k0, k1)
85+
in
86+
let work _ (k0, k1) =
87+
for k = k0 to k1 do
88+
assert (Htbl.try_add t k ())
89+
done
90+
in
91+
let after () = assert (n_ops = Htbl.non_linearizable_length t) in
92+
let config =
93+
Printf.sprintf "%d worker%s" n_domains (if n_domains = 1 then "" else "s")
94+
in
95+
Times.record ~n_runs_min:19 ~budgetf ~n_domains ~before ~init ~work ~after ()
96+
|> Times.to_thruput_metrics ~n:n_ops ~singular:"add" ~config
97+
98+
let run_suite ~budgetf =
99+
[ 1; 2; 4; 8 ]
100+
|> List.concat_map @@ fun n_domains ->
101+
if Picos_domain.recommended_domain_count () < n_domains then []
102+
else
103+
let basic =
104+
[ 10; 50; 90 ]
105+
|> List.concat_map @@ fun percent_mem ->
106+
run_one ~budgetf ~n_domains ~percent_mem ()
107+
in
108+
let fill1m = run_fill1m ~budgetf ~n_domains () in
109+
basic @ fill1m

bench/dune

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
(run %{test} -brief "Picos_mpmcq")
1717
(run %{test} -brief "Picos_mpscq")
1818
(run %{test} -brief "Picos_htbl")
19+
(run %{test} -brief "Picos_ihtbl")
1920
(run %{test} -brief "Hashtbl with Picos_std_sync")
2021
(run %{test} -brief "Picos_stdio")
2122
(run %{test} -brief "Picos_sync Stream")
@@ -36,6 +37,7 @@
3637
picos.domain
3738
picos.thread
3839
picos_aux.htbl
40+
picos_aux.ihtbl
3941
picos_aux.mpmcq
4042
picos_aux.mpscq
4143
picos_io

bench/main.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ let benchmarks =
1515
("Picos_mpmcq", Bench_mpmcq.run_suite);
1616
("Picos_mpscq", Bench_mpscq.run_suite);
1717
("Picos_htbl", Bench_htbl.run_suite);
18+
("Picos_ihtbl", Bench_ihtbl.run_suite);
1819
("Hashtbl with Picos_std_sync", Bench_hashtbl.run_suite);
1920
("Picos_stdio", Bench_stdio.run_suite);
2021
("Picos_sync Stream", Bench_stream.run_suite);

lib/picos_aux.ihtbl/dune

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
(library
2+
(name picos_aux_ihtbl)
3+
(public_name picos_aux.ihtbl)
4+
(libraries backoff multicore-magic))
5+
6+
(mdx
7+
(package picos_meta)
8+
(enabled_if
9+
(>= %{ocaml_version} 5.1.0))
10+
(libraries picos_aux.ihtbl backoff)
11+
(files picos_aux_ihtbl.mli))

0 commit comments

Comments
 (0)