Skip to content

Commit

Permalink
Merge pull request #4 from khorshuheng/pregenerated-requests
Browse files Browse the repository at this point in the history
Pregenerate requests before serving
  • Loading branch information
khorshuheng authored Jan 21, 2021
2 parents 82b798d + e950ef8 commit 8e61716
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"gopkg.in/yaml.v2"
"io/ioutil"
"log"
"math/rand"
"net/http"
"sync"
"time"
Expand Down Expand Up @@ -52,12 +53,15 @@ func main() {
if err != nil {
log.Fatalf("Unable to instantiate request requestGenerator: %v", err)
}
requestsPool := make([][]feast.OnlineFeaturesRequest, 100)
for i := 0; i < 100; i++ {
requestsPool[i] = requestGenerator.GenerateRequests()
}

http.HandleFunc("/send", func(w http.ResponseWriter, r *http.Request) {
requests := requestGenerator.GenerateRequests()

ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
requests := requestsPool[rand.Intn(len(requestsPool))]
if len(requests) == 1 {
resp, err := client.GetOnlineFeatures(ctx, &requests[0])
if err != nil {
Expand Down

0 comments on commit 8e61716

Please sign in to comment.