Skip to content

Commit aea9ab5

Browse files
committed
CP-307958: Benchmark for Db_lock
No functional change Signed-off-by: Edwin Török <[email protected]>
1 parent 1cfaab9 commit aea9ab5

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

ocaml/tests/bench/bench_pool_field.ml

+22
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,24 @@ let date_of_iso8601 () = Clock.Date.of_iso8601 date
6464
let local_session_hook () =
6565
Xapi_local_session.local_session_hook ~__context ~session_id:Ref.null
6666

67+
let atomic = Atomic.make 0
68+
69+
let atomic_inc () = Atomic.incr atomic
70+
71+
let mutex = Mutex.create ()
72+
73+
let locked_ref = ref 0
74+
75+
let with_lock = Xapi_stdext_threads.Threadext.Mutex.execute
76+
77+
let inc_locked () = incr locked_ref
78+
79+
let inc_with_mutex () = with_lock mutex inc_locked
80+
81+
let noop () = Sys.opaque_identity ()
82+
83+
let db_lock_uncontended () : unit = Xapi_database.Db_lock.with_lock noop
84+
6785
let benchmarks =
6886
[
6987
Test.make ~name:"local_session_hook" (Staged.stage local_session_hook)
@@ -73,6 +91,10 @@ let benchmarks =
7391
; Test.make ~name:"Db.Pool.get_all_records" (Staged.stage get_all)
7492
; Test.make ~name:"pool_t -> Rpc.t" (Staged.stage serialize)
7593
; Test.make ~name:"Rpc.t -> pool_t" (Staged.stage deserialize)
94+
; Test.make ~name:"Atomic.incr" (Staged.stage atomic_inc)
95+
; Test.make ~name:"Mutex+incr" (Staged.stage inc_with_mutex)
96+
; Test.make ~name:"Db_lock.with_lock uncontended"
97+
(Staged.stage db_lock_uncontended)
7698
]
7799

78100
let () = Bechamel_simple_cli.cli benchmarks

ocaml/tests/bench/dune

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,5 @@
2727
log
2828
xapi_database
2929
xapi_datamodel
30-
xapi_internal))
30+
xapi_internal
31+
xapi-stdext-threads))

0 commit comments

Comments
 (0)