Skip to content

Commit 65211c5

Browse files
Lock free skiplist with size (#99)
Add skiplist with generalized size computation --------- Co-authored-by: Carine Morel <[email protected]>, Sooraj Srinivasan <[email protected]>
1 parent 719846f commit 65211c5

File tree

12 files changed

+873
-0
lines changed

12 files changed

+873
-0
lines changed

bench/bench_skiplist.ml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
open Saturn
2+
3+
let workload num_elems num_threads add remove =
4+
let sl = Skiplist.create ~compare:Int.compare () in
5+
let elems = Array.init num_elems (fun _ -> Random.int 10000) in
6+
let push () =
7+
Domain.spawn (fun () ->
8+
let start_time = Unix.gettimeofday () in
9+
for i = 0 to (num_elems - 1) / num_threads do
10+
Domain.cpu_relax ();
11+
let prob = Random.float 1.0 in
12+
if prob < add then Skiplist.try_add sl (Random.int 10000) () |> ignore
13+
else if prob >= add && prob < add +. remove then
14+
Skiplist.try_remove sl (Random.int 10000) |> ignore
15+
else Skiplist.mem sl elems.(i) |> ignore
16+
done;
17+
start_time)
18+
in
19+
let threads = List.init num_threads (fun _ -> push ()) in
20+
let start_time_threads =
21+
List.map (fun domain -> Domain.join domain) threads
22+
in
23+
let end_time = Unix.gettimeofday () in
24+
let time_diff = end_time -. List.nth start_time_threads 0 in
25+
time_diff
26+
27+
(* A write heavy workload with threads with 50% adds and 50% removes. *)
28+
let write_heavy_workload num_elems num_threads =
29+
workload num_elems num_threads 0.5 0.5
30+
31+
(* A regular workload with 90% reads, 9% adds and 1% removes. *)
32+
let read_heavy_workload num_elems num_threads =
33+
workload num_elems num_threads 0.09 0.01
34+
35+
let moderate_heavy_workload num_elems num_threads =
36+
workload num_elems num_threads 0.2 0.1
37+
38+
let balanced_heavy_workload num_elems num_threads =
39+
workload num_elems num_threads 0.3 0.2
40+
41+
let bench ~workload_type ~num_elems ~num_threads () =
42+
let workload =
43+
if workload_type = "read_heavy" then read_heavy_workload
44+
else if workload_type = "moderate_heavy" then moderate_heavy_workload
45+
else if workload_type = "balanced_heavy" then balanced_heavy_workload
46+
else write_heavy_workload
47+
in
48+
let results = ref [] in
49+
for i = 1 to 10 do
50+
let time = workload num_elems num_threads in
51+
if i > 1 then results := time :: !results
52+
done;
53+
let results = List.sort Float.compare !results in
54+
let median_time = List.nth results 4 in
55+
let median_throughput = Float.of_int num_elems /. median_time in
56+
Benchmark_result.create_generic ~median_time ~median_throughput
57+
("atomic_skiplist_" ^ workload_type)

bench/main.ml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ let benchmark_list =
77
Mpmc_queue.bench ~use_cas:true ~takers:4 ~pushers:4;
88
Mpmc_queue.bench ~use_cas:true ~takers:1 ~pushers:8;
99
Mpmc_queue.bench ~use_cas:true ~takers:8 ~pushers:1;
10+
Bench_skiplist.bench ~workload_type:"read_heavy" ~num_elems:2000000
11+
~num_threads:2;
12+
Bench_skiplist.bench ~workload_type:"moderate_heavy" ~num_elems:2000000
13+
~num_threads:2;
1014
]
1115

1216
let () =

src/saturn.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,4 @@ module Single_prod_single_cons_queue =
3535

3636
module Single_consumer_queue = Saturn_lockfree.Single_consumer_queue
3737
module Relaxed_queue = Mpmc_relaxed_queue
38+
module Skiplist = Saturn_lockfree.Skiplist

src/saturn.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,4 @@ module Single_prod_single_cons_queue =
3939

4040
module Single_consumer_queue = Saturn_lockfree.Single_consumer_queue
4141
module Relaxed_queue = Mpmc_relaxed_queue
42+
module Skiplist = Saturn_lockfree.Skiplist

src_lockfree/saturn_lockfree.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,4 @@ module Single_prod_single_cons_queue = Spsc_queue
3333
module Single_consumer_queue = Mpsc_queue
3434
module Relaxed_queue = Mpmc_relaxed_queue
3535
module Size = Size
36+
module Skiplist = Skiplist

src_lockfree/saturn_lockfree.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,5 @@ module Work_stealing_deque = Ws_deque
3636
module Single_prod_single_cons_queue = Spsc_queue
3737
module Single_consumer_queue = Mpsc_queue
3838
module Relaxed_queue = Mpmc_relaxed_queue
39+
module Skiplist = Skiplist
3940
module Size = Size

0 commit comments

Comments
 (0)