Limiting Room List (and asynchronous responses)

Post here your questions about Actionscript and Java server side extensions development.

Moderators: Lapo, Bax

User avatar
alexgenaud
Posts: 13
Joined: 05 Oct 2009, 12:57
Location: Copenhagen, DK
Contact:

Limiting Room List (and asynchronous responses)

Postby alexgenaud » 14 Dec 2009, 12:43

Older related thread: http://smartfoxserver.com/forums/viewtopic.php?t=6242

Hi,

We have potentially thousands of rooms, but only five room types. We want to reduce the amount of XML Room List data we send to all users. We also want to give the users the impression of a small community (and predictable return-to-same-room experience).

Our solution is to add users to one of many 'room dimensions', which are smaller collections of users and rooms. The client always requests to switch rooms by calling an extension. The extension places the user in a room.

However, in some cases, we need to switch the user into a different dimension. In this case, the extension returns a new XML room list (sendGenericMessage) before calling ExtensionHelper.joinRoom.

We know that SFS/OpenSpace complains if the user is added to a room which is not in the client's room list. For this reason, many of the operations are performed by the client from a limbo room (id=1).

Question: Our server uses a large number of concurrent threads, however sendGenericMessage and ExtensionHelper.joinRoom are called in sequence in a single thread. Are they guaranteed to go onto a single MessageQueue in order and be received by the client in the same order? In other words, can we be guaranteed that the XML room list is received by the client before OpenSpace learns that the user's room has been changed?

Cheers,
Alex
User avatar
Lapo
Site Admin
Posts: 23027
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Limiting Room List (and asynchronous responses)

Postby Lapo » 16 Dec 2009, 09:25

Hi,
alexgenaud wrote:Question: Our server uses a large number of concurrent threads, however sendGenericMessage and ExtensionHelper.joinRoom are called in sequence in a single thread. Are they guaranteed to go onto a single MessageQueue in order and be received by the client in the same order? In other words, can we be guaranteed that the XML room list is received by the client before OpenSpace learns that the user's room has been changed?

Can you better explain the "large number of concurrent threads"?
What's your setting for SysHandlerThreads and ExtHandlerThreads?

Thanks
Lapo
--
gotoAndPlay()
...addicted to flash games
User avatar
alexgenaud
Posts: 13
Joined: 05 Oct 2009, 12:57
Location: Copenhagen, DK
Contact:

FIFO queue

Postby alexgenaud » 16 Dec 2009, 18:30

Hi Lapo,

We've got at least 8 cores per machine. We plan to bump the Extension threads to about a dozen threads.

In addition, our application spins quite a number of threads. We have a few scheduled tasks, potentially sixty-four parallel threads accessing database partitions (shards), and who knows what else.

I think to summarize my question: is there exactly ONE outgoing message queue? Regardless of the number of working threads, are messages sent (to a single user on a single socket connection) in the same order the messages were put on the outgoing queue?

Cheers,
Alex
User avatar
Lapo
Site Admin
Posts: 23027
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 17 Dec 2009, 10:03

The out-of-order problem is usually very unlikely but when working with many threads it is not completely impossible.

First of all the outgoing queue is single and does not represent the problem. The problem lies one step before, when threads are running concurrently and adding outgoing messages to the queue.

Here is a scenario where out-of-order messages could happen.
Suppose you have a client firing 3 different requests to the server one after another, very quickly. Let's call them request A, B and C.

Suppose that A returns a simple flag, B requires a database call and C is another quick one. Since you are running many threads each request might be executed concurrently but it is likely that requests A and C will be executed much quicker than request B, where the running thread has to wait for some data from the database.

In this scenario it is possible that the responses will get in the Outgoing Queue in this order: A, C, B

Is this bad? It depends.
If those request depend one each other it will be a problem because when you get Response C you should have already received Response B first.

BUT...

In the very specific case in which you need A,B and C to be processed sequentially you wouldn't have worked the way I've just described. You would have instead sent each request separately waiting for the relative server response and then proceed with the next one until you are done. So at the end of the day, this is a non-problem.

On the other hand if you don't care about order because the requests are unrelated between each others you would be able to fire them simultaneously and then wait for each server Response.

Hope it helps
Lapo

--

gotoAndPlay()

...addicted to flash games
User avatar
alexgenaud
Posts: 13
Joined: 05 Oct 2009, 12:57
Location: Copenhagen, DK
Contact:

Postby alexgenaud » 17 Dec 2009, 14:50

Hi Lapo,

In my case, there is only request A. But request A generates 2 responses (one sendGenericMessage (XML roomlist) followed by sendResponse (STR protocol)). I can guarantee that sendGenericMessage is called before sendResponse (same thread). I just wanted to know if the Queue and socket guarantees that the client will receive those messages in that order (XML first followed by STR).

It sounds as though the order IS guaranteed. Thanks,
Alex

Return to “Server Side Extension Development”

Who is online

Users browsing this forum: No registered users and 36 guests