Browse Source

Switch `sync.Mutex` to `sync.RWMutex` in `publisher` for improved concurrent read performance.

main
mleku 4 months ago
parent
commit
9dec51cd40
No known key found for this signature in database
  1. 6
      app/publisher.go

6
app/publisher.go

@ -56,7 +56,7 @@ func (w *W) Type() (typeName string) { return Type }
type P struct { type P struct {
c context.Context c context.Context
// Mx is the mutex for the Map. // Mx is the mutex for the Map.
Mx sync.Mutex Mx sync.RWMutex
// Map is the map of subscribers and subscriptions from the websocket api. // Map is the map of subscribers and subscriptions from the websocket api.
Map Map
} }
@ -150,8 +150,8 @@ func (p *P) Receive(msg typer.T) {
// for unauthenticated users when events are privileged. // for unauthenticated users when events are privileged.
func (p *P) Deliver(ev *event.E) { func (p *P) Deliver(ev *event.E) {
var err error var err error
p.Mx.Lock() p.Mx.RLock()
defer p.Mx.Unlock() defer p.Mx.RUnlock()
log.D.C( log.D.C(
func() string { func() string {
return fmt.Sprintf( return fmt.Sprintf(

Loading…
Cancel
Save