diff options
author | Neil Alexander <neilalexander@users.noreply.github.com> | 2020-12-14 10:42:21 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-14 10:42:21 +0000 |
commit | f5869daaab2b8135415f4ae5b2d61ac8c3037a9d (patch) | |
tree | cac22f3c4191eae2e00cc4adfd54caa295495ead /roomserver | |
parent | d7824ed5b1b677ad5ea5fe84d1131a5d386b0c7e (diff) |
Don't start more goroutines than needed on RS input, increase input worker buffer size (#1638)
Diffstat (limited to 'roomserver')
-rw-r--r-- | roomserver/internal/input/input.go | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/roomserver/internal/input/input.go b/roomserver/internal/input/input.go index 2bed0c7f..6b833072 100644 --- a/roomserver/internal/input/input.go +++ b/roomserver/internal/input/input.go @@ -54,10 +54,8 @@ type inputWorker struct { input chan *inputTask } +// Guarded by a CAS on w.running func (w *inputWorker) start() { - if !w.running.CAS(false, true) { - return - } defer w.running.Store(false) for { select { @@ -142,7 +140,7 @@ func (r *Inputer) InputRoomEvents( // room - the channel will be quite small as it's just pointer types. w, _ := r.workers.LoadOrStore(roomID, &inputWorker{ r: r, - input: make(chan *inputTask, 10), + input: make(chan *inputTask, 32), }) worker := w.(*inputWorker) @@ -156,7 +154,9 @@ func (r *Inputer) InputRoomEvents( } // Send the task to the worker. - go worker.start() + if worker.running.CAS(false, true) { + go worker.start() + } worker.input <- tasks[i] } |