Best server side game loop method

FlipFlop
edited February 2012 in Photon Server
Hi

I'm wondering what the best approach to having a server side game loop in a room is.

I want to be able to have as many rooms as possible (at least 50)

Right now I have a ThreadFiber per room that runs an action that calls Update and then sleeps (40-updateTime) ms. This works ok but has some trouble with Operations executing concurrently with Update(). I believe I have the relevant parts in locks but dispose is still a bit annoying.

I've been considering adding an UpdateGame message and then doing the Game update from ProcessMessage.

There's many ways I can think of but if anyone can tell me what the way is I'd like to hear it :)

- Hans-Henrik

Comments

  • the correct way is not have an update but schedule message in the future again, that way everything will work fine and in the correct order, requires no locks and scales significantly better than what you are trying to do.

    Loops are definitely nothing to touch if you want to scale and 'sleeping' of threads is killing the server as you do not only sleep the fiber but one of the X threads of the thread pool (default is 2 - 4, so you likely kill 25-50% performance)
  • IFiber's Schedule(action, ms) doesn't put the action in the queue when the time is up does it ?

    I guess I can just have the action do that.

    - FlipFlop
  • Schedule also uses the Fiber, so no need to schedule a action to queue a message.