File tree Expand file tree Collapse file tree 8 files changed +283
-81
lines changed
Expand file tree Collapse file tree 8 files changed +283
-81
lines changed Original file line number Diff line number Diff line change 1313 CARGO_TERM_COLOR : always
1414 RUSTUP_MAX_RETRIES : 10
1515 ORT_DYLIB_PATH : /tmp/onnxruntime/lib/libonnxruntime.so
16- RUST_LOG : event_worker =trace
16+ RUST_LOG : sb_event_worker =trace
1717
1818jobs :
1919 cargo-fmt :
Original file line number Diff line number Diff line change @@ -279,6 +279,7 @@ pub struct RuntimeState {
279279 pub event_loop_completed : Arc < AtomicFlag > ,
280280 pub terminated : Arc < AtomicFlag > ,
281281 pub found_inspector_session : Arc < AtomicFlag > ,
282+ pub mem_reached_half : Arc < AtomicFlag > ,
282283}
283284
284285impl RuntimeState {
@@ -1324,6 +1325,14 @@ where
13241325 }
13251326 }
13261327
1328+ if let Some ( limit) = mem_state. limit {
1329+ if total_malloced_bytes >= limit / 2 {
1330+ state. mem_reached_half . raise ( ) ;
1331+ } else {
1332+ state. mem_reached_half . lower ( ) ;
1333+ }
1334+ }
1335+
13271336 if let Some ( threshold_bytes) = beforeunload_mem_threshold. load ( ) . as_deref ( ) . copied ( )
13281337 {
13291338 let total_malloced_bytes = total_malloced_bytes as u64 ;
Original file line number Diff line number Diff line change @@ -460,8 +460,6 @@ impl WorkerPool {
460460 if tx. send ( Ok ( CreateUserWorkerResult { key : uuid } ) ) . is_err ( ) {
461461 error ! ( "main worker receiver dropped" )
462462 } ;
463-
464- status. demand . fetch_add ( 1 , Ordering :: Release ) ;
465463 }
466464 Err ( err) => {
467465 error ! ( "{err:#}" ) ;
@@ -502,6 +500,8 @@ impl WorkerPool {
502500 let cancel = worker. cancel . clone ( ) ;
503501 let ( req_start_tx, req_end_tx) = profile. timing_tx_pair . clone ( ) ;
504502
503+ profile. status . demand . fetch_add ( 1 , Ordering :: Release ) ;
504+
505505 // Create a closure to handle the request and send the response
506506 let request_handler = async move {
507507 if !policy. is_per_worker ( ) {
@@ -648,15 +648,7 @@ impl WorkerPool {
648648 . get ( & worker_uuid)
649649 . map ( |it| it. status . is_retired . clone ( ) )
650650 {
651- Some ( is_retired) if !is_retired. is_raised ( ) => {
652- self . user_workers
653- . get ( & worker_uuid)
654- . map ( |it| it. status . demand . as_ref ( ) )
655- . unwrap ( )
656- . fetch_add ( 1 , Ordering :: Release ) ;
657-
658- Some ( worker_uuid)
659- }
651+ Some ( is_retired) if !is_retired. is_raised ( ) => Some ( worker_uuid) ,
660652
661653 _ => {
662654 self . retire ( & worker_uuid) ;
You can’t perform that action at this time.
0 commit comments