Skip to content

Commit 1df916b

Browse files
committed
cmd/swarm: remove timeout from wrapCli; revert changes to randomBytes to be uploaded
1 parent e977917 commit 1df916b

File tree

7 files changed

+145
-88
lines changed

7 files changed

+145
-88
lines changed

cmd/swarm/swarm-smoke/feed_upload_and_sync.go

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package main
33
import (
44
"bytes"
55
"crypto/md5"
6-
crand "crypto/rand"
76
"fmt"
87
"io"
98
"io/ioutil"
@@ -16,7 +15,9 @@ import (
1615
"github.com/ethereum/go-ethereum/common/hexutil"
1716
"github.com/ethereum/go-ethereum/crypto"
1817
"github.com/ethereum/go-ethereum/log"
18+
"github.com/ethereum/go-ethereum/metrics"
1919
"github.com/ethereum/go-ethereum/swarm/storage/feed"
20+
"github.com/ethereum/go-ethereum/swarm/testutil"
2021
"github.com/pborman/uuid"
2122
cli "gopkg.in/urfave/cli.v1"
2223
)
@@ -25,10 +26,27 @@ const (
2526
feedRandomDataLength = 8
2627
)
2728

28-
// TODO: retrieve with manifest + extract repeating code
29-
func feedUploadAndSync(c *cli.Context) error {
30-
defer func(now time.Time) { log.Info("total time", "time", time.Since(now), "size (kb)", filesize) }(time.Now())
29+
func feedUploadAndSync(ctx *cli.Context, tuid string) error {
30+
errc := make(chan error)
3131

32+
go func() {
33+
errc <- fuas(ctx, tuid)
34+
}()
35+
36+
select {
37+
case err := <-errc:
38+
if err != nil {
39+
metrics.GetOrRegisterCounter(fmt.Sprintf("%s.fail", commandName), nil).Inc(1)
40+
}
41+
return err
42+
case <-time.After(time.Duration(timeout) * time.Second):
43+
metrics.GetOrRegisterCounter(fmt.Sprintf("%s.timeout", commandName), nil).Inc(1)
44+
45+
return fmt.Errorf("timeout after %v sec", timeout)
46+
}
47+
}
48+
49+
func fuas(c *cli.Context, tuid string) error {
3250
log.Info("generating and uploading feeds to " + httpEndpoint(hosts[0]) + " and syncing")
3351

3452
// create a random private key to sign updates with and derive the address
@@ -197,13 +215,11 @@ func feedUploadAndSync(c *cli.Context) error {
197215
log.Info("all endpoints synced random data successfully")
198216

199217
// upload test file
200-
seed := int(time.Now().UnixNano() / 1e6)
201218
log.Info("feed uploading to "+httpEndpoint(hosts[0])+" and syncing", "seed", seed)
202219

203-
h = md5.New()
204-
r := io.TeeReader(io.LimitReader(crand.Reader, int64(filesize*1000)), h)
220+
randomBytes := testutil.RandomBytes(seed, filesize*1000)
205221

206-
hash, err := upload(r, filesize*1000, httpEndpoint(hosts[0]))
222+
hash, err := upload(randomBytes, httpEndpoint(hosts[0]))
207223
if err != nil {
208224
return err
209225
}

cmd/swarm/swarm-smoke/main.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,25 +120,25 @@ func main() {
120120
Name: "upload_and_sync",
121121
Aliases: []string{"c"},
122122
Usage: "upload and sync",
123-
Action: wrapCliCommand("upload-and-sync", true, uploadAndSync),
123+
Action: wrapCliCommand("upload-and-sync", uploadAndSync),
124124
},
125125
{
126126
Name: "feed_sync",
127127
Aliases: []string{"f"},
128128
Usage: "feed update generate, upload and sync",
129-
Action: wrapCliCommand("feed-and-sync", true, feedUploadAndSync),
129+
Action: wrapCliCommand("feed-and-sync", feedUploadAndSync),
130130
},
131131
{
132132
Name: "upload_speed",
133133
Aliases: []string{"u"},
134134
Usage: "measure upload speed",
135-
Action: wrapCliCommand("upload-speed", true, uploadSpeed),
135+
Action: wrapCliCommand("upload-speed", uploadSpeed),
136136
},
137137
{
138138
Name: "sliding_window",
139139
Aliases: []string{"s"},
140140
Usage: "measure network aggregate capacity",
141-
Action: wrapCliCommand("sliding-window", false, slidingWindow),
141+
Action: wrapCliCommand("sliding-window", slidingWindow),
142142
},
143143
}
144144

cmd/swarm/swarm-smoke/sliding_window.go

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,36 +17,49 @@
1717
package main
1818

1919
import (
20-
"crypto/md5"
21-
crand "crypto/rand"
20+
"bytes"
2221
"fmt"
23-
"io"
2422
"math/rand"
2523
"time"
2624

2725
"github.com/ethereum/go-ethereum/log"
2826
"github.com/ethereum/go-ethereum/metrics"
27+
"github.com/ethereum/go-ethereum/swarm/testutil"
2928
"github.com/pborman/uuid"
3029

3130
cli "gopkg.in/urfave/cli.v1"
3231
)
3332

34-
var seed = time.Now().UTC().UnixNano()
35-
36-
func init() {
37-
rand.Seed(seed)
38-
}
39-
4033
type uploadResult struct {
4134
hash string
4235
digest []byte
4336
}
4437

45-
func slidingWindow(c *cli.Context) error {
38+
func slidingWindow(ctx *cli.Context, tuid string) error {
39+
errc := make(chan error)
40+
41+
go func() {
42+
errc <- sl(ctx, tuid)
43+
}()
44+
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)
55+
}
56+
}
57+
58+
func sl(ctx *cli.Context, tuid string) error {
4659
hashes := []uploadResult{} //swarm hashes of the uploads
4760
nodes := len(hosts)
4861
const iterationTimeout = 30 * time.Second
49-
log.Info("sliding window test started", "nodes", nodes, "filesize(kb)", filesize, "timeout", timeout)
62+
log.Info("sliding window test started", "tuid", tuid, "nodes", nodes, "filesize(kb)", filesize, "timeout", timeout)
5063
uploadedBytes := 0
5164
networkDepth := 0
5265
errored := false
@@ -55,19 +68,23 @@ outer:
5568
for {
5669
log.Info("uploading to "+httpEndpoint(hosts[0])+" and syncing", "seed", seed)
5770

58-
h := md5.New()
59-
r := io.TeeReader(io.LimitReader(crand.Reader, int64(filesize*1000)), h)
6071
t1 := time.Now()
6172

62-
hash, err := upload(r, filesize*1000, httpEndpoint(hosts[0]))
73+
randomBytes := testutil.RandomBytes(seed, filesize*1000)
74+
75+
hash, err := upload(randomBytes, httpEndpoint(hosts[0]))
6376
if err != nil {
6477
log.Error(err.Error())
6578
return err
6679
}
6780

6881
metrics.GetOrRegisterResettingTimer("sliding-window.upload-time", nil).UpdateSince(t1)
6982

70-
fhash := h.Sum(nil)
83+
fhash, err := digest(bytes.NewReader(randomBytes))
84+
if err != nil {
85+
log.Error(err.Error())
86+
return err
87+
}
7188

7289
log.Info("uploaded successfully", "hash", hash, "digest", fmt.Sprintf("%x", fhash), "sleeping", syncDelay)
7390
hashes = append(hashes, uploadResult{hash: hash, digest: fhash})

cmd/swarm/swarm-smoke/upload_and_sync.go

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,50 +17,68 @@
1717
package main
1818

1919
import (
20-
"crypto/md5"
21-
crand "crypto/rand"
20+
"bytes"
2221
"fmt"
23-
"io"
2422
"math/rand"
2523
"sync"
2624
"time"
2725

2826
"github.com/ethereum/go-ethereum/log"
2927
"github.com/ethereum/go-ethereum/metrics"
28+
"github.com/ethereum/go-ethereum/swarm/testutil"
3029
"github.com/pborman/uuid"
3130

3231
cli "gopkg.in/urfave/cli.v1"
3332
)
3433

35-
func uploadAndSync(c *cli.Context) error {
36-
seed := int(time.Now().UnixNano() / 1e6)
34+
func uploadAndSync(ctx *cli.Context, tuid string) error {
35+
randomBytes := testutil.RandomBytes(seed, filesize*1000)
3736

38-
// test uuid
39-
tuid := uuid.New()[:8]
37+
errc := make(chan error)
4038

41-
log.Info("uploading to "+httpEndpoint(hosts[0])+" and syncing", "tuid", tuid, "seed", seed)
39+
go func() {
40+
errc <- uas(ctx, randomBytes, tuid)
41+
}()
42+
43+
select {
44+
case err := <-errc:
45+
if err != nil {
46+
metrics.GetOrRegisterCounter(fmt.Sprintf("%s.fail", commandName), nil).Inc(1)
47+
}
48+
return err
49+
case <-time.After(time.Duration(timeout) * time.Second):
50+
metrics.GetOrRegisterCounter(fmt.Sprintf("%s.timeout", commandName), nil).Inc(1)
4251

43-
h := md5.New()
44-
r := io.TeeReader(io.LimitReader(crand.Reader, int64(filesize*1000)), h)
52+
// trigger debug functionality on randomBytes
53+
54+
return fmt.Errorf("timeout after %v sec", timeout)
55+
}
56+
}
57+
58+
func uas(c *cli.Context, randomBytes []byte, tuid string) error {
59+
log.Info("uploading to "+httpEndpoint(hosts[0])+" and syncing", "tuid", tuid, "seed", seed)
4560

4661
t1 := time.Now()
47-
hash, err := upload(r, filesize*1000, httpEndpoint(hosts[0]))
62+
hash, err := upload(randomBytes, httpEndpoint(hosts[0]))
4863
if err != nil {
4964
log.Error(err.Error())
5065
return err
5166
}
5267
t2 := time.Since(t1)
5368
metrics.GetOrRegisterResettingTimer("upload-and-sync.upload-time", nil).Update(t2)
5469

55-
fhash := h.Sum(nil)
70+
fhash, err := digest(bytes.NewReader(randomBytes))
71+
if err != nil {
72+
log.Error(err.Error())
73+
return err
74+
}
5675

5776
log.Info("uploaded successfully", "tuid", tuid, "hash", hash, "took", t2, "digest", fmt.Sprintf("%x", fhash))
5877

5978
time.Sleep(time.Duration(syncDelay) * time.Second)
6079

6180
wg := sync.WaitGroup{}
6281
if single {
63-
rand.Seed(time.Now().UTC().UnixNano())
6482
randIndex := 1 + rand.Intn(len(hosts)-1)
6583
ruid := uuid.New()[:8]
6684
wg.Add(1)

cmd/swarm/swarm-smoke/upload_speed.go

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,38 +17,56 @@
1717
package main
1818

1919
import (
20-
"crypto/md5"
21-
crand "crypto/rand"
20+
"bytes"
2221
"fmt"
23-
"io"
2422
"time"
2523

2624
"github.com/ethereum/go-ethereum/log"
2725
"github.com/ethereum/go-ethereum/metrics"
26+
"github.com/ethereum/go-ethereum/swarm/testutil"
2827

2928
cli "gopkg.in/urfave/cli.v1"
3029
)
3130

32-
func uploadSpeed(c *cli.Context) error {
33-
if len(hosts) < 2 {
34-
log.Crit("less than 2 hosts")
35-
}
31+
func uploadSpeed(ctx *cli.Context, tuid string) error {
32+
log.Info("uploading to "+hosts[0], "tuid", tuid, "seed", seed)
33+
randomBytes := testutil.RandomBytes(seed, filesize*1000)
34+
35+
errc := make(chan error)
36+
37+
go func() {
38+
errc <- us(ctx, tuid, randomBytes)
39+
}()
3640

37-
seed := int(time.Now().UnixNano() / 1e6)
38-
log.Info("uploading to "+hosts[0], "seed", seed)
41+
select {
42+
case err := <-errc:
43+
if err != nil {
44+
metrics.GetOrRegisterCounter(fmt.Sprintf("%s.fail", commandName), nil).Inc(1)
45+
}
46+
return err
47+
case <-time.After(time.Duration(timeout) * time.Second):
48+
metrics.GetOrRegisterCounter(fmt.Sprintf("%s.timeout", commandName), nil).Inc(1)
3949

40-
h := md5.New()
41-
r := io.TeeReader(io.LimitReader(crand.Reader, int64(filesize*1000)), h)
50+
// trigger debug functionality on randomBytes
4251

52+
return fmt.Errorf("timeout after %v sec", timeout)
53+
}
54+
}
55+
56+
func us(c *cli.Context, tuid string, data []byte) error {
4357
t1 := time.Now()
44-
hash, err := upload(r, filesize*1000, hosts[0])
58+
hash, err := upload(data, hosts[0])
4559
if err != nil {
4660
log.Error(err.Error())
4761
return err
4862
}
4963
metrics.GetOrRegisterCounter("upload-speed.upload-time", nil).Inc(int64(time.Since(t1)))
5064

51-
fhash := h.Sum(nil)
65+
fhash, err := digest(bytes.NewReader(data))
66+
if err != nil {
67+
log.Error(err.Error())
68+
return err
69+
}
5270

5371
log.Info("uploaded successfully", "hash", hash, "digest", fmt.Sprintf("%x", fhash))
5472
return nil

0 commit comments

Comments
 (0)