@@ -11,7 +11,7 @@ let sleep_outer = ref 2.0
1111
1212let n_jobs = ref 1
1313
14- let iterations = ref 1
14+ let iterations = Atomic. make 1
1515
1616let num_sleep = Atomic. make 0
1717
@@ -32,8 +32,8 @@ let run_job clock _job_id : unit =
3232 ~attrs: [ " i" , `Int ! i ]
3333 in
3434
35- for j = 0 to ! iterations do
36- if j > = ! iterations then
35+ for j = 0 to Atomic. get iterations do
36+ if j > = Atomic. get iterations then
3737 (* Terminate program, having reached our max iterations *)
3838 Atomic. set stop true
3939 else
@@ -80,7 +80,7 @@ let run_job clock _job_id : unit =
8080 done
8181 done
8282
83- let run env : unit =
83+ let run env proc () : unit =
8484 OT.GC_metrics. basic_setup () ;
8585
8686 OT.Metrics_callbacks. register (fun () ->
@@ -90,8 +90,11 @@ let run env : unit =
9090 [ int (Atomic. get num_sleep) ];
9191 ]);
9292
93+ (* The callbacks registered by [OT.Metrics_callbacks.register] are only triggered when a tick runs *)
94+ OT.Collector. tick () ;
95+
9396 let n_jobs = max 1 ! n_jobs in
94- Printf. printf " run %d jobs\n %!" n_jobs;
97+ Printf. printf " run %d jobs in proc %d \n %!" n_jobs proc ;
9598
9699 Eio.Switch. run (fun sw ->
97100 for j = 1 to n_jobs do
@@ -109,6 +112,7 @@ let () =
109112 let batch_metrics = ref 3 in
110113 let batch_logs = ref 400 in
111114 let url = ref None in
115+ let n_procs = ref 1 in
112116 let opts =
113117 [
114118 " --debug" , Arg. Bool (( := ) debug), " enable debug output" ;
@@ -125,8 +129,11 @@ let () =
125129 " --batch-logs" , Arg. Int (( := ) batch_logs), " size of logs batch" ;
126130 " --sleep-inner" , Arg. Set_float sleep_inner, " sleep (in s) in inner loop" ;
127131 " --sleep-outer" , Arg. Set_float sleep_outer, " sleep (in s) in outer loop" ;
128- " --iterations" , Arg. Set_int iterations, " the number of iterations to run" ;
129- " -j" , Arg. Set_int n_jobs, " number of parallel jobs" ;
132+ ( " --iterations" ,
133+ Arg. Int (Atomic. set iterations),
134+ " the number of iterations to run" );
135+ " -j" , Arg. Set_int n_jobs, " number of jobs per domain" ;
136+ " --procs" , Arg. Set_int n_procs, " number of processes" ;
130137 ]
131138 |> Arg. align
132139 in
@@ -155,4 +162,16 @@ let () =
155162 Printf. printf " \n done. %d spans in %.4fs (%.4f/s)\n %!"
156163 (Atomic. get num_tr) elapsed n_per_sec)
157164 in
158- Opentelemetry_client_cohttp_eio. with_setup ~stop ~config run |> Eio_main. run
165+ Eio_main. run @@ fun env ->
166+ (if ! n_procs < 2 then
167+ Opentelemetry_client_cohttp_eio. with_setup ~stop ~config (run env 0 ) env
168+ else
169+ Eio.Switch. run @@ fun sw ->
170+ Opentelemetry_client_cohttp_eio. setup ~stop ~config ~sw env;
171+ let dm = Eio.Stdenv. domain_mgr env in
172+ Eio.Switch. run (fun sw ->
173+ for proc = 1 to ! n_procs do
174+ Eio.Fiber. fork ~sw @@ fun () ->
175+ Eio.Domain_manager. run dm (run env proc)
176+ done));
177+ Opentelemetry.Collector. remove_backend () ~on_done: ignore
0 commit comments