Skip to content

Commit

Permalink
randomize provider order to ensure load balancing
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMarstonConnell committed May 30, 2023
1 parent 09de875 commit a738a4a
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"io"
"math/rand"
"net/http"

storageTypes "github.com/jackalLabs/canine-chain/x/storage/types"
Expand Down Expand Up @@ -55,6 +56,10 @@ func downloadFile(qc storageTypes.QueryClient, fid string, writer io.Writer) err

fmt.Println("attempting to download file...")

rand.Shuffle(len(arr), func(i, j int) { // randomize provider order
arr[i], arr[j] = arr[j], arr[i]
})

failed := true
for _, s := range arr {
err := downloadFileFromURL(s, fid, writer)
Expand Down

0 comments on commit a738a4a

Please sign in to comment.