Skip to content
Closed
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
19 changes: 19 additions & 0 deletions bench/concurrent_bench.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
open Main

let read_index () =
let r = Index.v ~fresh:false ~readonly:true ~log_size index_name in
Fmt.epr "\n Read in readonly index. \n";
let count = ref 0 in
Index.iter
Copy link
Member

@samoht samoht Sep 9, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this work when the index is updated concurrently? e.g. will newly written elements be read too?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not for readonly instances. Fixed by #81 .

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I think I understand what you meant now.
The iter indeed won't see the elements added after it was called., so this bench will only read the elements that were there from previous benchs.

(fun _ _ ->
count := !count + 1;
if !count mod 1_000 = 0 then
Fmt.epr "\r%a%!" pp_stats (!count, index_size))
r

let () =
let pid = Unix.fork () in
if pid <> 0 then
let _ = Unix.fork () in
read_index ()
else add_and_find ()
9 changes: 7 additions & 2 deletions bench/dune
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(executable
(name main)
(executables
(names main concurrent_bench)
(libraries fmt index.unix))

(alias
Expand All @@ -10,3 +10,8 @@
(alias
(name runtest)
(deps main.exe))

(alias
(name cbench)
(action
(run ./concurrent_bench.exe)))
7 changes: 6 additions & 1 deletion bench/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ let t = Index.v ~fresh:true ~log_size index_name
let pp_stats ppf (count, max) =
Fmt.pf ppf "\t%4dk/%dk" (count / 1000) (max / 1000)

let () =
let add_and_find () =
let t0 = Sys.time () in
Fmt.epr "Adding %d bindings.\n%!" index_size;
let rec loop bindings i =
Expand Down Expand Up @@ -83,3 +83,8 @@ let () =
let t2 = Sys.time () -. t1 in
Fmt.epr "\n%d bindings found in %fs.\n%!" index_size t2;
print_newline ()

let () =
add_and_find ();
Index.flush t;
()