Turn based game player timeout

Post here your questions about SFS2X. Here we discuss all server-side matters. For client API questions see the dedicated forums.

Moderators: Lapo, Bax

manosint
Posts: 6
Joined: 24 May 2009, 06:42

Turn based game player timeout

Postby manosint » 20 Feb 2011, 05:45

In my turn based game, I want each player, when it is his turn, to have a timeout to play.
What is the best way to implement it?

A scheduler in each room? (possible many rooms?)
A scheduler which run every second to loop every room for timeout checking? (many runs)
A timer at the client side? (the logic is at the client? The client sends timeout message to the server?)

Is there other better solution?

Thank you.
tchen
Posts: 191
Joined: 11 Dec 2010, 14:14

Postby tchen » 20 Feb 2011, 13:57

This might have been what you mean, but just to be clear...

Use the master SmartFoxServer.getTaskScheduler with multiple runnables one per room. This way, you leverage the same thread pool and it doesn't matter how many rooms you have.
manosint
Posts: 6
Joined: 24 May 2009, 06:42

Postby manosint » 22 Feb 2011, 04:59

Thank you, for your replay,

but the smartfoxserver documentation says:

"It's also advisable to avoid spawning very large thread pools (50+ threads) unless there are specific reasons for doing so. A setting of 1-4 threads is usually sufficient to handle any number of concurrent delayed events....."
tchen
Posts: 191
Joined: 11 Dec 2010, 14:14

Postby tchen » 22 Feb 2011, 07:09

Indeed. Runnable tasks do not however get their own thread. They're executed as their delays are triggered. During which time, they occupy one of the threads in the pool. Once they're done, they are taken off that thread, and another takes its place.

The documentation refers to resizeThreadPool, where you can adjust the number of threads the pool has. As it says, normally 1-4 threads is more than enough and avoids penalty from excessive context switching.

It is possible to saturate all threads if you have too many long-duration events. In which case, you should break them up OR increase the number of threads. But this is rare, and you should probably use another thread pool for those types of tasks if encountered.
manosint
Posts: 6
Joined: 24 May 2009, 06:42

Postby manosint » 23 Feb 2011, 19:25

Ok, thank you

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 53 guests