修复连接超时问题
This commit is contained in:
@@ -3,10 +3,7 @@ package main
|
||||
import (
|
||||
"math/rand"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"time"
|
||||
|
||||
vegeta "github.com/tsenart/vegeta/lib"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -15,39 +12,20 @@ func main() {
|
||||
}
|
||||
|
||||
func mock() {
|
||||
|
||||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
waiting := rand.Intn(450) + 50
|
||||
time.Sleep(time.Duration(waiting) * time.Millisecond)
|
||||
w.Write([]byte("Hello World"))
|
||||
})
|
||||
|
||||
err := http.ListenAndServe(":8080", nil)
|
||||
serv := &http.Server{
|
||||
Addr: ":8080",
|
||||
Handler: nil,
|
||||
}
|
||||
serv.SetKeepAlivesEnabled(false)
|
||||
err := serv.ListenAndServe()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func attack() {
|
||||
targeter := vegeta.NewStaticTargeter(vegeta.Target{
|
||||
Method: "GET",
|
||||
URL: "http://localhost:8080",
|
||||
})
|
||||
|
||||
rate := vegeta.Rate{Freq: 500, Per: time.Second}
|
||||
|
||||
duration := 10 * time.Second
|
||||
|
||||
attacker := vegeta.NewAttacker()
|
||||
|
||||
vegeta.Proxy(func(request *http.Request) (*url.URL, error) {
|
||||
return url.Parse("http://test-api.imfree.site:20001")
|
||||
})(attacker)
|
||||
|
||||
result := attacker.Attack(targeter, rate, duration, "test")
|
||||
|
||||
maxNum := 0
|
||||
for res := range result {
|
||||
println(res.Latency)
|
||||
}
|
||||
println(maxNum)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user