Do Interval tasks run in their own thread?

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

Moderators: Lapo, Bax

Post Reply
NateDog
Posts: 52
Joined: 26 Jun 2006, 13:25

Do Interval tasks run in their own thread?

Post 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.
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Post 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
Lapo
--
gotoAndPlay()
...addicted to flash games
elmo
Posts: 9
Joined: 16 Jun 2006, 12:13

Intervals from a java extension

Post by elmo »

hi Lapo,

what is the syntax to use Intervals from a java extension? :shock:

thank you for your help,

best regards,

elmo
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Post by Lapo »

The syntax is shown in our documentation under "setInterval"

... and PLEASE! DO RESIZE THAT AVATAR! :shock: :)
Lapo
--
gotoAndPlay()
...addicted to flash games
elmo
Posts: 9
Joined: 16 Jun 2006, 12:13

Post 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
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Post 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 :)
Lapo
--
gotoAndPlay()
...addicted to flash games
elmo
Posts: 9
Joined: 16 Jun 2006, 12:13

Post by elmo »

thank you :D
jflowers45
Posts: 63
Joined: 11 Jul 2006, 20:52

Post 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!
How you doin?
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Post 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
Lapo
--
gotoAndPlay()
...addicted to flash games
NateDog
Posts: 52
Joined: 26 Jun 2006, 13:25

Post 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?
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Post 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
Lapo
--
gotoAndPlay()
...addicted to flash games
jflowers45
Posts: 63
Joined: 11 Jul 2006, 20:52

Post 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
How you doin?
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Post 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
Lapo
--
gotoAndPlay()
...addicted to flash games
vtween
Posts: 36
Joined: 26 Jul 2007, 17:31

Post 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
Post Reply