Page 1 of 1
Do Interval tasks run in their own thread?
Posted: 26 Jul 2006, 20:43
by NateDog
My understanding is the server is single-threaded.
Are intervals handled in the same single-threaded environment as user requests or do they run in a separate thread?
If in a separate thread, does each interval run in its own thread or do all intervals share a single thread?
Thanks in advance.
Posted: 27 Jul 2006, 04:53
by Lapo
My understanding is the server is single-threaded.
No, it's multi threaded, but it does not use the one-thread-per-client model.
With the default configuration the server should use 10 threads
Are intervals handled in the same single-threaded environment as user requests or do they run in a separate thread?
Each interval is a separate thread
If in a separate thread, does each interval run in its own thread or do all intervals share a single thread?
Each interval is a separate thread
Intervals from a java extension
Posted: 27 Jul 2006, 10:06
by elmo
hi Lapo,
what is the syntax to use Intervals from a java extension?
thank you for your help,
best regards,
elmo
Posted: 27 Jul 2006, 10:13
by Lapo
The syntax is shown in our documentation under "setInterval"
... and
PLEASE! DO RESIZE THAT AVATAR!

Posted: 27 Jul 2006, 10:21
by elmo
sorry,
i have no problem with Actionscript version, but I cannot find the java version of it,
maybe I'm looking the wrong place, i cannot find java doc about intervals
still searching...
elmo
Posted: 27 Jul 2006, 14:32
by Lapo
Intervals are not available in Java like they are in actionscript.
The reason is simple... in Java you can use a Timer or a Thread, so there's no need to wrap such classes into another class that does just the same
Hope it helps

Posted: 27 Jul 2006, 14:35
by elmo
thank you

Posted: 27 Jul 2006, 19:42
by jflowers45
Lapo -
I'm a little confused. I had read your response to NateDog's earlier questions about threading here
http://www.gotoandplay.it/_forums/viewtopic.php?t=2291
and they *seem* to conflict with the answer you just gave. Mainly we're worried about whether we need to avoid race conditions. Can you elaborate?
The reason we started wondering about this is that we are having a problem in our game where users are seeing other users' inventories instead of their own while being logged in, and we can't figure out how it's happening. It doesn't happen too often but it hasn't been a one time thing either.
Thanks!
Posted: 28 Jul 2006, 06:33
by Lapo
and they *seem* to conflict with the answer you just gave.
mmm... no they don't
He asked about the general architecture of the server and I explained that, by default, the custom extensions run in a single thread.
Of course if you do add threads by running intervals or java timers/threads you will have to pay attention to possible race conditions.
The reason we started wondering about this is that we are having a problem in our game where users are seeing other users' inventories instead of their own while being logged in,
I don't know ... this seems a problem with some wrong user id that leads to reading the wrong data
Posted: 28 Jul 2006, 10:40
by NateDog
Here's our understanding ...
1) I understand that the intervals will each run in a separate thread.
2) Since our game is written as a custom extension, it runs in a single thread.
So I'm not clear then what the setting in the config file controls. Does it limit the overall number threads for all intervals and extensions for the entire server?
Posted: 28 Jul 2006, 13:36
by Lapo
1) I understand that the intervals will each run in a separate thread.
Correct
2) Since our game is written as a custom extension, it runs in a single thread.
I will try to be more precise here. I went back to the code to review a couple of aspects of the server architecture.
All the requests handled in the handleRequest() method are executed by the same thread, while the events are dispatched by another thread.
If you're using Actionscript this shouldn't give you problems. If you're writing extensions in Java you will probably have to synchronize shared resources. (collections, files etc...)
Hope it helps
Posted: 28 Jul 2006, 19:58
by jflowers45
You mentioned that by default the server was set to 10 threads ... where does one change this setting? I looked in config.xml and found the OutQueueThreads variable but that appears to be set to 1 by default
Posted: 02 Aug 2006, 07:35
by Lapo
Many of the threads used internally are private and can't be modified from outside (acceptor thread, reader thread, disconnector thread etc...)
You can however add more threads to the "Socker Writer stage" which is backed by a thread pool, by default set to 1.
You should also understand that running many concurrent threads in a JVM adds some overhead to the execution due to the thread switching.
We usually recommend to alter the number of threads only in particular cases, for example when using multi-cpu machines (quad CPU or more)
You can read more in chapter 2.2. of our docs
Posted: 09 Aug 2007, 13:42
by vtween
Hi Lapo,
I'm writing a multi user game where about 20 users in the same room compete over a single resource (a Frisbee) - Ultimate Frisbee if you are familiar with the game.
I'm using a Java room extension and handleRequest method.
Sorry for nagging, but I want be be 100% sure.
Will all user requests arriving to the extension be handled serially in the order of their arrival?
Are no sych locks required?
Doesn't it affect the extension performance in a high traffic env?
If a room is created on the fly and uses the same extension class does it share the same instance of the extension more rooms that deploy this extension?
Thanks