Skip to content

Commit 6103cad

Browse files
committed
Use atomics internally for stats and expose as non mutable
1 parent 70abb8b commit 6103cad

File tree

14 files changed

+151
-94
lines changed

14 files changed

+151
-94
lines changed

.ocamlformat

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
version = 0.26.1
1+
version = 0.27.0
22
profile = conventional
33

4-
ocaml-version = 4.08
4+
ocaml-version = 5.3
55
break-infix = fit-or-vertical
66
parse-docstrings = true
77
indicate-multiline-delimiters = no

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## Changed
44

5+
- Use atomics in stats (#403, @clecat)
56
- Lock files are now opened with O_CLOEXEC flag (#394, @vect0r-vicall)
67
- Update to cmdliner.1.1.0 (#382, @MisterDA)
78
- Mirage support: optional dependency to unix (#396, @art-w)

bench.Dockerfile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM ocaml/opam:debian-ocaml-5.3
2+
RUN sudo ln -sf /usr/bin/opam-2.1 /usr/bin/opam
3+
RUN mkdir bench-dir && chown opam:opam bench-dir
4+
WORKDIR bench-dir
5+
RUN sudo chown opam .
6+
COPY *.opam ./
7+
RUN opam remote add origin https://github.com/ocaml/opam-repository.git && opam update
8+
RUN opam pin -yn --with-version=dev .
9+
RUN opam install -y --deps-only --with-test .
10+
COPY . ./
11+
ENTRYPOINT opam exec -- make bench

bench/bench.ml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,11 @@ module Benchmark = struct
133133
Write amplification in syscalls: %f@,\
134134
Write amplification in bytes: %f@,\
135135
Last 10 merges cumulated duration (μs): %f@\n\
136-
Number of merges : %d@]" Mtime.Span.pp result.time result.ops_per_sec
137-
result.mbs_per_sec result.read_amplification_calls
138-
result.read_amplification_size result.write_amplification_calls
139-
result.write_amplification_size result.merges_duration result.nb_merges
136+
Number of merges : %d@]"
137+
Mtime.Span.pp result.time result.ops_per_sec result.mbs_per_sec
138+
result.read_amplification_calls result.read_amplification_size
139+
result.write_amplification_calls result.write_amplification_size
140+
result.merges_duration result.nb_merges
140141
end
141142

142143
let make_bindings_pool nb_entries =
@@ -382,9 +383,9 @@ let pp_config fmt config =
382383
Log size: %d@,\
383384
Seed: %d@,\
384385
Metrics: %b@,\
385-
Sampling interval: %d@]" config.key_size config.value_size
386-
config.nb_entries config.log_size config.seed config.with_metrics
387-
config.sampling_interval
386+
Sampling interval: %d@]"
387+
config.key_size config.value_size config.nb_entries config.log_size
388+
config.seed config.with_metrics config.sampling_interval
388389

389390
let cleanup root =
390391
let files = [ "data"; "log"; "lock"; "log_async"; "merge" ] in

bench/replay.ml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ module Encoding = struct
8888
end
8989

9090
let decoded_seq_of_encoded_chan_with_prefixes :
91-
'a. 'a Repr.ty -> in_channel -> 'a Seq.t =
91+
'a. 'a Repr.ty -> in_channel -> 'a Seq.t =
9292
fun repr channel ->
9393
let decode_bin = Repr.decode_bin repr |> Repr.unstage in
9494
let decode_prefix = Repr.(decode_bin int32 |> unstage) in
@@ -171,9 +171,8 @@ end
171171
let hash_of_string = Repr.of_string Encoding.Hash.t
172172

173173
module Bench_suite
174-
(Store : S
175-
with type key = Encoding.Hash.t
176-
and type value = Int63.t * int * char) =
174+
(Store :
175+
S with type key = Encoding.Hash.t and type value = Int63.t * int * char) =
177176
struct
178177
let key_to_hash k =
179178
match hash_of_string k with

