aboutsummaryrefslogtreecommitdiff
path: root/unmaintained/stress_filer_upload/write_files/write_files.go
diff options
context:
space:
mode:
authorbingoohuang <bingoo.huang@gmail.com>2021-04-26 17:19:35 +0800
committerbingoohuang <bingoo.huang@gmail.com>2021-04-26 17:19:35 +0800
commitd861cbd81b75b6684c971ac00e33685e6575b833 (patch)
tree301805fef4aa5d0096bfb1510536f7a009b661e7 /unmaintained/stress_filer_upload/write_files/write_files.go
parent70da715d8d917527291b35fb069fac077d17b868 (diff)
parent4ee58922eff61a5a4ca29c0b4829b097a498549e (diff)
downloadseaweedfs-d861cbd81b75b6684c971ac00e33685e6575b833.tar.xz
seaweedfs-d861cbd81b75b6684c971ac00e33685e6575b833.zip
Merge branch 'master' of https://github.com/bingoohuang/seaweedfs
Diffstat (limited to 'unmaintained/stress_filer_upload/write_files/write_files.go')
-rw-r--r--unmaintained/stress_filer_upload/write_files/write_files.go54
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))
+ }
+
+}