diff options
| author | hilimd <68371223+hilimd@users.noreply.github.com> | 2020-10-26 22:01:50 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-10-26 22:01:50 +0800 |
| commit | 843865f2ca534bb6286b7a3d79c436384d875608 (patch) | |
| tree | 653943fe04caf3fe607416715fb341460a624ab7 /unmaintained | |
| parent | cf7a1c722fa82fa78c546f68e4814fff7dc6d1e2 (diff) | |
| parent | 44921220b01d21c64755cbc7560ff8932f71984d (diff) | |
| download | seaweedfs-843865f2ca534bb6286b7a3d79c436384d875608.tar.xz seaweedfs-843865f2ca534bb6286b7a3d79c436384d875608.zip | |
Merge pull request #33 from chrislusf/master
sync
Diffstat (limited to 'unmaintained')
| -rw-r--r-- | unmaintained/stress_filer_upload/write_files/write_files.go | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/unmaintained/stress_filer_upload/write_files/write_files.go b/unmaintained/stress_filer_upload/write_files/write_files.go new file mode 100644 index 000000000..508e37d14 --- /dev/null +++ b/unmaintained/stress_filer_upload/write_files/write_files.go @@ -0,0 +1,54 @@ +package main + +import ( + "flag" + "fmt" + "math/rand" + "os" + "time" +) + +var ( + minSize = flag.Int("minSize", 1024, "min file size") + maxSize = flag.Int("maxSize", 3*1024*1024, "max file size") + fileCount = flag.Int("n", 1, "number of files to write") + blockSize = flag.Int("blockSizeKB", 4, "write block size") + toDir = flag.String("dir", ".", "destination directory") +) + +func check(e error) { + if e != nil { + panic(e) + } +} + +func main() { + + flag.Parse() + + block := make([]byte, *blockSize*1024) + + for i := 0; i < *fileCount; i++ { + + f, err := os.Create(fmt.Sprintf("%s/file%05d", *toDir, i)) + check(err) + + fileSize := *minSize + rand.Intn(*maxSize-*minSize) + startTime := time.Now() + + fmt.Printf("write %s %d bytes: ", f.Name(), fileSize) + + for x := 0; x < fileSize; { + rand.Read(block) + _, err = f.Write(block) + check(err) + x += len(block) + } + + err = f.Close() + check(err) + + fmt.Printf("%.02f MB/sec\n", float64(fileSize)*float64(time.Second)/float64(time.Now().Sub(startTime)*1024*1024)) + } + +} |
