MCPcopy Create free account
hub / github.com/Azure/peerd / downloadSASURLs

Function downloadSASURLs

tests/random/random.go:138–186  ·  view source on GitHub ↗

downloadSASURLs downloads the SAS URLs in a group and measures the download speed

(l *zerolog.Logger, group []string)

Source from the content-addressed store, hash-verified

136
137// downloadSASURLs downloads the SAS URLs in a group and measures the download speed
138func downloadSASURLs(l *zerolog.Logger, group []string) ([]float64, int) {
139 readsPerBlob := 5
140 var wg sync.WaitGroup
141 l.Info().Int("groupSize", len(group)).Int("readsPerBlob", readsPerBlob).Strs("urls", group).Msg("downloading blobs")
142 speeds := []float64{}
143 failures := 0
144
145 speedsChan := make(chan []float64, readsPerBlob)
146 failuresChan := make(chan int, readsPerBlob)
147
148 for _, sasURL := range group {
149 wg.Add(1)
150 go func(sasURL string) {
151 defer wg.Done()
152
153 if sasURL == "" {
154 l.Warn().Str("url", sasURL).Msg("skipping SAS URL")
155 return
156 }
157
158 blobSpeeds, f, err := downloadSASURL(l, sasURL, readsPerBlob)
159 if err != nil {
160 l.Error().Err(err).Str("url", sasURL).Msg("download error")
161 failuresChan <- f
162 }
163
164 speedsChan <- blobSpeeds
165 }(sasURL)
166 }
167
168 doneChan := make(chan bool, 1)
169 go func() {
170 wg.Wait()
171 doneChan <- true
172 }()
173
174 for {
175 select {
176 case blobSpeeds := <-speedsChan:
177 speeds = append(speeds, blobSpeeds...)
178
179 case failure := <-failuresChan:
180 failures += failure
181
182 case <-doneChan:
183 return speeds, failures
184 }
185 }
186}
187
188// downloadSASURL downloads a SAS URL and returns the number of bytes downloaded.
189func downloadSASURL(l *zerolog.Logger, sasURL string, readsPerBlob int) ([]float64, int, error) {

Callers 1

benchmarkFunction · 0.85

Calls 1

downloadSASURLFunction · 0.85

Tested by

no test coverage detected