Skip to content

Commit 34c85de

Browse files
acudnonsense
authored andcommitted
cmd/swarm/swarm-smoke: sliding window test should not time out (#19152)
1 parent 81ed700 commit 34c85de

2 files changed

Lines changed: 45 additions & 30 deletions

File tree

‎cmd/swarm/flags.go‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,9 @@ var (
149149
}
150150
SwarmStoreCacheCapacity = cli.UintFlag{
151151
Name: "store.cache.size",
152-
Usage: "Number of recent chunks cached in memory (default 5000)",
152+
Usage: "Number of recent chunks cached in memory",
153153
EnvVar: SwarmEnvStoreCacheCapacity,
154+
Value: 10000,
154155
}
155156
SwarmCompressedFlag = cli.BoolFlag{
156157
Name: "compressed",

‎cmd/swarm/swarm-smoke/sliding_window.go‎

Lines changed: 43 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -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

5852
func 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

6760
outer:
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()
@@ -79,6 +73,7 @@ outer:
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

Comments
 (0)