Commit 59c0e8ab authored by vicotor's avatar vicotor

add pprof

parent 0c26adba
...@@ -18,6 +18,8 @@ import ( ...@@ -18,6 +18,8 @@ import (
"github.com/odysseus/service-registry/registry" "github.com/odysseus/service-registry/registry"
"github.com/redis/go-redis/v9" "github.com/redis/go-redis/v9"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"net/http"
_ "net/http/pprof"
"strconv" "strconv"
"strings" "strings"
"sync" "sync"
...@@ -95,6 +97,13 @@ func (n *Node) Start() error { ...@@ -95,6 +97,13 @@ func (n *Node) Start() error {
if n.reg != nil { if n.reg != nil {
go n.reg.Start() go n.reg.Start()
} }
// start pprof
go func() {
err := http.ListenAndServe("0.0.0.0:6060", nil)
if err != nil {
log.WithError(err).Error("pprof failed")
}
}()
return n.startAllTask() return n.startAllTask()
} }
...@@ -238,6 +247,7 @@ func (n *Node) Loop(idx int) { ...@@ -238,6 +247,7 @@ func (n *Node) Loop(idx int) {
l := log.WithField("task-id", task.TaskId) l := log.WithField("task-id", task.TaskId)
l.WithField("task", task).Info("get task") l.WithField("task", task).Info("get task")
failed := make(map[string]bool) failed := make(map[string]bool)
t1 := time.Now()
for { for {
worker, err := n.poper.PopWorker(ctx, n.rdb, t, failed) worker, err := n.poper.PopWorker(ctx, n.rdb, t, failed)
if err == types.ErrNoWorker || err == types.ErrTimeout { if err == types.ErrNoWorker || err == types.ErrTimeout {
...@@ -268,7 +278,7 @@ func (n *Node) Loop(idx int) { ...@@ -268,7 +278,7 @@ func (n *Node) Loop(idx int) {
failed[worker.Workerid] = true failed[worker.Workerid] = true
continue continue
} else { } else {
l.Info("dispatch task success") l.WithField("timecost", time.Now().Sub(t1).Milliseconds()).Info("dispatch task success")
break break
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment