修复 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)
}

View File

@@ -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:

View File

@@ -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 {

View File

@@ -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)