Commit 59c0e8ab authored by vicotor's avatar vicotor

add pprof

parent 0c26adba
......@@ -18,6 +18,8 @@ import (
"github.com/odysseus/service-registry/registry"
"github.com/redis/go-redis/v9"
log "github.com/sirupsen/logrus"
"net/http"
_ "net/http/pprof"
"strconv"
"strings"
"sync"
......@@ -95,6 +97,13 @@ func (n *Node) Start() error {
if n.reg != nil {
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()
}
......@@ -238,6 +247,7 @@ func (n *Node) Loop(idx int) {
l := log.WithField("task-id", task.TaskId)
l.WithField("task", task).Info("get task")
failed := make(map[string]bool)
t1 := time.Now()
for {
worker, err := n.poper.PopWorker(ctx, n.rdb, t, failed)
if err == types.ErrNoWorker || err == types.ErrTimeout {
......@@ -268,7 +278,7 @@ func (n *Node) Loop(idx int) {
failed[worker.Workerid] = true
continue
} else {
l.Info("dispatch task success")
l.WithField("timecost", time.Now().Sub(t1).Milliseconds()).Info("dispatch task success")
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