Prechádzať zdrojové kódy

网关修改分配比较方案

lxg 3 rokov pred
rodič
commit
56b828534d
2 zmenil súbory, kde vykonal 2 pridanie a 27 odobranie
  1. 1 26
      gateway/gateway.go
  2. 1 1
      service.go

+ 1 - 26
gateway/gateway.go

@@ -8,8 +8,6 @@ import (
 	"net"
 	"sync"
 	"time"
-
-	"git.nspix.com/golang/micro/stats"
 )
 
 const (
@@ -19,9 +17,6 @@ const (
 var (
 	ErrShortFeature  = errors.New("short feature")
 	ErrFeatureExists = errors.New("feature already exists")
-
-	requestCounter     = stats.NewCounter("GatewayRequestCount", "Number of gateway request")
-	requestDropCounter = stats.NewCountersWithSingleLabel("GatewayRequestDropedCount", "Number of dropped by unusual request", "Reason")
 )
 
 type (
@@ -79,46 +74,26 @@ func (g *Gateway) process(conn net.Conn) {
 	var (
 		n       int
 		err     error
-		missing uint8
 		feature = make([]byte, MinFeatureLength)
 	)
-	if g.enableStats {
-		requestCounter.Add(1)
-	}
 	//set deadline
 	if err = conn.SetReadDeadline(time.Now().Add(time.Second)); err != nil {
-		if g.enableStats {
-			requestDropCounter.Add("ERROR", 1)
-		}
 		return
 	}
 	if n, err = io.ReadFull(conn, feature); err != nil {
-		if g.enableStats {
-			requestDropCounter.Add("EOF", 1)
-		}
 		_ = conn.Close()
 		return
 	}
 	//reset deadline
 	if err = conn.SetReadDeadline(time.Time{}); err != nil {
-		if g.enableStats {
-			requestDropCounter.Add("ERROR", 1)
-		}
 		return
 	}
-	missing = 1
 	for _, l := range g.listeners {
-		if bytes.Equal(feature[:n], l.feature[:n]) {
+		if bytes.Compare(feature[:n], l.feature[:n]) == 0 {
 			l.l.Receive(wrapConn(conn, feature[:n]))
-			missing = 0
 			break
 		}
 	}
-	if missing == 1 {
-		if g.enableStats {
-			requestDropCounter.Add("MISSING", 1)
-		}
-	}
 }
 
 func (g *Gateway) worker(ctx context.Context) {

+ 1 - 1
service.go

@@ -318,7 +318,7 @@ func (svr *Service) startHTTPServe() (err error) {
 		svr.httpSvr.Handle("GET", "/healthy", func(ctx *http.Context) (err error) {
 			return ctx.Success(map[string]interface{}{
 				"id":      svr.node.ID,
-				"healthy": "healthy",
+				"healthy": "Healthy",
 				"uptime":  time.Now().Sub(svr.upTime).String(),
 			})
 		})