@@ -22,13 +22,13 @@ use kube::{
2222} ;
2323use maplit:: btreemap;
2424use tokio:: time:: sleep;
25- use tracing:: { instrument, Level } ;
25+ use tracing:: { info , instrument, Level } ;
2626
2727use crate :: args:: CommonArgs ;
2828
2929use super :: Metrics ;
3030
31- #[ derive( Debug ) ]
31+ #[ derive( Copy , Clone , Debug ) ]
3232pub struct Instruction {
3333 pub num_k : usize ,
3434}
@@ -37,7 +37,10 @@ pub struct Instruction {
3737impl super :: Instruction for Instruction {
3838 #[ instrument( skip_all, err( level = Level :: ERROR ) ) ]
3939 async fn apply ( & self , kube : & Client , args : & CommonArgs , _metrics : & mut Metrics ) -> Result < ( ) > {
40- let objects: Vec < _ > = ( 0 ..self . num_k )
40+ let Self { num_k } = * self ;
41+ info ! ( "create_ponds: create {num_k}" ) ;
42+
43+ let objects: Vec < _ > = ( 0 ..num_k)
4144 . map ( |k| format ! ( "cdl-benchmark-{k:07}" ) )
4245 . map ( |namespace| ModelStorageCrd {
4346 metadata : ObjectMeta {
@@ -53,12 +56,17 @@ impl super::Instruction for Instruction {
5356 ModelStorageObjectOwnedSpec {
5457 replication : ModelStorageObjectOwnedReplicationSpec {
5558 resources : ResourceRequirements {
59+ limits : Some ( btreemap ! {
60+ "cpu" . into( ) => Quantity ( "1" . into( ) ) ,
61+ "memory" . into( ) => Quantity ( "1Gi" . into( ) ) ,
62+ } ) ,
5663 requests : Some ( btreemap ! {
5764 "storage" . into( ) => Quantity ( "10Ti" . into( ) ) ,
5865 } ) ,
5966 ..Default :: default ( )
6067 } ,
61- ..Default :: default ( )
68+ total_nodes : 1 ,
69+ total_volumes_per_node : 1 ,
6270 } ,
6371 ..Default :: default ( )
6472 } ,
@@ -71,35 +79,42 @@ impl super::Instruction for Instruction {
7179
7280 let api_ns = Api :: all ( kube. clone ( ) ) ;
7381 let pp = PostParams :: default ( ) ;
74- stream:: iter ( objects. iter ( ) . map ( |x| Ok ( x) ) )
75- . try_for_each_concurrent ( args. num_threads , |object| async {
76- let ns = Namespace {
77- metadata : ObjectMeta {
78- name : object. namespace ( ) ,
79- labels : Some ( btreemap ! {
80- "cdl.ulagbulag.io/benchmark" . into( ) => "true" . into( ) ,
81- } ) ,
82- ..Default :: default ( )
83- } ,
84- spec : None ,
85- status : None ,
86- } ;
87- api_ns. create ( & pp, & ns) . await ?;
82+ for object in & objects {
83+ let ns = Namespace {
84+ metadata : ObjectMeta {
85+ name : object. namespace ( ) ,
86+ labels : Some ( btreemap ! {
87+ "cdl.ulagbulag.io/benchmark" . into( ) => "true" . into( ) ,
88+ } ) ,
89+ ..Default :: default ( )
90+ } ,
91+ spec : None ,
92+ status : None ,
93+ } ;
94+ api_ns. create ( & pp, & ns) . await ?;
8895
89- let namespace = ns. name_any ( ) ;
90- loop {
91- if api_ns. get_metadata_opt ( & namespace) . await ?. is_some ( ) {
92- break ;
93- }
94- sleep ( Duration :: from_millis ( args. check_interval_ms ) ) . await ;
96+ let namespace = ns. name_any ( ) ;
97+ loop {
98+ if api_ns. get_metadata_opt ( & namespace) . await ?. is_some ( ) {
99+ break ;
95100 }
101+ sleep ( Duration :: from_millis ( args. apply_interval_ms ) ) . await ;
102+ }
96103
97- let api = Api :: namespaced ( kube. clone ( ) , & namespace) ;
98- api. create ( & pp, object) . await ?;
104+ let api = Api :: namespaced ( kube. clone ( ) , & namespace) ;
105+ api. create ( & pp, object) . await ?;
106+ sleep ( Duration :: from_millis (
107+ args. apply_interval_ms / args. num_threads as u64 ,
108+ ) )
109+ . await ;
110+ }
99111
112+ stream:: iter ( objects. iter ( ) . map ( |x| Ok ( x) ) )
113+ . try_for_each_concurrent ( args. num_threads , |object| async {
114+ let api = Api :: namespaced ( kube. clone ( ) , & object. namespace ( ) . unwrap ( ) ) ;
100115 let name = object. name_any ( ) ;
101116 loop {
102- let object = api. get ( & name) . await ?;
117+ let object: ModelStorageCrd = api. get ( & name) . await ?;
103118 if object
104119 . status
105120 . as_ref ( )
@@ -108,7 +123,7 @@ impl super::Instruction for Instruction {
108123 {
109124 break ;
110125 }
111- sleep ( Duration :: from_millis ( args. check_interval_ms ) ) . await ;
126+ sleep ( Duration :: from_millis ( args. apply_interval_ms ) ) . await ;
112127 }
113128 Ok :: < _ , Error > ( ( ) )
114129 } )
@@ -117,7 +132,10 @@ impl super::Instruction for Instruction {
117132
118133 #[ instrument( skip_all, err( level = Level :: ERROR ) ) ]
119134 async fn delete ( & self , kube : & Client , args : & CommonArgs , _metrics : & mut Metrics ) -> Result < ( ) > {
120- let namespaces: Vec < _ > = ( 0 ..self . num_k )
135+ let Self { num_k } = * self ;
136+ info ! ( "create_ponds: delete {num_k}" ) ;
137+
138+ let namespaces: Vec < _ > = ( 0 ..num_k)
121139 . map ( |k| format ! ( "cdl-benchmark-{k:07}" ) )
122140 . collect ( ) ;
123141
@@ -133,13 +151,22 @@ impl super::Instruction for Instruction {
133151 . collect :: < FuturesUnordered < _ > > ( )
134152 . try_for_each_concurrent ( args. num_threads , |namespace| async {
135153 api. delete ( namespace, & dp) . await ?;
154+ sleep ( Duration :: from_millis ( args. apply_interval_ms ) ) . await ;
155+ Ok :: < _ , Error > ( ( ) )
156+ } )
157+ . await ?;
136158
159+ namespaces
160+ . iter ( )
161+ . map ( |x| async move { Ok ( x) } )
162+ . collect :: < FuturesUnordered < _ > > ( )
163+ . try_for_each_concurrent ( args. num_threads , |namespace| async {
137164 loop {
138165 let object = api. get_metadata_opt ( namespace) . await ?;
139166 if object. is_none ( ) {
140167 break ;
141168 }
142- sleep ( Duration :: from_millis ( args. check_interval_ms ) ) . await ;
169+ sleep ( Duration :: from_millis ( args. apply_interval_ms ) ) . await ;
143170 }
144171 Ok :: < _ , Error > ( ( ) )
145172 } )
0 commit comments