Is the server's OnOperationRequest asynchronous?

drawmaster77
edited January 2012 in Photon Server
Hi, Is the server's OnOperationRequest asynchronous? So whenever new OnOperationRequest arrives it will run on a separate thread if another OnOperationRequest arrived earlier and is still running?

I am pretty sure it is, but I just need to make sure, so I can arrange my other code accordingly.

Comments

  • dreamora
    dreamora
    edited January 2012
    They are fiber driven and as such async, yes.
    If they end on different threads or not is not defined, they could end on the same. That depends on the load and the order in which the fibers get executed (you can have many many more fiber than threads used to process them which is normally configured to be 4 I think. A new thread for every user would be completely nonscaleable)
    But that should not matter if they are on the same thread or not as you don't work with threading there or at least I wouldn't. The code is written to allow you easy and non troublesome parallelization as long as you don't try to communicate with other fiber through other means than messaging, if you want to keep it performant
  • The correct answer is: Yes and No.
    The server makes use of Fibers. Each of those runs in a separate thread (from a pool) but per fiber, there is a queue of actions to be done. This is used for operations.
    Incoming operations are executed in order and one-by-one in each peer and in each room that's associated.
    This means you have to keep peers separated from each other and rooms, too. But you don't have to worry that more than one operation is done at any time in a single room or peer.
    Communication between each of those classes must be done via message or require explicit locking (which you should avoid).

    I hope this helps.
  • ok I think I am missing something here.

    Ive looked into PoolFiber.cs code on web, its just queueing up actions to be executed in order right?

    So if I got 2 peers in the same room are their actions queued up on that room's fiber, so that I wouldn't have to worry to sync that stuff manually?

    But if I have 2 peers in different rooms, is that when I use messages to sync?

    Also what do you mean by messages (is there an example somewhere I can look)? Is it just event or smth?

    Also while at it, I have a DB server I send/receive data from, how do I syncronize these requests with room's fiber? i.e. is that also to be done with messages?

    Thanks & sorry for noob questions.
  • > its just queueing up actions to be executed in order right?
    Yep.
    > So if I got 2 peers in the same room are their actions queued up on that room's fiber, so that I wouldn't have to worry to sync that stuff manually?
    Exactly.
    > But if I have 2 peers in different rooms, is that when I use messages to sync?
    Yes.

    Two rooms should interact by passing messages, as should players. If players are in a room, they pass their operations there and this gets them in-order. If another room wants to pass data, it must enqueue this, too, or lock. The latter is tricky.

    It's best to look at the code in Lite. Opening LitePeer.HandleGameOperation. Follow to Room.EnqueueOperation() and there the fiber is used.

    We defined to separate methods that are commonly called through the fiber: ExecuteOperation and ProcessMessage. You put a call to either method into the room's fiber and it's called when the previously enqueued calls are done. A message is just something you can pass to ProcessMessage into a room (something that's not an operation).
    In principle a operation could also be passed on as IMessage with a type being "operation".
  • ok I think I figured this out thatnks.