I think you should write everything to run in the main thread. Then, when all the logic is more or less complete, you should benchmark the parts that you think will cause the performance bottlenecks. Once you've identified those parts, you can run them off the main thread using the Threading library.
Thank you for your answer,
@Roycefer.
I know where the bottlenecks can be (also, I have to study a method to test).
1) the game room manager; it seems to become a "server instance". I'll try to explain this better below.
2) db queries
Don't use the Threading library unless you are convinced that all other solutions will be too slow. Especially not in a server solution as each connection is already handled by a different thread.
Thank you,
@Erel
Right. I will have an additional thread for each Room, which should contain 3/6 users/players, each one with its thread (websocket).
Unfortunately, I do not know in advance how many users will be. There are card games that have millions of downloads; assuming 400,000 users have your app, is it reasonable to assume that will be 1,000 users simultaneously connected? So about 1,222 threads (1,000 + (average of 3/6 players per room) * 1,000)
The "correct" solution depends on the specific requirements. If your app needs to interact with databases then use async queries (which are handled by a pool of threads).
Handle DB async queries is hard (at least for me
). Moreover, I have to understand, since I will need a "game room manager" which should "handle" those queries and... and I have to study this solution
Unfortunately, I explain badly and you do not have time.
I thought my game server can work as the Chatroom web server example (except, unfortunately, my server will not use web pages but b4a clients only).
The Chatroom web server example has one room only; this room is handled by the ChatShared code module, which we can consider as the "game room handler" or "game engine", the fulcrum. If ChatShared was a class, I could have many ChatShared instances, then many rooms.
Am I wrong thinking so? Thinking to ChatShared (GameRoom, in my case) as the "game engine"?
How would you add other (variable number) rooms to Chatroom web server? This could/should be the solution, I think, but I don't know how, given that ChatShared is a code module. [Obviously, my problem is not change a code module to a class].
Thanks again for your answers.