Browse Source

WIP performance and load related updates

gek/new-load-tests
Gabe Kangas 5 years ago
parent
commit
b0f9465138
  1. 14
      core/chat/server.go

14
core/chat/server.go

@ -2,6 +2,7 @@ package chat @@ -2,6 +2,7 @@ package chat
import (
"encoding/json"
"fmt"
"net/http"
"sync"
"time"
@ -71,6 +72,7 @@ func (s *Server) Run() { @@ -71,6 +72,7 @@ func (s *Server) Run() {
}
case message := <-s.inbound:
fmt.Println("inbound...")
s.eventReceived(message)
}
}
@ -214,14 +216,22 @@ func (s *Server) Broadcast(payload events.EventPayload) error { @@ -214,14 +216,22 @@ func (s *Server) Broadcast(payload events.EventPayload) error {
return err
}
go func() {
s.mu.Lock()
defer s.mu.Unlock()
defer func() {
if a := recover(); a != nil {
fmt.Println("RECOVER", a)
}
}()
for _, client := range s.clients {
if client == nil {
continue
}
if client.send != nil {
select {
case client.send <- data:
default:
@ -229,6 +239,8 @@ func (s *Server) Broadcast(payload events.EventPayload) error { @@ -229,6 +239,8 @@ func (s *Server) Broadcast(payload events.EventPayload) error {
delete(s.clients, client.id)
}
}
}
}()
return nil
}
@ -241,7 +253,9 @@ func (s *Server) Send(payload events.EventPayload, client *Client) { @@ -241,7 +253,9 @@ func (s *Server) Send(payload events.EventPayload, client *Client) {
return
}
if client.send != nil {
client.send <- data
}
}
// DisconnectUser will forcefully disconnect all clients belonging to a user by ID.

Loading…
Cancel
Save