mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
cmd/swarm/swarm-smoke: address PR comments
This commit is contained in:
parent
ca37153f3a
commit
75b2b3428a
5 changed files with 59 additions and 71 deletions
|
|
@ -3,6 +3,7 @@ package main
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"crypto/md5"
|
"crypto/md5"
|
||||||
|
crand "crypto/rand"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
|
@ -16,7 +17,6 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
"github.com/ethereum/go-ethereum/log"
|
"github.com/ethereum/go-ethereum/log"
|
||||||
"github.com/ethereum/go-ethereum/swarm/storage/feed"
|
"github.com/ethereum/go-ethereum/swarm/storage/feed"
|
||||||
"github.com/ethereum/go-ethereum/swarm/testutil"
|
|
||||||
"github.com/pborman/uuid"
|
"github.com/pborman/uuid"
|
||||||
cli "gopkg.in/urfave/cli.v1"
|
cli "gopkg.in/urfave/cli.v1"
|
||||||
)
|
)
|
||||||
|
|
@ -203,9 +203,10 @@ func feedUploadAndSync(c *cli.Context) error {
|
||||||
seed := int(time.Now().UnixNano() / 1e6)
|
seed := int(time.Now().UnixNano() / 1e6)
|
||||||
log.Info("feed uploading to "+endpoints[0]+" and syncing", "seed", seed)
|
log.Info("feed uploading to "+endpoints[0]+" and syncing", "seed", seed)
|
||||||
|
|
||||||
randomBytes := testutil.RandomBytes(seed, filesize*1000)
|
h = md5.New()
|
||||||
|
r := io.TeeReader(io.LimitReader(crand.Reader, int64(filesize*1000)), h)
|
||||||
|
|
||||||
hash, err := upload(&randomBytes, endpoints[0])
|
hash, err := upload(r, filesize*1000, endpoints[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
@ -214,10 +215,7 @@ func feedUploadAndSync(c *cli.Context) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
multihashHex := hexutil.Encode(hashBytes)
|
multihashHex := hexutil.Encode(hashBytes)
|
||||||
fileHash, err := digest(bytes.NewReader(randomBytes))
|
fileHash := h.Sum(nil)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Info("uploaded successfully", "hash", hash, "digest", fmt.Sprintf("%x", fileHash))
|
log.Info("uploaded successfully", "hash", hash, "digest", fmt.Sprintf("%x", fileHash))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,31 +17,32 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"crypto/md5"
|
||||||
|
crand "crypto/rand"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"sync"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/log"
|
"github.com/ethereum/go-ethereum/log"
|
||||||
"github.com/ethereum/go-ethereum/metrics"
|
"github.com/ethereum/go-ethereum/metrics"
|
||||||
"github.com/ethereum/go-ethereum/swarm/testutil"
|
|
||||||
"github.com/pborman/uuid"
|
"github.com/pborman/uuid"
|
||||||
|
|
||||||
cli "gopkg.in/urfave/cli.v1"
|
cli "gopkg.in/urfave/cli.v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var seed = time.Now().UTC().UnixNano()
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
rand.Seed(seed)
|
||||||
|
}
|
||||||
|
|
||||||
type uploadResult struct {
|
type uploadResult struct {
|
||||||
hash string
|
hash string
|
||||||
digest []byte
|
digest []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
func slidingWindow(c *cli.Context) error {
|
func slidingWindow(c *cli.Context) error {
|
||||||
// test dscription:
|
|
||||||
// 1. upload repeatedly the same file size, maintain a slice in which swarm hashes are stored, first hash at idx=0
|
|
||||||
// 2. select a random node, start downloading the hashes, starting with the LAST one first (it should always be availble), till the FIRST hash
|
|
||||||
// 3. when
|
|
||||||
|
|
||||||
defer func(now time.Time) {
|
defer func(now time.Time) {
|
||||||
totalTime := time.Since(now)
|
totalTime := time.Since(now)
|
||||||
|
|
||||||
|
|
@ -50,69 +51,61 @@ func slidingWindow(c *cli.Context) error {
|
||||||
}(time.Now())
|
}(time.Now())
|
||||||
|
|
||||||
generateEndpoints(scheme, cluster, appName, from, to)
|
generateEndpoints(scheme, cluster, appName, from, to)
|
||||||
storeSize = storeSize * 4096 //store size is in chunks - transform to bytes
|
hashes := []uploadResult{} //swarm hashes of the uploads
|
||||||
hashes := []uploadResult{} //swarm hashes of the uploads
|
|
||||||
nodes := to - from
|
nodes := to - from
|
||||||
networkCapacity := float64(storeSize) * float64(nodes)
|
|
||||||
const iterationTimeout = 30 * time.Second
|
const iterationTimeout = 30 * time.Second
|
||||||
log.Info("sliding window test started", "store size(kb)", int(storeSize/1000), "nodes", nodes, "filesize(kb)", filesize, "network capacity(kb)", int(networkCapacity/1000), "timeout", timeout)
|
log.Info("sliding window test started", "nodes", nodes, "filesize(kb)", filesize, "timeout", timeout)
|
||||||
uploadedBytes := 0
|
uploadedBytes := 0
|
||||||
networkDepth := 0
|
networkDepth := 0
|
||||||
errored := false
|
errored := false
|
||||||
|
|
||||||
outer:
|
outer:
|
||||||
for {
|
for {
|
||||||
seed := int(time.Now().UnixNano() / 1e6)
|
|
||||||
log.Info("uploading to "+endpoints[0]+" and syncing", "seed", seed)
|
log.Info("uploading to "+endpoints[0]+" and syncing", "seed", seed)
|
||||||
|
|
||||||
randomBytes := testutil.RandomBytes(seed, filesize*1000)
|
h := md5.New()
|
||||||
|
r := io.TeeReader(io.LimitReader(crand.Reader, int64(filesize*1000)), h)
|
||||||
t1 := time.Now()
|
t1 := time.Now()
|
||||||
hash, err := upload(&randomBytes, endpoints[0])
|
|
||||||
if err != nil {
|
|
||||||
log.Error(err.Error())
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
metrics.GetOrRegisterCounter("sliding-window.upload-time", nil).Inc(int64(time.Since(t1)))
|
|
||||||
|
|
||||||
fhash, err := digest(bytes.NewReader(randomBytes))
|
hash, err := upload(r, filesize*1000, endpoints[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(err.Error())
|
log.Error(err.Error())
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
metrics.GetOrRegisterResettingTimer("sliding-window.upload-time", nil).UpdateSince(t1)
|
||||||
|
|
||||||
|
fhash := h.Sum(nil)
|
||||||
|
|
||||||
log.Info("uploaded successfully", "hash", hash, "digest", fmt.Sprintf("%x", fhash), "sleeping", syncDelay)
|
log.Info("uploaded successfully", "hash", hash, "digest", fmt.Sprintf("%x", fhash), "sleeping", syncDelay)
|
||||||
hashes = append(hashes, uploadResult{hash: hash, digest: fhash})
|
hashes = append(hashes, uploadResult{hash: hash, digest: fhash})
|
||||||
time.Sleep(time.Duration(syncDelay) * time.Second)
|
time.Sleep(time.Duration(syncDelay) * time.Second)
|
||||||
uploadedBytes += filesize * 1000
|
uploadedBytes += filesize * 1000
|
||||||
var wg sync.WaitGroup
|
|
||||||
for i, v := range hashes {
|
for i, v := range hashes {
|
||||||
timeout := time.After(30 * time.Second)
|
timeout := time.After(30 * time.Second)
|
||||||
errored = false
|
errored = false
|
||||||
wg.Add(1)
|
|
||||||
go func(i int, v uploadResult) {
|
inner:
|
||||||
defer wg.Done()
|
for {
|
||||||
for {
|
select {
|
||||||
select {
|
case <-timeout:
|
||||||
case <-timeout:
|
errored = true
|
||||||
errored = true
|
log.Error("error retrieving hash. timeout", "hash idx", i, "err", err)
|
||||||
log.Error("error retrieving hash. timeout", "hash idx", i, "err", err)
|
metrics.GetOrRegisterCounter("sliding-window.single.error", nil).Inc(1)
|
||||||
metrics.GetOrRegisterCounter("sliding-window.single.error", nil).Inc(1)
|
default:
|
||||||
return
|
|
||||||
default:
|
|
||||||
}
|
|
||||||
rand.Seed(time.Now().UTC().UnixNano())
|
|
||||||
randIndex := 1 + rand.Intn(len(endpoints)-1)
|
randIndex := 1 + rand.Intn(len(endpoints)-1)
|
||||||
ruid := uuid.New()[:8]
|
ruid := uuid.New()[:8]
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
err := fetch(v.hash, endpoints[randIndex], v.digest, ruid)
|
err := fetch(v.hash, endpoints[randIndex], v.digest, ruid)
|
||||||
fetchTime := time.Since(start)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue inner
|
||||||
}
|
}
|
||||||
metrics.GetOrRegisterMeter("sliding-window.single.fetch-time", nil).Mark(int64(fetchTime))
|
metrics.GetOrRegisterResettingTimer("sliding-window.single.fetch-time", nil).UpdateSince(start)
|
||||||
|
break inner
|
||||||
}
|
}
|
||||||
}(i, v)
|
}
|
||||||
wg.Wait()
|
|
||||||
if errored {
|
if errored {
|
||||||
break outer
|
break outer
|
||||||
}
|
}
|
||||||
|
|
@ -120,8 +113,8 @@ outer:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Info("sliding window test finished", "errored?", errored, "networkDepth", networkDepth, "networkDepth(kb)", int(networkDepth*filesize))
|
log.Info("sliding window test finished", "errored?", errored, "networkDepth", networkDepth, "networkDepth(kb)", networkDepth*filesize)
|
||||||
log.Info("stats", "uploadedFiles", len(hashes), "uploadedKb", uploadedBytes/1000, "filesizeKb", filesize, "networkCapacityKb", int(networkCapacity/1000), "networkCapacityMb", int(networkCapacity/1000000))
|
log.Info("stats", "uploadedFiles", len(hashes), "uploadedKb", uploadedBytes/1000, "filesizeKb", filesize)
|
||||||
|
|
||||||
metrics.GetOrRegisterMeter("sliding-window.network-depth", nil).Mark(int64(networkDepth))
|
metrics.GetOrRegisterMeter("sliding-window.network-depth", nil).Mark(int64(networkDepth))
|
||||||
return nil
|
return nil
|
||||||
|
|
|
||||||
|
|
@ -17,15 +17,16 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"crypto/md5"
|
||||||
|
crand "crypto/rand"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/log"
|
"github.com/ethereum/go-ethereum/log"
|
||||||
"github.com/ethereum/go-ethereum/metrics"
|
"github.com/ethereum/go-ethereum/metrics"
|
||||||
"github.com/ethereum/go-ethereum/swarm/testutil"
|
|
||||||
"github.com/pborman/uuid"
|
"github.com/pborman/uuid"
|
||||||
|
|
||||||
cli "gopkg.in/urfave/cli.v1"
|
cli "gopkg.in/urfave/cli.v1"
|
||||||
|
|
@ -40,23 +41,21 @@ func uploadAndSync(c *cli.Context) error {
|
||||||
|
|
||||||
generateEndpoints(scheme, cluster, appName, from, to)
|
generateEndpoints(scheme, cluster, appName, from, to)
|
||||||
seed := int(time.Now().UnixNano() / 1e6)
|
seed := int(time.Now().UnixNano() / 1e6)
|
||||||
|
|
||||||
log.Info("uploading to "+endpoints[0]+" and syncing", "seed", seed)
|
log.Info("uploading to "+endpoints[0]+" and syncing", "seed", seed)
|
||||||
|
|
||||||
randomBytes := testutil.RandomBytes(seed, filesize*1000)
|
h := md5.New()
|
||||||
|
r := io.TeeReader(io.LimitReader(crand.Reader, int64(filesize*1000)), h)
|
||||||
|
|
||||||
t1 := time.Now()
|
t1 := time.Now()
|
||||||
hash, err := upload(&randomBytes, endpoints[0])
|
hash, err := upload(r, filesize*1000, endpoints[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(err.Error())
|
log.Error(err.Error())
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
metrics.GetOrRegisterResettingTimer("upload-and-sync.upload-time", nil).UpdateSince(t1)
|
metrics.GetOrRegisterResettingTimer("upload-and-sync.upload-time", nil).UpdateSince(t1)
|
||||||
|
|
||||||
fhash, err := digest(bytes.NewReader(randomBytes))
|
fhash := h.Sum(nil)
|
||||||
if err != nil {
|
|
||||||
log.Error(err.Error())
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Info("uploaded successfully", "hash", hash, "digest", fmt.Sprintf("%x", fhash))
|
log.Info("uploaded successfully", "hash", hash, "digest", fmt.Sprintf("%x", fhash))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,13 +17,14 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"crypto/md5"
|
||||||
|
crand "crypto/rand"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/log"
|
"github.com/ethereum/go-ethereum/log"
|
||||||
"github.com/ethereum/go-ethereum/metrics"
|
"github.com/ethereum/go-ethereum/metrics"
|
||||||
"github.com/ethereum/go-ethereum/swarm/testutil"
|
|
||||||
|
|
||||||
cli "gopkg.in/urfave/cli.v1"
|
cli "gopkg.in/urfave/cli.v1"
|
||||||
)
|
)
|
||||||
|
|
@ -40,21 +41,18 @@ func uploadSpeed(c *cli.Context) error {
|
||||||
seed := int(time.Now().UnixNano() / 1e6)
|
seed := int(time.Now().UnixNano() / 1e6)
|
||||||
log.Info("uploading to "+endpoint, "seed", seed)
|
log.Info("uploading to "+endpoint, "seed", seed)
|
||||||
|
|
||||||
randomBytes := testutil.RandomBytes(seed, filesize*1000)
|
h := md5.New()
|
||||||
|
r := io.TeeReader(io.LimitReader(crand.Reader, int64(filesize*1000)), h)
|
||||||
|
|
||||||
t1 := time.Now()
|
t1 := time.Now()
|
||||||
hash, err := upload(&randomBytes, endpoint)
|
hash, err := upload(r, filesize*1000, endpoint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(err.Error())
|
log.Error(err.Error())
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
metrics.GetOrRegisterCounter("upload-speed.upload-time", nil).Inc(int64(time.Since(t1)))
|
metrics.GetOrRegisterCounter("upload-speed.upload-time", nil).Inc(int64(time.Since(t1)))
|
||||||
|
|
||||||
fhash, err := digest(bytes.NewReader(randomBytes))
|
fhash := h.Sum(nil)
|
||||||
if err != nil {
|
|
||||||
log.Error(err.Error())
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Info("uploaded successfully", "hash", hash, "digest", fmt.Sprintf("%x", fhash))
|
log.Info("uploaded successfully", "hash", hash, "digest", fmt.Sprintf("%x", fhash))
|
||||||
return nil
|
return nil
|
||||||
|
|
|
||||||
|
|
@ -203,14 +203,14 @@ func fetch(hash string, endpoint string, original []byte, ruid string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// upload an arbitrary byte as a plaintext file to `endpoint` using the api client
|
// upload an arbitrary byte as a plaintext file to `endpoint` using the api client
|
||||||
func upload(dataBytes *[]byte, endpoint string) (string, error) {
|
func upload(r io.Reader, size int, endpoint string) (string, error) {
|
||||||
swarm := client.NewClient(endpoint)
|
swarm := client.NewClient(endpoint)
|
||||||
f := &client.File{
|
f := &client.File{
|
||||||
ReadCloser: ioutil.NopCloser(bytes.NewReader(*dataBytes)),
|
ReadCloser: ioutil.NopCloser(r),
|
||||||
ManifestEntry: api.ManifestEntry{
|
ManifestEntry: api.ManifestEntry{
|
||||||
ContentType: "text/plain",
|
ContentType: "text/plain",
|
||||||
Mode: 0660,
|
Mode: 0660,
|
||||||
Size: int64(len(*dataBytes)),
|
Size: int64(size),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue