mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2025-11-24 08:46:54 +08:00
stress test filer
This commit is contained in:
@@ -4,7 +4,10 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
|
"math/rand"
|
||||||
"mime/multipart"
|
"mime/multipart"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
@@ -17,6 +20,7 @@ var (
|
|||||||
size = flag.Int("size", 1024, "file size")
|
size = flag.Int("size", 1024, "file size")
|
||||||
concurrency = flag.Int("c", 4, "concurrent number of uploads")
|
concurrency = flag.Int("c", 4, "concurrent number of uploads")
|
||||||
times = flag.Int("n", 1024, "repeated number of times")
|
times = flag.Int("n", 1024, "repeated number of times")
|
||||||
|
fileCount = flag.Int("fileCount", 1, "number of files to write")
|
||||||
destination = flag.String("to", "http://localhost:8888/", "destination directory on filer")
|
destination = flag.String("to", "http://localhost:8888/", "destination directory on filer")
|
||||||
|
|
||||||
statsChan = make(chan stat, 8)
|
statsChan = make(chan stat, 8)
|
||||||
@@ -37,24 +41,32 @@ func main() {
|
|||||||
for x := 0; x < *concurrency; x++ {
|
for x := 0; x < *concurrency; x++ {
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
|
|
||||||
client := &http.Client{}
|
go func(x int) {
|
||||||
|
|
||||||
go func() {
|
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
|
|
||||||
|
client := &http.Client{Transport: &http.Transport{
|
||||||
|
MaxConnsPerHost: 1024,
|
||||||
|
MaxIdleConnsPerHost: 1024,
|
||||||
|
}}
|
||||||
|
r := rand.New(rand.NewSource(time.Now().UnixNano() + int64(x)))
|
||||||
|
|
||||||
for t := 0; t < *times; t++ {
|
for t := 0; t < *times; t++ {
|
||||||
if size, err := uploadFileToFiler(client, data, fmt.Sprintf("file%d", t), *destination); err == nil {
|
for f := 0; f < *fileCount; f++ {
|
||||||
statsChan <- stat{
|
fn := r.Intn(*fileCount)
|
||||||
size: size,
|
if size, err := uploadFileToFiler(client, data, fmt.Sprintf("file%04d", fn), *destination); err == nil {
|
||||||
|
statsChan <- stat{
|
||||||
|
size: size,
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log.Fatalf("client %d upload %d times: %v", x, t, err)
|
||||||
}
|
}
|
||||||
}else {
|
|
||||||
log.Fatalf("upload: %v", err)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}(x)
|
||||||
}
|
}
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
ticker := time.NewTicker(500 * time.Millisecond)
|
ticker := time.NewTicker(1000 * time.Millisecond)
|
||||||
|
|
||||||
var lastTime time.Time
|
var lastTime time.Time
|
||||||
var counter, size int64
|
var counter, size int64
|
||||||
@@ -105,6 +117,7 @@ func uploadFileToFiler(client *http.Client, data []byte, filename, destination s
|
|||||||
|
|
||||||
request, err := http.NewRequest("POST", uri, body)
|
request, err := http.NewRequest("POST", uri, body)
|
||||||
request.Header.Set("Content-Type", writer.FormDataContentType())
|
request.Header.Set("Content-Type", writer.FormDataContentType())
|
||||||
|
// request.Close = true // can not use this, which do not reuse http connection, impacting filer->volume also.
|
||||||
|
|
||||||
resp, err := client.Do(request)
|
resp, err := client.Do(request)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -115,6 +128,7 @@ func uploadFileToFiler(client *http.Client, data []byte, filename, destination s
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, fmt.Errorf("read http POST %s response: %v", uri, err)
|
return 0, fmt.Errorf("read http POST %s response: %v", uri, err)
|
||||||
}
|
}
|
||||||
|
io.Copy(ioutil.Discard, resp.Body)
|
||||||
resp.Body.Close()
|
resp.Body.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -142,6 +142,7 @@ func uploadFileToFiler(client *http.Client, filename, destination string) (size
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, fmt.Errorf("read http POST %s response: %v", uri, err)
|
return 0, fmt.Errorf("read http POST %s response: %v", uri, err)
|
||||||
}
|
}
|
||||||
|
io.Copy(ioutil.Discard, resp.Body)
|
||||||
resp.Body.Close()
|
resp.Body.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user