File tree Expand file tree Collapse file tree 3 files changed +48
-10
lines changed Expand file tree Collapse file tree 3 files changed +48
-10
lines changed Original file line number Diff line number Diff line change 1
- type t = { rnd : Random.State .t ; max_workers : int ; workers : int }
1
+ type t = {
2
+ rnd : Random.State .t ;
3
+ max_workers : int ;
4
+ workers : int ;
5
+ supervisor_restart_limit : int ;
6
+ supervisor_restart_period : int ;
7
+ }
2
8
3
- let make ?workers () =
9
+ let pp fmt t =
10
+ Format. fprintf fmt " == RIOT CONFIG ==\n " ;
11
+ Format. fprintf fmt " * max_wokers=%d\n " t.max_workers;
12
+ Format. fprintf fmt " * workers=%d\n " t.workers;
13
+ Format. fprintf fmt " * supervisor_restart_limit=%d\n " t.supervisor_restart_limit;
14
+ Format. fprintf fmt " * supervisor_restart_period=%d\n " t.supervisor_restart_period;
15
+ Format. fprintf fmt " \n %!"
16
+ ;;
17
+
18
+ let make ?(supervisor_restart_limit = 1 ) ?(supervisor_restart_period = 0 )
19
+ ?workers () =
4
20
let max_workers = Int. max 0 (Stdlib.Domain. recommended_domain_count () - 2 ) in
5
21
let workers =
6
22
match workers with Some w -> Int. min w max_workers | None -> max_workers
7
23
in
8
24
let rnd = Random.State. make_self_init () in
9
- { rnd; max_workers; workers }
25
+ {
26
+ rnd;
27
+ max_workers;
28
+ workers;
29
+ supervisor_restart_limit;
30
+ supervisor_restart_period;
31
+ }
10
32
11
33
let default () = make ()
Original file line number Diff line number Diff line change @@ -31,7 +31,8 @@ let run ?(config = Config.default ()) main =
31
31
32
32
let Config. { workers; rnd; _ } = config in
33
33
34
- Log. debug (fun f -> f " Initializing Riot runtime..." );
34
+ Log. debug (fun f -> f " Initializing Riot runtime...\n %a" Config. pp config);
35
+
35
36
Printexc. record_backtrace true ;
36
37
Core.Pid. reset () ;
37
38
Scheduler.Uid. reset () ;
@@ -63,20 +64,22 @@ let run_with_status ?config ~on_error main =
63
64
in
64
65
shutdown ~status ()
65
66
66
- let start ?config ~apps () =
67
- run ? config @@ fun () ->
67
+ let start ?( config = Config. default () ) ~apps () =
68
+ run ~ config @@ fun () ->
68
69
let child_specs =
69
70
List. map
70
71
(fun (module App : Application.Intf ) ->
71
72
Supervisor. child_spec App. start () )
72
73
apps
73
74
in
75
+ let restart_limit = config.supervisor_restart_limit in
76
+ let restart_period = config.supervisor_restart_period in
74
77
Supervisor. (
75
78
start_supervisor
76
79
{
77
80
strategy = One_for_one ;
78
- restart_limit = 1 ;
79
- restart_period = 0 ;
81
+ restart_limit;
82
+ restart_period;
80
83
child_specs;
81
84
children = [] ;
82
85
restarts = [] ;
Original file line number Diff line number Diff line change @@ -305,10 +305,23 @@ val shutdown : ?status:int -> unit -> unit
305
305
(* * Gracefully shuts down the runtime. Any non-yielding process will block this. *)
306
306
307
307
module Config : sig
308
- type t = { rnd : Random.State .t ; max_workers : int ; workers : int }
308
+ type t = {
309
+ rnd : Random.State .t ;
310
+ max_workers : int ;
311
+ workers : int ;
312
+ supervisor_restart_limit : int ;
313
+ supervisor_restart_period : int ;
314
+ }
309
315
316
+ val pp : Format .formatter -> t -> unit
310
317
val default : unit -> t
311
- val make : ?workers : int -> unit -> t
318
+
319
+ val make :
320
+ ?supervisor_restart_limit : int ->
321
+ ?supervisor_restart_period : int ->
322
+ ?workers : int ->
323
+ unit ->
324
+ t
312
325
end
313
326
314
327
val run : ?config : Config .t -> (unit -> unit ) -> unit
You can’t perform that action at this time.
0 commit comments