@@ -18,11 +18,32 @@ import (
18
18
)
19
19
20
20
type 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 ))]
26
47
}
27
48
28
49
func main () {
@@ -34,21 +55,21 @@ func main() {
34
55
}
35
56
36
57
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 )
38
59
if err != nil {
39
60
log .Fatalf ("Could not connect to: %v" , err )
40
61
}
41
62
42
63
log .Printf ("Loading specification at %s" , c .SpecificationPath )
43
64
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
+ }
52
73
requestGenerator , err := generator .NewRequestGenerator (loadSpec , c .ProjectName )
53
74
if err != nil {
54
75
log .Fatalf ("Unable to instantiate request requestGenerator: %v" , err )
@@ -59,11 +80,11 @@ func main() {
59
80
}
60
81
61
82
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 )
63
84
defer cancel ()
64
85
requests := requestsPool [rand .Intn (len (requestsPool ))]
65
86
if len (requests ) == 1 {
66
- resp , err := client .GetOnlineFeatures (ctx , & requests [0 ])
87
+ resp , err := pool . GetClient () .GetOnlineFeatures (ctx , & requests [0 ])
67
88
if err != nil {
68
89
w .WriteHeader (500 )
69
90
} else {
@@ -82,7 +103,7 @@ func main() {
82
103
request := request
83
104
go func () {
84
105
defer wg .Done ()
85
- resp , err := client .GetOnlineFeatures (ctx , & request )
106
+ resp , err := pool . GetClient () .GetOnlineFeatures (ctx , & request )
86
107
if err != nil {
87
108
fatalErrors <- err
88
109
}
@@ -113,10 +134,10 @@ func main() {
113
134
})
114
135
115
136
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 )
117
138
defer cancel ()
118
139
var req serving.GetFeastServingInfoRequest
119
- _ , err := client .GetFeastServingInfo (ctx , & req )
140
+ _ , err := pool . GetClient () .GetFeastServingInfo (ctx , & req )
120
141
if err != nil {
121
142
log .Fatalf ("%v" , err )
122
143
}
0 commit comments