修复 docker compose 配置问题,添加 block 监控项,优化日志输出

This commit is contained in:
2025-03-06 10:30:54 +08:00
parent 736dbff17d
commit 9d8bdaec7e
4 changed files with 25 additions and 18 deletions

View File

@@ -1,7 +1,6 @@
package main
import (
"math"
"math/rand"
"net/http"
"net/url"
@@ -11,19 +10,24 @@ import (
)
func main() {
go func() {
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"))
})
mock()
// attack()
}
err := http.ListenAndServe(":8080", nil)
if err != nil {
panic(err)
}
}()
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)
if err != nil {
panic(err)
}
}
func attack() {
targeter := vegeta.NewStaticTargeter(vegeta.Target{
Method: "GET",
URL: "http://localhost:8080",
@@ -31,7 +35,7 @@ func main() {
rate := vegeta.Rate{Freq: 500, Per: time.Second}
duration := 5 * time.Second
duration := 10 * time.Second
attacker := vegeta.NewAttacker()
@@ -43,7 +47,7 @@ func main() {
maxNum := 0
for res := range result {
math.Max(float64(res.Latency.Milliseconds()), float64(maxNum))
println(res.Latency)
}
println(maxNum)
}