Skip to content

Commit 24e39c4

Browse files
committed
Code Review changes
1 parent 8637051 commit 24e39c4

File tree

8 files changed

+340
-415
lines changed

8 files changed

+340
-415
lines changed

bench/bench_atomic_skiplist.ml

Lines changed: 44 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,90 +1,59 @@
11
open Lockfree
2-
let num_elems = 200_000
3-
let num_threads = 2
42

5-
(* A write heavy workload with threads with 50% adds and 50% removes. *)
6-
let write_heavy_workload () =
7-
let sl = Atomicskiplist.create () in
8-
(* let elems = Array.init num_elems (fun _ -> Random.int 10000) in *)
9-
let push = (fun () -> Domain.spawn ( fun () ->
10-
let start_time = Unix.gettimeofday () in
11-
for i = 0 to (num_elems - 1) do (
12-
if (i/2) < num_elems/2 then
13-
Atomicskiplist.add sl (i) |> ignore
14-
else
15-
Atomicskiplist.remove sl (i - (num_elems/2)) |> ignore)
16-
done;
17-
start_time
18-
)) in
19-
let threads = List.init num_threads (fun _ -> push ()) in
20-
let start_time_threads = List.map (fun domain -> Domain.join domain) threads in
21-
let end_time = Unix.gettimeofday () in
22-
let time_diff = end_time -. (List.nth start_time_threads 0) in
3+
let max_height = 10
4+
5+
let workload num_elems num_threads add remove =
6+
let sl = Atomicskiplist.create max_height in
7+
let elems = Array.init num_elems (fun _ -> Random.int 10000) in
8+
let push () =
9+
Domain.spawn (fun () ->
10+
let start_time = Unix.gettimeofday () in
11+
for i = 0 to (num_elems - 1) / num_threads do
12+
Domain.cpu_relax ();
13+
let prob = Random.float 1.0 in
14+
if prob < add then Atomicskiplist.add sl (Random.int 10000) |> ignore
15+
else if prob >= add && prob < add +. remove then
16+
Atomicskiplist.remove sl (Random.int 10000) |> ignore
17+
else Atomicskiplist.mem sl elems.(i) |> ignore
18+
done;
19+
start_time)
20+
in
21+
let threads = List.init num_threads (fun _ -> push ()) in
22+
let start_time_threads =
23+
List.map (fun domain -> Domain.join domain) threads
24+
in
25+
let end_time = Unix.gettimeofday () in
26+
let time_diff = end_time -. List.nth start_time_threads 0 in
2327
time_diff
2428

29+
(* A write heavy workload with threads with 50% adds and 50% removes. *)
30+
let write_heavy_workload num_elems num_threads =
31+
workload num_elems num_threads 0.5 0.5
32+
2533
(* A regular workload with 90% reads, 9% adds and 1% removes. *)
26-
let read_heavy_workload () =
27-
let sl = Atomicskiplist.create () in
28-
let elems = Array.init num_elems (fun _ -> Random.int 10000) in
29-
let push = (fun () -> Domain.spawn ( fun () ->
30-
let start_time = Unix.gettimeofday () in
31-
for i = 0 to (num_elems - 1) do (
32-
if i mod 1000 < 90 then
33-
Atomicskiplist.add sl elems.(i) |> ignore
34-
else if i mod 1000 >= 90 && i mod 1000 < 100 then
35-
Atomicskiplist.remove sl elems.(i) |> ignore
36-
else
37-
Atomicskiplist.find sl elems.(i) |> ignore
38-
)
39-
done;
40-
start_time
41-
)) in
42-
let threads = List.init num_threads (fun _ -> push ()) in
43-
let start_time_threads = List.map (fun domain -> Domain.join domain) threads in
44-
let end_time = Unix.gettimeofday () in
45-
let time_diff = end_time -. (List.nth start_time_threads 0) in
46-
time_diff
47-
48-
49-
let moderate_heavy_workload () =
50-
let sl = Atomicskiplist.create () in
51-
let elems = Array.init num_elems (fun _ -> Random.int 10000) in
52-
let push = (fun () -> Domain.spawn ( fun () ->
53-
let start_time = Unix.gettimeofday () in
54-
for i = 0 to (num_elems - 1) do (
55-
if i mod 1000 < 200 then
56-
Atomicskiplist.add sl elems.(i) |> ignore
57-
else if i mod 1000 >= 200 && i mod 1000 < 300 then
58-
Atomicskiplist.remove sl elems.(i) |> ignore
59-
else
60-
Atomicskiplist.find sl elems.(i) |> ignore
61-
)
62-
done;
63-
start_time
64-
)) in
65-
let threads = List.init num_threads (fun _ -> push ()) in
66-
let start_time_threads = List.map (fun domain -> Domain.join domain) threads in
67-
let end_time = Unix.gettimeofday () in
68-
let time_diff = end_time -. (List.nth start_time_threads 0) in
69-
time_diff
70-
34+
let read_heavy_workload num_elems num_threads =
35+
workload num_elems num_threads 0.09 0.01
36+
37+
let moderate_heavy_workload num_elems num_threads =
38+
workload num_elems num_threads 0.2 0.1
7139

40+
let balanced_heavy_workload num_elems num_threads =
41+
workload num_elems num_threads 0.3 0.2
7242

73-
let bench ~workload_type () =
43+
let bench ~workload_type ~num_elems ~num_threads () =
7444
let workload =
75-
if workload_type = "read_heavy" then
76-
read_heavy_workload
77-
else if workload_type == "moderate_heavy" then
78-
moderate_heavy_workload
79-
else
80-
write_heavy_workload
81-
in
45+
if workload_type = "read_heavy" then read_heavy_workload
46+
else if workload_type = "moderate_heavy" then moderate_heavy_workload
47+
else if workload_type = "balanced_heavy" then balanced_heavy_workload
48+
else write_heavy_workload
49+
in
8250
let results = ref [] in
8351
for i = 1 to 10 do
84-
let time = workload () in
52+
let time = workload num_elems num_threads in
8553
if i > 1 then results := time :: !results
8654
done;
8755
let results = List.sort Float.compare !results in
8856
let median_time = List.nth results 4 in
8957
let median_throughput = Float.of_int num_elems /. median_time in
90-
Benchmark_result.create_generic ~median_time ~median_throughput ("atomic_skiplist_"^workload_type)
58+
Benchmark_result.create_generic ~median_time ~median_throughput
59+
("atomic_skiplist_" ^ workload_type)

bench/main.ml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ let benchmark_list =
1616
Mpmc_queue.bench ~use_cas:true ~takers:4 ~pushers:4;
1717
Mpmc_queue.bench ~use_cas:true ~takers:1 ~pushers:8;
1818
Mpmc_queue.bench ~use_cas:true ~takers:8 ~pushers:1;
19-
Bench_atomic_skiplist.bench ~workload_type:"read_heavy";
20-
Bench_atomic_skiplist.bench ~workload_type:"moderate_heavy";
19+
Bench_atomic_skiplist.bench ~workload_type:"read_heavy" ~num_elems:2000000
20+
~num_threads:2;
21+
Bench_atomic_skiplist.bench ~workload_type:"moderate_heavy"
22+
~num_elems:2000000 ~num_threads:2;
2123
]
2224
@ backoff_benchmarks
2325

0 commit comments

Comments
 (0)