11use std:: collections:: HashMap ;
22use std:: env;
33use std:: fs:: File ;
4- use std:: num:: NonZeroUsize ;
4+ use std:: num:: NonZeroU64 ;
55use std:: path:: Path ;
66use std:: pin:: Pin ;
77use std:: time:: { Duration , Instant } ;
@@ -29,16 +29,16 @@ struct Config {
2929 namespace : Option < String > ,
3030 /// The maximum number of instances per container image, this does not
3131 /// include the base worker.
32- max_pods : NonZeroUsize ,
32+ max_pods : NonZeroU64 ,
3333 /// The number of tasks in the queue per allocated CPU.
34- queue_per_cpu : NonZeroUsize ,
34+ queue_per_cpu : NonZeroU64 ,
3535 /// The number of CPUs to allocate on the base worker, this is a worker
3636 /// that remains for two days after a property set is used.
37- base_worker_cpu : usize ,
37+ base_worker_cpu : action_info :: OperationCount ,
3838 /// The number of GB of RAM to allocate per CPU allocated to a worker.
39- memory_to_cpu : NonZeroUsize ,
39+ memory_to_cpu : NonZeroU64 ,
4040 /// The number of CPUs to allocate to a standard worker.
41- worker_cpu : NonZeroUsize ,
41+ worker_cpu : NonZeroU64 ,
4242}
4343
4444const DOCKER_IMAGE_PREFIX : & str = "docker://" ;
@@ -60,7 +60,7 @@ struct WorkerInfo {
6060
6161#[ derive( Debug ) ]
6262struct PropertyWorkers {
63- queue_size : usize ,
63+ queue_size : action_info :: OperationCount ,
6464 workers : HashMap < WorkerName , WorkerInfo > ,
6565 base_worker : Option < WorkerName > ,
6666 last_queue_update : Instant ,
@@ -71,7 +71,7 @@ impl PropertyWorkers {
7171 Self :: new_with_workers ( 0 , HashMap :: new ( ) )
7272 }
7373
74- fn new_with_workers ( queue_size : usize , workers : HashMap < WorkerName , WorkerInfo > ) -> Self {
74+ fn new_with_workers ( queue_size : action_info :: OperationCount , workers : HashMap < WorkerName , WorkerInfo > ) -> Self {
7575 Self {
7676 queue_size,
7777 workers,
@@ -104,7 +104,7 @@ impl PropertyWorkers {
104104 . map ( |( name, info) | ( name, info. start_time ) )
105105 }
106106
107- fn update_queue ( & mut self , queue_size : usize ) {
107+ fn update_queue ( & mut self , queue_size : action_info :: OperationCount ) {
108108 if self . queue_size != 0 || queue_size != 0 {
109109 self . last_queue_update = Instant :: now ( ) ;
110110 }
@@ -119,8 +119,8 @@ impl PropertyWorkers {
119119 self . base_worker . is_none ( ) && self . base_worker_required ( )
120120 }
121121
122- fn workers_count ( & self ) -> usize {
123- self . workers . len ( )
122+ fn workers_count ( & self ) -> action_info :: OperationCount {
123+ self . workers . len ( ) as u64
124124 }
125125
126126 fn set_base_worker ( & mut self , name : WorkerName ) -> bool {
@@ -150,19 +150,19 @@ impl PropertyWorkers {
150150 }
151151 }
152152
153- fn scale_down_to ( & mut self , workers : usize ) -> Vec < ( WorkerName , WorkerInfo ) > {
154- if self . workers . len ( ) <= workers {
153+ fn scale_down_to ( & mut self , workers : action_info :: OperationCount ) -> Vec < ( WorkerName , WorkerInfo ) > {
154+ if self . workers_count ( ) <= workers {
155155 return Vec :: new ( ) ;
156156 }
157- let to_remove = self . workers . len ( ) - workers;
157+ let to_remove = self . workers_count ( ) - workers;
158158 let mut all_workers: Vec < _ > = self . workers . iter ( ) . collect ( ) ;
159159 all_workers. sort_by ( |a, b| b. 1 . start_time . cmp ( & a. 1 . start_time ) ) ;
160160 let keep_names: Vec < _ > = all_workers
161161 . iter ( )
162- . skip ( to_remove)
162+ . skip ( to_remove as usize )
163163 . filter_map ( |( name, info) | info. death_time . is_some ( ) . then_some ( ( * name) . clone ( ) ) )
164164 . collect ( ) ;
165- all_workers. truncate ( to_remove) ;
165+ all_workers. truncate ( to_remove as usize ) ;
166166 let now: Instant = Instant :: now ( ) ;
167167 let ( to_add_death_time, workers_to_remove) : ( Vec < _ > , Vec < _ > ) = all_workers
168168 . into_iter ( )
@@ -194,22 +194,22 @@ impl PropertyWorkers {
194194 removed_workers
195195 }
196196
197- fn get_queue_size ( & self ) -> usize {
197+ fn get_queue_size ( & self ) -> action_info :: OperationCount {
198198 self . queue_size
199199 }
200200}
201201
202202type WorkerMap = HashMap < action_info:: PropertySet , PropertyWorkers > ;
203203
204204struct ScaleInfo {
205- max_pods : usize ,
206- queue_per_cpu : usize ,
207- base_worker_cpu : usize ,
208- worker_cpu : usize ,
205+ max_pods : action_info :: OperationCount ,
206+ queue_per_cpu : action_info :: OperationCount ,
207+ base_worker_cpu : action_info :: OperationCount ,
208+ worker_cpu : action_info :: OperationCount ,
209209}
210210
211211impl ScaleInfo {
212- fn required_workers ( & self , queue_size : usize ) -> usize {
212+ fn required_workers ( & self , queue_size : action_info :: OperationCount ) -> action_info :: OperationCount {
213213 let base_queue = self . queue_per_cpu * self . base_worker_cpu ;
214214 let required_workers = if queue_size > base_queue {
215215 let queue_per_pod = self . queue_per_cpu * self . worker_cpu ;
@@ -265,7 +265,7 @@ async fn get_worker_pods(
265265 . collect ( )
266266}
267267
268- async fn enumerate_existing_workers ( pods : & Api < Pod > , base_cpu : usize ) -> WorkerMap {
268+ async fn enumerate_existing_workers ( pods : & Api < Pod > , base_cpu : action_info :: OperationCount ) -> WorkerMap {
269269 let pod_list = match pods. list ( & ListParams :: default ( ) ) . await {
270270 Ok ( list) => list,
271271 Err ( e) => {
@@ -287,7 +287,7 @@ async fn enumerate_existing_workers(pods: &Api<Pod>, base_cpu: usize) -> WorkerM
287287 . as_ref ( )
288288 . and_then ( |resources| resources. requests . as_ref ( ) )
289289 . and_then ( |requests| requests. get ( "cpu" ) )
290- . and_then ( |cpu| cpu. 0 . parse :: < usize > ( ) . ok ( ) )
290+ . and_then ( |cpu| cpu. 0 . parse :: < action_info :: OperationCount > ( ) . ok ( ) )
291291 . is_some_and ( |request_cpu| request_cpu == base_cpu) ;
292292 Some ( ( image_name, name, is_base) )
293293 } ) ;
@@ -321,9 +321,9 @@ struct WorkerManager {
321321 workers : WorkerMap ,
322322 operations_change : Receiver < ( action_info:: PropertySet , action_info:: OperationCount ) > ,
323323 watcher : Pin < Box < dyn Stream < Item = kube:: runtime:: watcher:: Result < Event < Pod > > > > > ,
324- memory_to_cpu : usize ,
325- worker_cpu : usize ,
326- base_worker_cpu : usize ,
324+ memory_to_cpu : action_info :: OperationCount ,
325+ worker_cpu : action_info :: OperationCount ,
326+ base_worker_cpu : action_info :: OperationCount ,
327327}
328328
329329impl WorkerManager {
@@ -409,7 +409,7 @@ impl WorkerManager {
409409 None
410410 }
411411
412- fn configure_pod ( pod : & Pod , cpu : usize , memory : usize ) -> Pod {
412+ fn configure_pod ( pod : & Pod , cpu : action_info :: OperationCount , memory : action_info :: OperationCount ) -> Pod {
413413 let mut this_pod = pod. clone ( ) ;
414414 // Create a unique name for this pod.
415415 this_pod. metadata . name = Some ( format ! (
@@ -453,7 +453,7 @@ impl WorkerManager {
453453 this_pod
454454 }
455455
456- async fn maybe_scale_up ( & mut self , properties : action_info:: PropertySet , queue_size : usize ) {
456+ async fn maybe_scale_up ( & mut self , properties : action_info:: PropertySet , queue_size : action_info :: OperationCount ) {
457457 let mut workers_entry = match self . workers . entry ( properties. clone ( ) ) {
458458 std:: collections:: hash_map:: Entry :: Occupied ( mut occupied_entry) => {
459459 occupied_entry. get_mut ( ) . update_queue ( queue_size) ;
0 commit comments