|Welcome to the Monastery|
Re^5: How to share complex data structure in threads ?by BrowserUk (Pope)
|on Dec 30, 2012 at 17:53 UTC||Need Help??|
So, whenever a player is connected, a new thread created, while everyone will access the same world map.
Hm. If you have any ambition that your game will support more than a few tens of concurrent players, then I agree with anonymonk, 1 thread per player is the wrong way to go. Imagine your game became moderately popular and you have 1000 players on line at a time. 1000 threads all sitting there consuming memory doing essentially nothing waiting for their user to type something. You'd need a machine with huge memory; but the processing could be done by a 386 class cpu and it would still be mostly idle.Now think about how you would scale that to 10,000 players. You'd need 10 times as much memory but still not much more cpu.
Equally, using an in-memory database would be very dangerous. One errant piece of code or a faulty power supply and bang! your game -- ie. your database -- is gone.
If you are serious about developing this, you need to seriously reconsider your architecture. Your game will need to reside in the database, and the database will need to be resilient and scale. You will need (to allow for) multiple comms servers talking to your player clients; and redundant, resilient, actively distributed database server back ends (or a cluster of machines accessing a distributed filesystem like hadoop).
Even if you want to start small on a single machine, you should separate the comms components and database components of the game and run them as separate processes on that machine and have them communicate through the database/distributed filesystem ONLY. Thus, when and if you need more capacity, you can separate the comms onto a different machine from the DB/game handling. And then if things grow larger, you can increase the number of comms servers and DB servers independently of each other to match your growing requirements.
With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.