Efficient use of JGN and JME


Currently I'm designing a game that will use networking. However I'm at a crossroad how to effectively implement JGN and JME.

Im setting up a client side and a server side. The idea is that for each 2 clients that connect a game starts. So as example, you'll have 5 game instances running when 10 clients connect. Now I've tested this and running 5 headless game instances (with physics and a JGNServer for each instance) is pretty heavy for the CPU. I'm thinking that the game instance and JGNServer are the heaviest power consumers. As a sidenote, I'm letting the server side calculate the physics to reduce load on the client side and because I want the server to be authoritive on all spatials. This also adds for better validation checks. The server then synchronizes the objects with the clients.

So I've been thinking and wondered if it could be done more efficient.

A solution that came to mind was to keep track of each game instance (registering and keeping track of them) thus reducing the amount of JGNServer's to just 1. Since a JGNServer can handle 32K players I reckoned using it for only 2 is a waste of overhead and resources. A second solution that came to mind was letting multiple games be rendered in one instance rather than having an instance per game. In example that would mean that player 1 till 8 are assigned the same game instance (but would still play their own game) while the next 8 players get a new game instance. Each player would then only render the necessaries required to play the game with their opponent. However a problem that rises with this is the synchronization. I couldn't find a way to register spatials to a selected clients (e.a. spatial object 1 is only registered to client 3 and 4 while spatial object 2 is only registered to client 5 and 6). The clientsynchronizer would always complain that it cannot find a spatial. A solution to this would be to let all clients register all spatials and only render those that matter but that would unnecessary increase traffic.

Basically what I wish to know is what would be a good way to handle this kind of situation and if my solutions are valid for the problems. Also, im doubting if the JGNServer is really -that- heavy and brings alot of overhead. If someone could answer these 3 questions I'd be help me a lot! :slight_smile:

Thanks in advance 

If JGNServer adds any noticeable weight to your application something is wrong.  JGN is meant to be extremely light-weight and efficient.  In most cases it should run hundreds of messages a second through and never even show a hit on the CPU at all.  I would suggest that the physics are probably your biggest drain (that's my biggest problem I've been encountering in my own development).

However, for the sake of the questions asked I will say you can run multiple JGNServers in a single thread (ex. JGN.createThread(server1, server2, server3, server4).start();), you can create a single JGNServer that separates between clients connected (multiple instances of SynchronizationManager), and you can even have the JGNServer be updated in your games thread itself so you never even break away from the single-threaded model if you so desire.

The threading functionality of JGN is meant to be completely thread-safe, but imposes no restrictions or even any comprehension on what you can/should do when you thread it…or even if you thread it.

I expected that JGNServer wasn't really the cause. Thanks for confirming it. Your post gave me a new insight in JGN.

Supposedly the headless instance and the overhead it brings to initialize -is- the cause. I would be interested to see how you, seeing you're one of the most active gamedev's in this community, would approach this obstacle, just for the sake of someone hopefully looking at it from a different perspective.

Say for instance you have your space-sim where 2 players can have a deathmatch. Now you could start a server game and let the clients connect. The "server game" handles physics, scoring, hits etc. Having 2 or 3 more "server games" running, tremendously slows down the entire (physical) server while this resuls in only being able to serve 4 or 6 players. Would you agree with me that this is inefficient use of a jME (+jme physics) implementation? Implying that it could do much more updates?

And secondly how you approach this scenario?

Thanks! :slight_smile:

Well, using something like StandardGame in headless mode, and specifying a fixed framerate (this will keep it from starving other threads) and running your JGN server in another thread and simply having multiple VM instances per client is probably the best approach.  Yes, you're actually wasting a bit of resources by having multiple VMs instead of one, but it shouldn't be too bad if you've got a pretty powerful machine it should be able to run several instances at a time particularly if you've just got two players per instance.  When an instance is not being used you should probably lock() the game thread so it's not wasting resources and just have the networking thread running waiting for connections.

I know you were looking for something more profound, but in the realm of programming, simplicity rules. :wink: