Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/YanHeDoki/zinx
Browse files Browse the repository at this point in the history
  • Loading branch information
YanHeDoki committed May 6, 2023
2 parents 7f46617 + 766f595 commit 04599f5
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 806 deletions.
4 changes: 0 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@ module github.com/aceld/zinx
go 1.16

require (
github.com/davecgh/go-spew v1.1.1
github.com/golang/protobuf v1.5.3
github.com/gorilla/websocket v1.5.0
github.com/pmezard/go-difflib v1.0.0
github.com/prometheus/client_golang v1.15.0
github.com/stretchr/testify v1.8.1
gopkg.in/yaml.v3 v3.0.1
)
514 changes: 4 additions & 510 deletions go.sum

Large diffs are not rendered by default.

56 changes: 19 additions & 37 deletions zconf/globalobj.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,21 +82,6 @@ type Config struct {
*/
CertFile string // The name of the certificate file. If it is empty, TLS encryption is not enabled.(证书文件名称 默认"")
PrivateKeyFile string // The name of the private key file. If it is empty, TLS encryption is not enabled.(私钥文件名称 默认"" --如果没有设置证书和私钥文件,则不启用TLS加密)

/*
Prometheus Metrics
*/
// A boolean value that indicates whether Prometheus Metrics is enabled. The default value is false.
// (是否开启Prometheus Metrics 指标统计, 默认为false关闭)
PrometheusMetricsEnable bool

// A boolean value that indicates whether a separate Prometheus Metrics server is required. The default value is false.
// (是否需要zinx单独启动一个Prometheus Metrics 服务, 默认为false关闭)
PrometheusServer bool

// The IP address and port number of the Prometheus Metrics server. The default value is "0.0.0.0:20004".
// (Prometheus Metrics 服务IP和端口, 默认为 0.0.0.0:20004)
PrometheusListen string
}

