修复 docker compose 配置问题,添加 block 监控项,优化日志输出
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"math"
|
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
@@ -11,7 +10,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
go func() {
|
mock()
|
||||||
|
// attack()
|
||||||
|
}
|
||||||
|
|
||||||
|
func mock() {
|
||||||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||||
waiting := rand.Intn(450) + 50
|
waiting := rand.Intn(450) + 50
|
||||||
time.Sleep(time.Duration(waiting) * time.Millisecond)
|
time.Sleep(time.Duration(waiting) * time.Millisecond)
|
||||||
@@ -22,8 +25,9 @@ func main() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
}()
|
}
|
||||||
|
|
||||||
|
func attack() {
|
||||||
targeter := vegeta.NewStaticTargeter(vegeta.Target{
|
targeter := vegeta.NewStaticTargeter(vegeta.Target{
|
||||||
Method: "GET",
|
Method: "GET",
|
||||||
URL: "http://localhost:8080",
|
URL: "http://localhost:8080",
|
||||||
@@ -31,7 +35,7 @@ func main() {
|
|||||||
|
|
||||||
rate := vegeta.Rate{Freq: 500, Per: time.Second}
|
rate := vegeta.Rate{Freq: 500, Per: time.Second}
|
||||||
|
|
||||||
duration := 5 * time.Second
|
duration := 10 * time.Second
|
||||||
|
|
||||||
attacker := vegeta.NewAttacker()
|
attacker := vegeta.NewAttacker()
|
||||||
|
|
||||||
@@ -43,7 +47,7 @@ func main() {
|
|||||||
|
|
||||||
maxNum := 0
|
maxNum := 0
|
||||||
for res := range result {
|
for res := range result {
|
||||||
math.Max(float64(res.Latency.Milliseconds()), float64(maxNum))
|
println(res.Latency)
|
||||||
}
|
}
|
||||||
println(maxNum)
|
println(maxNum)
|
||||||
}
|
}
|
||||||
|
|||||||
6
scripts/env/test/docker-compose.yaml
vendored
6
scripts/env/test/docker-compose.yaml
vendored
@@ -21,7 +21,7 @@ services:
|
|||||||
container_name: proxy-server-dev-service
|
container_name: proxy-server-dev-service
|
||||||
build:
|
build:
|
||||||
context: ../../..
|
context: ../../..
|
||||||
dockerfile: ../../../Dockerfile
|
dockerfile: Dockerfile
|
||||||
environment:
|
environment:
|
||||||
APP_CTRL_PORT: $APP_CTRL_PORT
|
APP_CTRL_PORT: $APP_CTRL_PORT
|
||||||
APP_DATA_PORT: $APP_DATA_PORT
|
APP_DATA_PORT: $APP_DATA_PORT
|
||||||
@@ -46,8 +46,8 @@ services:
|
|||||||
vector:
|
vector:
|
||||||
container_name: proxy-server-dev-vector
|
container_name: proxy-server-dev-vector
|
||||||
build:
|
build:
|
||||||
context: vector
|
context: ./vector
|
||||||
dockerfile: vector/Dockerfile
|
dockerfile: Dockerfile
|
||||||
ports:
|
ports:
|
||||||
- "8686:8686"
|
- "8686:8686"
|
||||||
volumes:
|
volumes:
|
||||||
|
|||||||
@@ -158,7 +158,6 @@ func (s *Service) startCtrlTun() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Service) processCtrlConn(conn net.Conn) error {
|
func (s *Service) processCtrlConn(conn net.Conn) error {
|
||||||
slog.Debug("客户端连入", "addr", conn.RemoteAddr().String())
|
|
||||||
reader := bufio.NewReader(conn)
|
reader := bufio.NewReader(conn)
|
||||||
|
|
||||||
// 获取转发端口
|
// 获取转发端口
|
||||||
@@ -168,6 +167,8 @@ func (s *Service) processCtrlConn(conn net.Conn) error {
|
|||||||
}
|
}
|
||||||
port := binary.BigEndian.Uint16(portBuf)
|
port := binary.BigEndian.Uint16(portBuf)
|
||||||
|
|
||||||
|
slog.Info("客户端注册", "addr", conn.RemoteAddr().String(), "port", port)
|
||||||
|
|
||||||
// 启动转发服务
|
// 启动转发服务
|
||||||
proxy, err := dispatcher.New(port)
|
proxy, err := dispatcher.New(port)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import (
|
|||||||
"proxy-server/server/pkg/env"
|
"proxy-server/server/pkg/env"
|
||||||
"proxy-server/server/pkg/log"
|
"proxy-server/server/pkg/log"
|
||||||
"proxy-server/server/pkg/orm"
|
"proxy-server/server/pkg/orm"
|
||||||
|
"runtime"
|
||||||
"sync"
|
"sync"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
@@ -39,6 +40,7 @@ func Start() {
|
|||||||
|
|
||||||
// 性能监控
|
// 性能监控
|
||||||
go func() {
|
go func() {
|
||||||
|
runtime.SetBlockProfileRate(1)
|
||||||
err := http.ListenAndServe(":6060", nil)
|
err := http.ListenAndServe(":6060", nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
slog.Error("性能监控服务发生错误", "err", err)
|
slog.Error("性能监控服务发生错误", "err", err)
|
||||||
|
|||||||
Reference in New Issue
Block a user