Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 109 additions & 0 deletions bench/bench_ihtbl.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
open Multicore_bench
module Htbl = Picos_aux_ihtbl

module Key = struct
type t = int

let equal = Int.equal
let hash = Fun.id
end

let run_one ~budgetf ~n_domains ?(n_ops = 400 * Util.iter_factor)
?(n_keys = 1000) ~percent_mem ?(percent_add = (100 - percent_mem + 1) / 2)
?(prepopulate = true) () =
let limit_mem = percent_mem in
let limit_add = percent_mem + percent_add in

assert (0 <= limit_mem && limit_mem <= 100);
assert (limit_mem <= limit_add && limit_add <= 100);

let t = Htbl.create ~hashed_type:(module Key) () in

let n_ops = (100 + percent_mem) * n_ops / 100 in
let n_ops = n_ops * n_domains in

let n_ops_todo = Countdown.create ~n_domains () in

let before () =
Htbl.clear t;
assert (Htbl.non_linearizable_length t = 0);
Countdown.non_atomic_set n_ops_todo n_ops
in
let init i =
let state = Random.State.make_self_init () in
if prepopulate then begin
let n = ((i + 1) * n_keys / n_domains) - (i * n_keys / n_domains) in
for _ = 1 to n do
let value = Random.State.bits state in
let key = value mod n_keys in
Htbl.try_add t key value |> ignore
done
end;
state
in
let work domain_index state =
let rec work () =
let n = Countdown.alloc n_ops_todo ~domain_index ~batch:1000 in
if n <> 0 then begin
for _ = 1 to n do
let value = Random.State.bits state in
let op = (value asr 20) mod 100 in
let key = value mod n_keys in
if op < percent_mem then
match Htbl.find_exn t key with _ -> () | exception Not_found -> ()
else if op < limit_add then Htbl.try_add t key value |> ignore
else
match Htbl.remove_exn t key with
| _ -> ()
| exception Not_found -> ()
done;
work ()
end
in
work ()
in

let config =
Printf.sprintf "%d worker%s, %d%% reads" n_domains
(if n_domains = 1 then "" else "s")
percent_mem
in
Times.record ~budgetf ~n_domains ~before ~init ~work ()
|> Times.to_thruput_metrics ~n:n_ops ~singular:"operation" ~config

let run_fill1m ~budgetf ~n_domains () =
let n_ops = 250_000 * n_domains in
let t = Htbl.create ~hashed_type:(module Key) () in
let before () =
Htbl.clear t;
assert (Htbl.non_linearizable_length t = 0)
in
let init i =
let k0 = i * n_ops / n_domains in
let k1 = ((i + 1) * n_ops / n_domains) - 1 in
(k0, k1)
in
let work _ (k0, k1) =
for k = k0 to k1 do
assert (Htbl.try_add t k ())
done
in
let after () = assert (n_ops = Htbl.non_linearizable_length t) in
let config =
Printf.sprintf "%d worker%s" n_domains (if n_domains = 1 then "" else "s")
in
Times.record ~n_runs_min:19 ~budgetf ~n_domains ~before ~init ~work ~after ()
|> Times.to_thruput_metrics ~n:n_ops ~singular:"add" ~config

let run_suite ~budgetf =
[ 1; 2; 4; 8 ]
|> List.concat_map @@ fun n_domains ->
if Picos_domain.recommended_domain_count () < n_domains then []
else
let basic =
[ 10; 50; 90 ]
|> List.concat_map @@ fun percent_mem ->
run_one ~budgetf ~n_domains ~percent_mem ()
in
let fill1m = run_fill1m ~budgetf ~n_domains () in
basic @ fill1m
2 changes: 2 additions & 0 deletions bench/dune
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
(run %{test} -brief "Picos_mpmcq")
(run %{test} -brief "Picos_mpscq")
(run %{test} -brief "Picos_htbl")
(run %{test} -brief "Picos_ihtbl")
(run %{test} -brief "Hashtbl with Picos_std_sync")
(run %{test} -brief "Picos_stdio")
(run %{test} -brief "Picos_sync Stream")
Expand All @@ -36,6 +37,7 @@
picos.domain
picos.thread
picos_aux.htbl
picos_aux.ihtbl
picos_aux.mpmcq
picos_aux.mpscq
picos_io
Expand Down
1 change: 1 addition & 0 deletions bench/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ let benchmarks =
("Picos_mpmcq", Bench_mpmcq.run_suite);
("Picos_mpscq", Bench_mpscq.run_suite);
("Picos_htbl", Bench_htbl.run_suite);
("Picos_ihtbl", Bench_ihtbl.run_suite);
("Hashtbl with Picos_std_sync", Bench_hashtbl.run_suite);
("Picos_stdio", Bench_stdio.run_suite);
("Picos_sync Stream", Bench_stream.run_suite);
Expand Down
11 changes: 11 additions & 0 deletions lib/picos_aux.ihtbl/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
(library
(name picos_aux_ihtbl)
(public_name picos_aux.ihtbl)
(libraries backoff multicore-magic))

(mdx
(package picos_meta)
(enabled_if
(>= %{ocaml_version} 5.1.0))
(libraries picos_aux.ihtbl backoff)
(files picos_aux_ihtbl.mli))
Loading
Loading