-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.go
62 lines (54 loc) · 1.29 KB
/
test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package main
import (
"flag"
"fmt"
"math/rand"
"os"
"time"
"github.com/ginuerzh/weedo"
)
var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
func randStr(n int) string {
s := make([]rune, n)
for i := range s {
s[i] = letters[rand.Intn(len(letters))]
}
return string(s)
}
func smallFileUploadTest(filedir string, master string) {
// generate small files
for i := 0; i < 1024; i++ {
f, err := os.Create(filedir + "small" + fmt.Sprint(i))
if err != nil {
panic(err)
}
_, err = f.Write([]byte(randStr(1024 * 1024)))
if err != nil {
panic(err)
}
f.Close()
}
// upload the files
start := time.Now()
client := weedo.NewClient(master, "")
for i := 0; i < 1024; i++ {
f, err := os.Open(filedir + "small" + fmt.Sprint(i))
if err != nil {
panic(err)
}
client.AssignUpload(randStr(4)+"small"+fmt.Sprint(i), "text/plain", f)
f.Close()
}
fmt.Print(1024 / time.Since(start).Seconds())
fmt.Println(" MiB/s")
fmt.Println("(Small File Upload Speed)")
}
func main() {
master := flag.String("master", "", "Specify master address")
filedir := flag.String("f", "", "Specify data directory")
op := flag.String("op", "", "Specify operation (s: small upload; l: large upload)")
flag.Parse()
if *op == "s" {
smallFileUploadTest(*filedir, *master)
}
}