B4J Question How to best structure a web server

LucaMs

Expert
Licensed User
Longtime User
Very complicated question, sorry :(

New Year, good intentions: structure well my sw.

I developed a web server that works decently (though I did not carry out performance tests), but I would like to structure it better.

Obvious premise, speed is important.There is the need to determine where to perform the routines (in which threads).
There is a difference between the behavior of handler classes and static code modules.

When you use CallSubDelayed to call a handler class then the sub will run on the thread that owns this specific class instance. When you use CallSubDelayed to call a sub in a static code module it will run on the main thread.

Using CallSub is the same as calling the sub directly. It will run on the same thread.

Note that you can use Server.CurrentThreadIndex to get the thread number.



Currently, I have established that a websocket handler class ("wshUser", with its websocket) is a user. Then I have a class clsGameRoom in which there is a Map containing wshUser objects. I guess (hope) that I have executed the calls to the various routines in the right way to get the most speed.

For a better structure, and given that some users may enter a chat, even privately, rather than get into a game room, I'm thinking maybe it's better if:

have objects: clsUser, clsPlayer, clsGameRoom, clsChatRoom, ... and use the handler class wshUser (renamed) only as an object of "general communication", as if it were a physical object, inserted into clsUser.

Do you see possible bottlenecks?
Have you developed something like this?

[Obviously I did not really want to think, as usual :D]


Thank you
 
Top