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)