@@ -18,11 +18,32 @@ import (
1818)
1919
2020type Config struct {
21- FeastServingHost string `default:"localhost" split_words:"true"`
22- FeastServingPort int `default:"6566" split_words:"true"`
23- ListenPort string `default:"8080" split_words:"true"`
24- ProjectName string `default:"default" split_words:"true"`
25- SpecificationPath string `default:"loadSpec.yml" split_words:"true"`
21+ FeastServingHost string `default:"localhost" split_words:"true"`
22+ FeastServingPort int `default:"6566" split_words:"true"`
23+ ListenPort string `default:"8080" split_words:"true"`
24+ ProjectName string `default:"default" split_words:"true"`
25+ SpecificationPath string `default:"loadSpec.yml" split_words:"true"`
26+ ClientPoolSize int `default:"4" split_words:"true"`
27+ }
28+
29+ type FeastClientPool struct {
30+ clients []feast.Client
31+ }
32+
33+ func newFeastClientPool (host string , port int , poolSize int ) (* FeastClientPool , error ) {
34+ var clients []feast.Client
35+ for i := 0 ; i < poolSize ; i ++ {
36+ client , err := feast .NewGrpcClient (host , port )
37+ if err != nil {
38+ return nil , err
39+ }
40+ clients = append (clients , client )
41+ }
42+ return & FeastClientPool {clients }, nil
43+ }
44+
45+ func (p * FeastClientPool ) GetClient () feast.Client {
46+ return p .clients [rand .Intn (len (p .clients ))]
2647}
2748
2849func main () {
@@ -34,21 +55,21 @@ func main() {
3455 }
3556
3657 log .Printf ("Creating client to connect to Feast Serving at %s:%d" , c .FeastServingHost , c .FeastServingPort )
37- client , err := feast . NewGrpcClient (c .FeastServingHost , c .FeastServingPort )
58+ pool , err := newFeastClientPool (c .FeastServingHost , c .FeastServingPort , c . ClientPoolSize )
3859 if err != nil {
3960 log .Fatalf ("Could not connect to: %v" , err )
4061 }
4162
4263 log .Printf ("Loading specification at %s" , c .SpecificationPath )
4364 yamlSpec , err := ioutil .ReadFile (c .SpecificationPath )
44- if err != nil {
45- log .Fatalf ("Error reading specification file at %s" , err )
46- }
47- loadSpec := generator.LoadSpec {}
48- err = yaml .Unmarshal (yamlSpec , & loadSpec )
49- if err != nil {
50- log .Fatalf ("Unmarshal: %v" , err )
51- }
65+ if err != nil {
66+ log .Fatalf ("Error reading specification file at %s" , err )
67+ }
68+ loadSpec := generator.LoadSpec {}
69+ err = yaml .Unmarshal (yamlSpec , & loadSpec )
70+ if err != nil {
71+ log .Fatalf ("Unmarshal: %v" , err )
72+ }
5273 requestGenerator , err := generator .NewRequestGenerator (loadSpec , c .ProjectName )
5374 if err != nil {
5475 log .Fatalf ("Unable to instantiate request requestGenerator: %v" , err )
@@ -59,11 +80,11 @@ func main() {
5980 }
6081
6182 http .HandleFunc ("/send" , func (w http.ResponseWriter , r * http.Request ) {
62- ctx , cancel := context .WithTimeout (context .Background (), 60 * time .Second )
83+ ctx , cancel := context .WithTimeout (context .Background (), 60 * time .Second )
6384 defer cancel ()
6485 requests := requestsPool [rand .Intn (len (requestsPool ))]
6586 if len (requests ) == 1 {
66- resp , err := client .GetOnlineFeatures (ctx , & requests [0 ])
87+ resp , err := pool . GetClient () .GetOnlineFeatures (ctx , & requests [0 ])
6788 if err != nil {
6889 w .WriteHeader (500 )
6990 } else {
@@ -82,7 +103,7 @@ func main() {
82103 request := request
83104 go func () {
84105 defer wg .Done ()
85- resp , err := client .GetOnlineFeatures (ctx , & request )
106+ resp , err := pool . GetClient () .GetOnlineFeatures (ctx , & request )
86107 if err != nil {
87108 fatalErrors <- err
88109 }
@@ -113,10 +134,10 @@ func main() {
113134 })
114135
115136 http .HandleFunc ("/echo" , func (w http.ResponseWriter , r * http.Request ) {
116- ctx , cancel := context .WithTimeout (context .Background (), 60 * time .Second )
137+ ctx , cancel := context .WithTimeout (context .Background (), 60 * time .Second )
117138 defer cancel ()
118139 var req serving.GetFeastServingInfoRequest
119- _ , err := client .GetFeastServingInfo (ctx , & req )
140+ _ , err := pool . GetClient () .GetFeastServingInfo (ctx , & req )
120141 if err != nil {
121142 log .Fatalf ("%v" , err )
122143 }
0 commit comments