Skip to content

Commit

Permalink
[feature] log worker startup counts (#2958)
Browse files Browse the repository at this point in the history
* log number of each worker kinds started, and log when stopped

* remove worker debug logging

* whoops, fix the count of media workers
  • Loading branch information
NyaaaWhatsUpDoc authored Jun 3, 2024
1 parent 6ed6824 commit f17dd62
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 10 deletions.
3 changes: 0 additions & 3 deletions internal/transport/delivery/delivery.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"codeberg.org/gruf/go-structr"
"github.com/superseriousbusiness/gotosocial/internal/gtscontext"
"github.com/superseriousbusiness/gotosocial/internal/httpclient"
"github.com/superseriousbusiness/gotosocial/internal/log"
"github.com/superseriousbusiness/gotosocial/internal/queue"
"github.com/superseriousbusiness/gotosocial/internal/util"
)
Expand Down Expand Up @@ -181,8 +180,6 @@ func (w *Worker) run(ctx context.Context) {
if w.Client == nil || w.Queue == nil {
panic("not yet initialized")
}
log.Debugf(ctx, "%p: starting worker", w)
defer log.Debugf(ctx, "%p: stopped worker", w)
util.Must(func() { w.process(ctx) })
}

Expand Down
2 changes: 0 additions & 2 deletions internal/workers/worker_msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,6 @@ func (w *MsgWorker[T]) run(ctx context.Context) {
if w.Process == nil || w.Queue == nil {
panic("not yet initialized")
}
log.Debugf(ctx, "%p: starting worker", w)
defer log.Debugf(ctx, "%p: stopped worker", w)
util.Must(func() { w.process(ctx) })
}

Expand Down
39 changes: 34 additions & 5 deletions internal/workers/workers.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"runtime"

"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/log"
"github.com/superseriousbusiness/gotosocial/internal/messages"
"github.com/superseriousbusiness/gotosocial/internal/scheduler"
"github.com/superseriousbusiness/gotosocial/internal/transport/delivery"
Expand Down Expand Up @@ -59,26 +60,54 @@ type Workers struct {
// StartScheduler starts the job scheduler.
func (w *Workers) StartScheduler() {
_ = w.Scheduler.Start() // false = already running
log.Info(nil, "started scheduler")
}

// Start will start contained worker pools.
func (w *Workers) Start() {
var n int

maxprocs := runtime.GOMAXPROCS(0)
w.Delivery.Start(deliveryWorkers(maxprocs))
w.Client.Start(4 * maxprocs)
w.Federator.Start(4 * maxprocs)
w.Dereference.Start(4 * maxprocs)
w.Media.Start(8 * maxprocs)

n = deliveryWorkers(maxprocs)
w.Delivery.Start(n)
log.Infof(nil, "started %d delivery workers", n)

n = 4 * maxprocs
w.Client.Start(n)
log.Infof(nil, "started %d client workers", n)

n = 4 * maxprocs
w.Federator.Start(n)
log.Infof(nil, "started %d federator workers", n)

n = 4 * maxprocs
w.Dereference.Start(n)
log.Infof(nil, "started %d dereference workers", n)

n = 8 * maxprocs
w.Media.Start(n)
log.Infof(nil, "started %d media workers", n)
}

// Stop will stop all of the contained worker pools (and global scheduler).
func (w *Workers) Stop() {
_ = w.Scheduler.Stop() // false = not running

w.Delivery.Stop()
log.Info(nil, "stopped delivery workers")

w.Client.Stop()
log.Info(nil, "stopped client workers")

w.Federator.Stop()
log.Info(nil, "stopped federator workers")

w.Dereference.Stop()
log.Info(nil, "stopped dereference workers")

w.Media.Stop()
log.Info(nil, "stopped media workers")
}

// nocopy when embedded will signal linter to
Expand Down

0 comments on commit f17dd62

Please sign in to comment.