@@ -42,30 +42,24 @@ func slidingWindowCmd(ctx *cli.Context, tuid string) error {
4242 errc <- slidingWindow (ctx , tuid )
4343 }()
4444
45- select {
46- case err := <- errc :
47- if err != nil {
48- metrics .GetOrRegisterCounter (fmt .Sprintf ("%s.fail" , commandName ), nil ).Inc (1 )
49- }
50- return err
51- case <- time .After (time .Duration (timeout ) * time .Second ):
52- metrics .GetOrRegisterCounter (fmt .Sprintf ("%s.timeout" , commandName ), nil ).Inc (1 )
53-
54- return fmt .Errorf ("timeout after %v sec" , timeout )
45+ err := <- errc
46+ if err != nil {
47+ metrics .GetOrRegisterCounter (fmt .Sprintf ("%s.fail" , commandName ), nil ).Inc (1 )
5548 }
49+ return err
5650}
5751
5852func slidingWindow (ctx * cli.Context , tuid string ) error {
5953 var hashes []uploadResult //swarm hashes of the uploads
6054 nodes := len (hosts )
61- const iterationTimeout = 30 * time .Second
6255 log .Info ("sliding window test started" , "tuid" , tuid , "nodes" , nodes , "filesize(kb)" , filesize , "timeout" , timeout )
6356 uploadedBytes := 0
6457 networkDepth := 0
6558 errored := false
6659
6760outer:
6861 for {
62+ seed = int (time .Now ().UTC ().UnixNano ())
6963 log .Info ("uploading to " + httpEndpoint (hosts [0 ])+ " and syncing" , "seed" , seed )
7064
7165 t1 := time .Now ()
7973 }
8074
8175 metrics .GetOrRegisterResettingTimer ("sliding-window.upload-time" , nil ).UpdateSince (t1 )
76+ metrics .GetOrRegisterGauge ("sliding-window.upload-depth" , nil ).Update (int64 (len (hashes )))
8277
8378 fhash , err := digest (bytes .NewReader (randomBytes ))
8479 if err != nil {
@@ -90,37 +85,56 @@ outer:
9085 hashes = append (hashes , uploadResult {hash : hash , digest : fhash })
9186 time .Sleep (time .Duration (syncDelay ) * time .Second )
9287 uploadedBytes += filesize * 1000
93-
88+ q := make (chan struct {}, 1 )
89+ d := make (chan struct {})
90+ defer close (q )
91+ defer close (d )
9492 for i , v := range hashes {
95- timeout := time .After (time .Duration (timeout ) * time .Second )
93+ timeoutC := time .After (time .Duration (timeout ) * time .Second )
9694 errored = false
9795
98- inner :
96+ task :
9997 for {
10098 select {
101- case <- timeout :
99+ case q <- struct {}{}:
100+ go func () {
101+ var start time.Time
102+ done := false
103+ for ! done {
104+ log .Info ("trying to retrieve hash" , "hash" , v .hash )
105+ idx := 1 + rand .Intn (len (hosts )- 1 )
106+ ruid := uuid .New ()[:8 ]
107+ start = time .Now ()
108+ // fetch hangs when swarm dies out, so we have to jump through a bit more hoops to actually
109+ // catch the timeout, but also allow this retry logic
110+ err := fetch (v .hash , httpEndpoint (hosts [idx ]), v .digest , ruid , "" )
111+ if err != nil {
112+ log .Error ("error fetching hash" , "err" , err )
113+ continue
114+ }
115+ done = true
116+ }
117+ metrics .GetOrRegisterResettingTimer ("sliding-window.single.fetch-time" , nil ).UpdateSince (start )
118+ d <- struct {}{}
119+ }()
120+ case <- d :
121+ <- q
122+ break task
123+ case <- timeoutC :
102124 errored = true
103- log .Error ("error retrieving hash. timeout" , "hash idx" , i , "err" , err )
125+ log .Error ("error retrieving hash. timeout" , "hash idx" , i )
104126 metrics .GetOrRegisterCounter ("sliding-window.single.error" , nil ).Inc (1 )
105- break inner
127+ break outer
106128 default :
107- idx := 1 + rand .Intn (len (hosts )- 1 )
108- ruid := uuid .New ()[:8 ]
109- start := time .Now ()
110- err := fetch (v .hash , httpEndpoint (hosts [idx ]), v .digest , ruid , "" )
111- if err != nil {
112- continue inner
113- }
114- metrics .GetOrRegisterResettingTimer ("sliding-window.single.fetch-time" , nil ).UpdateSince (start )
115- break inner
116129 }
117130 }
118131
119- if errored {
120- break outer
121- }
122132 networkDepth = i
123133 metrics .GetOrRegisterGauge ("sliding-window.network-depth" , nil ).Update (int64 (networkDepth ))
134+ log .Info ("sliding window test successfully fetched file" , "currentDepth" , networkDepth )
135+ // this test might take a long time to finish - but we'd like to see metrics while they accumulate and not just when
136+ // the test finishes. therefore emit the metrics on each iteration
137+ emitMetrics (ctx )
124138 }
125139 }
126140
0 commit comments