/*
Expand Down Expand Up @@ -197,28 +182,25 @@ func init() {
// Initialize the GlobalObject variable and set some default values.
// (初始化GlobalObject变量,设置一些默认值)
GlobalObject = &Config{
Name: "ZinxServerApp",
Version: "V1.0",
TCPPort: 8999,
WsPort: 9000,
Host: "0.0.0.0",
MaxConn: 12000,
MaxPacketSize: 4096,
WorkerPoolSize: 10,
MaxWorkerTaskLen: 1024,
MaxMsgChanLen: 1024,
LogDir: pwd + "/log",
LogFile: "", //if set "", print to Stderr(默认日志文件为空,打印到stderr)
LogIsolationLevel: 0,
HeartbeatMax: 10, //The default maximum interval for heartbeat detection is 10 seconds. (默认心跳检测最长间隔为10秒)
IOReadBuffSize: 1024,
CertFile: "",
PrivateKeyFile: "",
Mode: ServerModeTcp,
PrometheusMetricsEnable: false,
PrometheusServer: false,
PrometheusListen: "0.0.0.0:20004",
RouterSlicesMode: false,
Name: "ZinxServerApp",
Version: "V1.0",
TCPPort: 8999,
WsPort: 9000,
Host: "0.0.0.0",
MaxConn: 12000,
MaxPacketSize: 4096,
WorkerPoolSize: 10,
MaxWorkerTaskLen: 1024,
MaxMsgChanLen: 1024,
LogDir: pwd + "/log",
LogFile: "", //if set "", print to Stderr(默认日志文件为空,打印到stderr)
LogIsolationLevel: 0,
HeartbeatMax: 10, //The default maximum interval for heartbeat detection is 10 seconds. (默认心跳检测最长间隔为10秒)
IOReadBuffSize: 1024,
CertFile: "",
PrivateKeyFile: "",
Mode: ServerModeTcp,
RouterSlicesMode: false,
}

// Note: Load some user-configured parameters from the configuration file.
Expand Down
12 changes: 0 additions & 12 deletions zconf/userconf.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,6 @@ func UserConfToGlobal(config *Config) {
GlobalObject.WsPort = config.WsPort
}

// Prometheus Metrics
if config.PrometheusMetricsEnable != false {
GlobalObject.PrometheusMetricsEnable = config.PrometheusMetricsEnable
}

if config.PrometheusServer != false {
GlobalObject.PrometheusServer = config.PrometheusServer
}

if config.PrometheusListen != "" {
GlobalObject.PrometheusListen = config.PrometheusListen
}
if config.RouterSlicesMode {
GlobalObject.RouterSlicesMode = config.RouterSlicesMode
}
Expand Down
73 changes: 0 additions & 73 deletions zmetrics/metrics.go

This file was deleted.

22 changes: 0 additions & 22 deletions zmetrics/opts.go

This file was deleted.

82 changes: 0 additions & 82 deletions zmetrics/prometheus_service.go

This file was deleted.

10 changes: 0 additions & 10 deletions znet/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import (
"sync"
"time"

"github.com/aceld/zinx/zmetrics"

"github.com/aceld/zinx/zconf"
"github.com/aceld/zinx/zinterceptor"
"github.com/aceld/zinx/zlog"
Expand Down Expand Up @@ -139,10 +137,6 @@ func newServerConn(server ziface.IServer, conn net.Conn, connID uint64) ziface.I
// (将新创建的Conn添加到链接管理中)
server.GetConnMgr().Add(c)

// Increase the connection count metric for the WS server
// (统计ws服务链接数量指标)
zmetrics.Metrics().IncConn(c.localAddr, c.name)

return c
}

Expand Down Expand Up @@ -499,10 +493,6 @@ func (c *Connection) finalizer() {

c.isClosed = true

// Remove the connection count from the metrics
// (将Metrics的指标删除conn数量)
zmetrics.Metrics().DecConn(c.localAddr, c.name)

zlog.Ins().InfoF("Conn Stop()...ConnID = %d", c.connID)
}

Expand Down
37 changes: 0 additions & 37 deletions znet/msghandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@ package znet
import (
"encoding/hex"
"fmt"
"strconv"
"time"

"github.com/aceld/zinx/zmetrics"

"github.com/aceld/zinx/zconf"
"github.com/aceld/zinx/ziface"
"github.com/aceld/zinx/zlog"
Expand Down Expand Up @@ -115,17 +110,6 @@ func (mh *MsgHandle) SendMsgToTaskQueue(request ziface.IRequest) {
zlog.Ins().DebugF("SendMsgToTaskQueue-->%s", hex.EncodeToString(request.GetData()))
}

func (mh *MsgHandle) StatisticsMetrics(request ziface.IRequest, workerId int, msgId uint32, timeNow time.Time) {

conn := request.GetConnection()

// Increment the count of times the MsgID is scheduled for routing
zmetrics.Metrics().IncRouterSchedule(conn.LocalAddrString(), conn.GetName(), strconv.Itoa(workerId), strconv.Itoa(int(msgId)))

// Record the duration of the Router and MsgID business scheduling
zmetrics.Metrics().ObserveRouterScheduleDuration(conn.LocalAddrString(), conn.GetName(), strconv.Itoa(workerId), strconv.Itoa(int(msgId)), time.Since(timeNow))
}

// doFuncHandler handles functional requests (执行函数式请求)
func (mh *MsgHandle) doFuncHandler(request ziface.IFuncRequest, workerId int) {
defer func() {
Expand All @@ -146,11 +130,6 @@ func (mh *MsgHandle) doMsgHandler(request ziface.IRequest, workerID int) {
}
}()

var timeNow time.Time
if zmetrics.Metrics().IsEnable() {
timeNow = time.Now()
}

msgId := request.GetMsgID()
handler, ok := mh.Apis[msgId]

Expand All @@ -165,9 +144,6 @@ func (mh *MsgHandle) doMsgHandler(request ziface.IRequest, workerID int) {

// Execute the corresponding processing method
request.Call()

// Record the Router scheduling indicator data
mh.StatisticsMetrics(request, workerID, msgId, timeNow)
}

func (mh *MsgHandle) Execute(request ziface.IRequest) {
Expand Down Expand Up @@ -214,11 +190,6 @@ func (mh *MsgHandle) doMsgHandlerSlices(request ziface.IRequest, workerID int) {
}
}()

var timeNow time.Time
if zmetrics.Metrics().IsEnable() {
timeNow = time.Now()
}

msgId := request.GetMsgID()
handlers, ok := mh.RouterSlices.GetHandlers(msgId)
if !ok {
Expand All @@ -228,9 +199,6 @@ func (mh *MsgHandle) doMsgHandlerSlices(request ziface.IRequest, workerID int) {

request.BindRouterSlices(handlers)
request.RouterSlicesNext()

// Statistics the number of times a MsgID is dispatched by the router
mh.StatisticsMetrics(request, workerID, msgId, timeNow)
}

// StartOneWorker starts a worker workflow
Expand Down Expand Up @@ -259,11 +227,6 @@ func (mh *MsgHandle) StartOneWorker(workerID int, taskQueue chan ziface.IRequest
} else if zconf.GlobalObject.RouterSlicesMode {
mh.doMsgHandlerSlices(req, workerID)
}

// Metrics statistics. After each request is processed, the number of tasks processed by the current WorkId is increased by 1.
// (Metrics统计,每次处理完一个请求,当前WorkId处理的任务数量+1)
conn := request.GetConnection()
zmetrics.Metrics().IncTask(conn.LocalAddrString(), conn.GetName(), strconv.Itoa(workerID))
}
}
}
Expand Down
Loading

0 comments on commit 04599f5

Please sign in to comment.