index-bench.opam

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ license: "MIT"
66
homepage: "https://github.com/mirage/index"
77
bug-reports: "https://github.com/mirage/index/issues"
88
depends: [
9-
"ocaml" {>= "4.03.0"}
9+
"ocaml" {>= "5.0.0"}
1010
"cmdliner" {>= "1.1.0"}
1111
"dune" {>= "2.7.0"}
1212
"fmt"

index.opam

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ build: [
1919
]
2020

2121
depends: [
22-
"ocaml" {>= "4.08.0"}
22+
"ocaml" {>= "5.0.0"}
2323
"dune" {>= "2.7.0"}
2424
"optint" {>= "0.1.0"}
2525
"repr" {>= "0.6.0"}

src/data.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ module type Key = sig
1212
(** The equality function for keys. *)
1313

1414
val hash : t -> int
15-
(** Note: Unevenly distributed hash functions may result in performance drops. *)
15+
(** Note: Unevenly distributed hash functions may result in performance drops.
16+
*)
1617

1718
val hash_size : int
1819
(** The number of bits necessary to encode the maximum output value of

src/index.ml

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ exception RO_not_allowed
3434
(** Raised whenever a read-only instance performs a write action. *)
3535

3636
exception RW_not_allowed
37-
(** Raised whenever a read-write instance performs a reserved read-only action. *)
37+
(** Raised whenever a read-write instance performs a reserved read-only action.
38+
*)
3839

3940
exception Closed
4041
(** Raised whenever a closed instance is used. *)
@@ -167,15 +168,17 @@ struct
167168
(** The log_async file contains bindings added concurrently to a [merge]
168169
operation. It is only present when a merge is ongoing. *)
169170
mutable open_instances : int;
170-
(** The number of open instances that are shared through the [Cache.t]. *)
171+
(** The number of open instances that are shared through the [Cache.t].
172+
*)
171173
mutable lru : Lru.t;
172174
writer_lock : IO.Lock.t option;
173175
(** A lock that prevents multiple RW instances to be open at the same
174176
time. *)
175177
sync_lock : Semaphore.t;
176178
(** A lock that prevents multiple [sync] to happen at the same time. *)
177179
merge_lock : Semaphore.t;
178-
(** A lock that prevents multiple [merges] to happen at the same time. *)
180+
(** A lock that prevents multiple [merges] to happen at the same time.
181+
*)
179182
rename_lock : Semaphore.t;
180183
(** A lock used to protect a critical bit when finalizing a [merge]
181184
operation. All operations should be guarded by this lock. *)
@@ -303,7 +306,8 @@ struct
303306
if
304307
(* the generation has changed *)
305308
h.generation > Int63.succ old_generation
306-
|| (* the last sync was done between clear(log) and clear(log_async) *)
309+
||
310+
(* the last sync was done between clear(log) and clear(log_async) *)
307311
(h.generation = Int63.succ old_generation && h.offset = Int63.zero)
308312
then (
309313
(* close the file .*)
@@ -324,9 +328,9 @@ struct
324328
"[%s] log_async IO header monotonicity violated during sync:@,\
325329
\ offset: %a -> %a@,\
326330
\ generation: %a -> %a@,\
327-
Reloading the log to compensate." (Filename.basename t.root)
328-
Int63.pp old_offset Int63.pp h.offset Int63.pp old_generation
329-
Int63.pp h.generation);
331+
Reloading the log to compensate."
332+
(Filename.basename t.root) Int63.pp old_offset Int63.pp h.offset
333+
Int63.pp old_generation Int63.pp h.generation);
330334
Log_file.reload log)
331335

332336
(** Syncs the [index] of the instance by checking on-disk changes. *)
@@ -446,7 +450,8 @@ struct
446450
Search.interpolation_search (IOArray.v index.io) key ~low ~high
447451
448452
(** Finds the value associated to [key] in [t]. In order, checks in
449-
[log_async] (in memory), then [log] (in memory), then [index] (on disk). *)
453+
[log_async] (in memory), then [log] (in memory), then [index] (on disk).
454+
*)
450455
let find_instance t key =
451456
let find_if_exists ~name ~find db =
452457
match db with

src/index_intf.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ module type S = sig
6060
(including both automatic flushing and explicit calls to {!flush} or
6161
{!close}).
6262
63-
This can be used to ensure certain pre-conditions are met before
64-
bindings are persisted to disk. (For instance, if the index bindings are
65-
pointers into another data-structure [d], it may be necessary to flush
66-
[d] first to avoid creating dangling pointers.)
63+
This can be used to ensure certain pre-conditions are met before bindings
64+
are persisted to disk. (For instance, if the index bindings are pointers
65+
into another data-structure [d], it may be necessary to flush [d] first to
66+
avoid creating dangling pointers.)
6767
@param cache used for instance sharing.
6868
@param fresh whether an existing index should be overwritten.
6969
@param read_only whether read-only mode is enabled for this index.

0 commit comments

Comments
 (0)