First, let me give a brief description of the scenario. I am writing a simple game where almost all the work is done on the server side with a thin client for players to access it. The player registers or creates an account and can then interact with the game, moving around the grid. When they enter a cell, they must be informed of other players in that cell, and similarly, other players in this cell will be informed that this player is in it. There are many other interactions and actions that can take place, but you should not dwell on them in detail, since this is simply something more. When a player logs out, then returns or the server returns and returns, the entire state of the game must be preserved, although if the server crashes, it does not matter if I lose 10 minutes of changes.
I decided to use NHibernate and the SQLite database, so I read a lot in NHibernate, following the tutorials and writing some sample applications, and I donβt understand how I should do it!
I have a question: what is the best way to manage my sessions? Just from the small amount that I really understand, all these possibilities are jumping onto me:
- You have one session that is always open that all clients use
- Conduct a session for each client that connects and periodically cleans it.
- Open a session every time I have to use any existing objects and close it as soon as the update, insert, delete or request is complete.
- You have a session for each client, but keep it disconnected and only reconnect it when I need to use it.
- Same as above, but keep it connected and only disconnect it after a certain period of inactivity
- Keep entities aloof and attach them every 10 minutes, say, to commit changes.
What strategy should be used to get decent performance, given that there can be many updates, inserts, deletions and requests per second from maybe hundreds of clients at the same time, and all of them must be consistent with each other?
One more question: how to use transactions effectively? Is it good for each individual change to be in its own transaction, or will it work badly when I have hundreds of clients trying to change cells in the grid? Should I try to figure out how to combine similar updates together and place them in a single transaction, or will it be too complicated? Do I even need transactions for most of this?
c # database session nhibernate transactions
IRBMe
source share