Allow configuring high_watermark

This commit is contained in:
Shon Feder 2025-06-30 22:01:13 -04:00
parent ca31707395
commit 18f58c3ac5
No known key found for this signature in database
2 changed files with 18 additions and 12 deletions

View file

@ -7,14 +7,15 @@ type 'a t = {
mutable start: Mtime.t;
}
let make ?(batch = 1) ?timeout () : _ t =
let high_watermark batch_size =
if batch_size = 1 then
100
else
batch_size * 10
let make ?(batch = 1) ?(high_watermark = high_watermark batch) ?timeout () : _ t
=
assert (batch > 0);
let high_watermark =
if batch = 1 then
100
else
batch * 10
in
{
size = 0;
start = Mtime_clock.now ();

View file

@ -2,15 +2,20 @@
type 'a t
val make : ?batch:int -> ?timeout:Mtime.span -> unit -> 'a t
val make :
?batch:int -> ?high_watermark:int -> ?timeout:Mtime.span -> unit -> 'a t
(** [make ()] is a new batch
@param batch
the number of elements after which the batch will be considered {b full},
and ready to pop. A "high water mark" is also derived form the batch as
[if batch = 1 then 100 else batch * 10]. This sets a limit after which new
elements will be [`Dropped] by {!push}. Set to [0] to disable batching.
Default [1].
and ready to pop. Set to [0] to disable batching. It is required that
[batch >= 0]. Default [1].
@param high_watermark
the batch size limit after which new elements will be [`Dropped] by
{!push}. This prevents the queue from growing too fast for effective
transmission in case of signal floods. Default
[if batch = 1 then 100 else batch * 10].
@param timeout
the time span after which a batch is ready to pop, whether or not it is