lijian пре 4 година
родитељ
комит
d0d773cdfa

+ 34 - 0
pkg/debug/pprof.go

@@ -0,0 +1,34 @@
+package debug
+
+import (
+	"log"
+	"net/http"
+	"net/http/pprof"
+	//"runtime/pprof"
+)
+
+type mode int
+
+const (
+	// ModeProd 生产模式
+	ModeProd mode = 1
+	// ModeDev 开发模式
+	ModeDev mode = 0
+)
+
+// Mode 运行模式
+var Mode = ModeDev
+
+// StartHTTPPprof
+func StartHTTPPprof(debugaddr string) {
+	debugServeMux := http.NewServeMux()
+	debugServeMux.Handle("/debug/pprof/", http.HandlerFunc(pprof.Index))
+	debugServeMux.Handle("/debug/pprof/cmdline", http.HandlerFunc(pprof.Cmdline))
+	debugServeMux.Handle("/debug/pprof/profile", http.HandlerFunc(pprof.Profile))
+	debugServeMux.Handle("/debug/pprof/symbol", http.HandlerFunc(pprof.Symbol))
+	debugServeMux.Handle("/debug/pprof/trace", http.HandlerFunc(pprof.Trace))
+	go func() {
+		log.Fatal(http.ListenAndServe(debugaddr, debugServeMux))
+	}()
+
+}

+ 1 - 1
pkg/ruleEngine/actor_system.go

@@ -154,7 +154,7 @@ func NewDefaultActorSystem(config *DefaultActorSystemConfig) *DefaultActorSystem
 	return &DefaultActorSystem{
 		dispatchers:  make(map[string]IDispatcher),
 		parentActors: make(map[string][]string),
-		scheduler:    grpool.New(config.SchedulerPoolSize),
+		// scheduler:    grpool.New(config.SchedulerPoolSize),
 		config:       config,
 		actors:       make(map[string]*MailBox),
 	}

+ 0 - 2
pkg/server/server.go

@@ -10,7 +10,6 @@ import (
 	"context"
 	"github.com/opentracing/opentracing-go"
 	"github.com/opentracing/opentracing-go/log"
-
 	// "github.com/vharitonsky/iniflags"
 	"flag"
 	"net/http"
@@ -42,7 +41,6 @@ func Init(name string) error {
 	if serverInstance == nil {
 		// read config
 		flag.Parse()
-
 		// read network info
 		readNetInterfaces()
 		// log

+ 3 - 5
services/controller/controller.go

@@ -182,9 +182,9 @@ func (c *Controller) initActorSystem() (*ActorSystem, error) {
 		TenantDispatcherPoolSize:     4,
 		RuleEngineDispatcherPoolSize: 4,
 	})
-	_ = system.CreateDispatcher(ruleEngine.APP_DISPATCHER_NAME, ruleEngine.NewPoolDispatcher(5))
-	_ = system.CreateDispatcher(ruleEngine.TENANT_DISPATCHER_NAME, ruleEngine.NewPoolDispatcher(4))
-	_ = system.CreateDispatcher(ruleEngine.RULE_DISPATCHER_NAME, ruleEngine.NewPoolDispatcher(4))
+	_ = system.CreateDispatcher(ruleEngine.APP_DISPATCHER_NAME, ruleEngine.NewPoolDispatcher(0))
+	_ = system.CreateDispatcher(ruleEngine.TENANT_DISPATCHER_NAME, ruleEngine.NewPoolDispatcher(0))
+	_ = system.CreateDispatcher(ruleEngine.RULE_DISPATCHER_NAME, ruleEngine.NewPoolDispatcher(0))
 
 	// init services
 	tenantService := &ruleEngine.TestTenantService{}
@@ -202,8 +202,6 @@ func (c *Controller) initActorSystem() (*ActorSystem, error) {
 	}
 	actorContext.AppActor = appActor
 	server.Log.Debugln("actor system initialized")
-	time.Sleep(time.Second * 1)
-	appActor.Tell(&ruleEngine.AppInitMsg{})
 	c.actorContext = actorContext
 	return &ActorSystem{rootActor: appActor}, nil
 }

+ 2 - 1
services/controller/main.go

@@ -1,6 +1,7 @@
 package main
 
 import (
+	"sparrow/pkg/debug"
 	"sparrow/pkg/rpcs"
 	"sparrow/pkg/server"
 )
@@ -12,7 +13,7 @@ func main() {
 		server.Log.Fatal(err)
 		return
 	}
-
+	debug.StartHTTPPprof("127.0.0.1:8999")
 	// register a rpc service
 	controller, err := NewController(*confRabbitHost)
 	if err != nil {