Is one worker can only assigned to one player? #267
-
Awesome work!In your design document and the code of worker, it seems one worker can handler more than one user, and each user session will spawn a new room running a gaming emulator. But the following code make me confused, Is one worker can only assigned to one player? func (o *Server) WS(w http.ResponseWriter, r *http.Request) {
log.Println("Coordinator: A user is connecting...")
// ...
// Assign available worker to browserClient
bc.WorkerID = wc.WorkerID
wc.IsAvailable = false
// Everything is cool
// Attach to Server instance with sessionID
o.browserClients[sessionID] = bc
defer o.cleanBrowser(bc, sessionID)
// Routing browserClient message
o.RouteBrowser(bc)
bc.Send(cws.WSPacket{
ID: "init",
Data: createInitPackage(wc.StunTurnServer, o.library.GetAll()),
}, nil)
// If peerconnection is done (client.Done is signalled), we close peerconnection
<-bc.Done
// Notify worker to clean session
wc.Send(cws.WSPacket{
ID: "terminateSession",
SessionID: sessionID,
}, nil)
// WorkerClient become available again
wc.IsAvailable = true
} A worker will not release until the user session quit. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
This logic is checking if a new user joins an existing room, the worker handling that room will serve that user. If not, the user will pick among available server. I think you got confused by this line "wc.IsAvailable = false" and "wc.IsAvailable = true" at the end of peerconnection. It looks like a bug here, wc.IsAvailable can only set to true if there is no peerconnection assign to it. Thanks very much for pointing that out! |
Beta Was this translation helpful? Give feedback.
Hi @gegaojian-richard,
This logic is checking if a new user joins an existing room, the worker handling that room will serve that user. If not, the user will pick among available server.
I think you got confused by this line "wc.IsAvailable = false" and "wc.IsAvailable = true" at the end of peerconnection. It looks like a bug here, wc.IsAvailable can only set to true if there is no peerconnection assign to it.
Thanks very much for pointing that out!