I'm still working on the minimal multiplayer game to be run from the Racket web-server.
I have a few questions in the following big post, most of which is to establish context.
I'm hung up on the various forms of parallelism in Racket (and (I suppose) in javascript, although I'm not there yet).
I'm planning to maintain a single copy of game state in the Racket web-server. I don't (at present) plan to place it in permanent long-term storage, because I don't expect any of hese games to last long enough for crash-recovery to be relevant.
The players will be connecting from various machines across the internet, using various browsers, likely versions of firefox, chrome, chromium, edge, and maybe even internet explorer. They will probably be using different operating systems, likely Linux and Windows.
The players will also be using an out-of-band voice communications channel, likely jitsi or discord. At least I don't have to worry about that for now.
Everything went smoothly until I realised that for continual updating of relevant game state on the player machines I could not rely on http (or https) providing multiple responses to one request, repeatedly updating the game display as things changed. I would have to use a timer and make repeated update requests every second or so. With current browser technology, this requires client-side javascript, which I have asked about elsewhere. I'm not asking for advice on javascript now, though if anyone has any to offer, I won't mind reading it.
This is not a massively multiplayer game. I'll have enough hardware resources even if the server is a very old computer (which it is).
Here are the parallelisms I may need to worry about:
-
Processes running on completely separate computers, connected by http or https over the wider internet. (i.e., not just a LAN)
-
OS processes. (I hope I don't have to deal with these in the server. I'm not planning to use CGI scripts.)
-
OS threads, which may be on different CPU's within one OS process. Doesn't Racket have some way of talking about these?
-
Racket threads, running within in OS thread.
-
The form of parallelism involved in the web-server for incoming requests, which is likely one of 3) or 4).
-
And of course, parallelism within the client machines, regulated by javascript. Mentioned here for completeness, though it is not the subject of this posting.
I understand that when requests come in from client machines, they are processes in parallel. Which form of parallelism is this?
My conceptual model is to have the entire web server run in one OS process and to use Racket semaphores for mutual exclusion, thereby separating the incoming requests. So on the server, requests will come in, by serialised by waiting on a single semaphore, update the game state one at a time and respond by sending an appropriate response to the client's browser. I've already implemented cookies to tell players apart.
-
Are Racket semaphores the right tool for serialising incoming requests? Or are they operating on the wrong level(s) of parallelism?
-
Do multiple requests from the same browser instance create separate processes (of whatever layer?). If not, will semaphores fail to separate them? (Some semaphore implementations I've encountered won't let a process wait on itself.)
On the client side, (for now) I'll have mouse buttons for the various actions players can take. Each will make a request from the server and update the screen on receiving a response. Also on the client, I'll have some kind of timeout or timer-based loop to frequently request a screen update. Details to be decided after I look through more Javascript documentation. In the interim, I can have an extra button on the screen to explicitly request an update (essentially an explicit player request to do nothing in the game -- not very player-friendly, but it will enable the rest to be written and tested.). I may eventually have to worry about synchronising time-outs with explicit player requests, but that's a javascript problem for another day. In the server, these will all be serialised on that one semaphore.
-- hendrik