From 9d8bdaec7eff17b3e8a2495f273413cfbc6bc9d1 Mon Sep 17 00:00:00 2001 From: luorijun Date: Thu, 6 Mar 2025 10:30:54 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20docker=20compose=20?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E9=97=AE=E9=A2=98=EF=BC=8C=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=20block=20=E7=9B=91=E6=8E=A7=E9=A1=B9=EF=BC=8C=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E6=97=A5=E5=BF=97=E8=BE=93=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/mock/main.go | 32 ++++++++++++++++------------ scripts/env/test/docker-compose.yaml | 6 +++--- server/fwd/fwd.go | 3 ++- server/server.go | 2 ++ 4 files changed, 25 insertions(+), 18 deletions(-) diff --git a/cmd/mock/main.go b/cmd/mock/main.go index bb6fc81..93cdb67 100644 --- a/cmd/mock/main.go +++ b/cmd/mock/main.go @@ -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) } diff --git a/scripts/env/test/docker-compose.yaml b/scripts/env/test/docker-compose.yaml index 1941188..b7cbd47 100644 --- a/scripts/env/test/docker-compose.yaml +++ b/scripts/env/test/docker-compose.yaml @@ -21,7 +21,7 @@ services: container_name: proxy-server-dev-service build: context: ../../.. - dockerfile: ../../../Dockerfile + dockerfile: Dockerfile environment: APP_CTRL_PORT: $APP_CTRL_PORT APP_DATA_PORT: $APP_DATA_PORT @@ -46,8 +46,8 @@ services: vector: container_name: proxy-server-dev-vector build: - context: vector - dockerfile: vector/Dockerfile + context: ./vector + dockerfile: Dockerfile ports: - "8686:8686" volumes: diff --git a/server/fwd/fwd.go b/server/fwd/fwd.go index a94d4c9..ad5c13d 100644 --- a/server/fwd/fwd.go +++ b/server/fwd/fwd.go @@ -158,7 +158,6 @@ func (s *Service) startCtrlTun() error { } func (s *Service) processCtrlConn(conn net.Conn) error { - slog.Debug("客户端连入", "addr", conn.RemoteAddr().String()) reader := bufio.NewReader(conn) // 获取转发端口 @@ -168,6 +167,8 @@ func (s *Service) processCtrlConn(conn net.Conn) error { } port := binary.BigEndian.Uint16(portBuf) + slog.Info("客户端注册", "addr", conn.RemoteAddr().String(), "port", port) + // 启动转发服务 proxy, err := dispatcher.New(port) if err != nil { diff --git a/server/server.go b/server/server.go index 968cdbf..007be82 100644 --- a/server/server.go +++ b/server/server.go @@ -11,6 +11,7 @@ import ( "proxy-server/server/pkg/env" "proxy-server/server/pkg/log" "proxy-server/server/pkg/orm" + "runtime" "sync" "syscall" "time" @@ -39,6 +40,7 @@ func Start() { // 性能监控 go func() { + runtime.SetBlockProfileRate(1) err := http.ListenAndServe(":6060", nil) if err != nil { slog.Error("性能监控服务发生错误", "err", err)