Thread Count keeps increasing

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

Moderators: Lapo, Bax

nandan
Posts: 11
Joined: 08 Jul 2012, 07:04

Thread Count keeps increasing

Postby nandan » 08 Jul 2012, 07:52

Hi,

I am making a turn based multi-player game with some fixed rooms and some dynamic rooms. I also create, around 20 max, NPCs, which are created and disconnected dynamically in room extension. When I start the server the thread count is as low as 40 and within 17 - 18 hrs with the peak of 36 users it shoots up to 600+. [The active thread list shows a lot of threads named pool-n-thread-1] I do not know what is happening, I am quite new to java and smartfoxserver. Please help.

Thanks in advance.

Nandan
User avatar
rjgtav
Posts: 2813
Joined: 19 Apr 2009, 11:31
Location: Lisbon, Portugal

Re: Thread Count keeps increasing

Postby rjgtav » 08 Jul 2012, 12:12

Hi.
Are you using anything Timer related on your code? Please make sure that you use the TaskScheduler that comes with SFS2X (more information here).
And you might also consider using a global Task that iterates through every room instead of having one task for every room.
Skills: SFS Pro, SFS2X, AS2.0/AS3.0, Java, HTML5/CSS3/JS, C#
Portfolio: https://rjgtav.wordpress.com/
SFS Tutorials: http://sfs-tutor.blogspot.com/ - Discontinued. Some examples may be bugged.
nandan
Posts: 11
Joined: 08 Jul 2012, 07:04

Re: Thread Count keeps increasing

Postby nandan » 08 Jul 2012, 14:59

Yes I am using TaskScheduler that comes with SFS2x at room level, that is restarted for each turn, is that a bad idea? How do I use global task, please help.
User avatar
rjgtav
Posts: 2813
Joined: 19 Apr 2009, 11:31
Location: Lisbon, Portugal

Re: Thread Count keeps increasing

Postby rjgtav » 08 Jul 2012, 15:09

Well, by a global Task I mean a task that runs at the Zone-Level, which has a local list of the rooms that will be iterated in each run.
If you're using this for a turn based, the best way would be to run the global task every second and reduce a time variable by 1 every run. Then, when that variable reaches 0, you execute the necessary code.
Skills: SFS Pro, SFS2X, AS2.0/AS3.0, Java, HTML5/CSS3/JS, C#
Portfolio: https://rjgtav.wordpress.com/
SFS Tutorials: http://sfs-tutor.blogspot.com/ - Discontinued. Some examples may be bugged.
nandan
Posts: 11
Joined: 08 Jul 2012, 07:04

Re: Thread Count keeps increasing

Postby nandan » 08 Jul 2012, 15:40

Got it :idea: . Thanks so much. :)
bbranislav
Posts: 81
Joined: 13 Sep 2011, 15:59
Location: Nitra, Slovakia
Contact:

Re: Thread Count keeps increasing

Postby bbranislav » 08 Jul 2012, 16:30

Hi rjgtav, I have around 500 rooms in Zone (those are game rooms with 2 users), by your mind I need one instance of scheduleAtFixedRate in that zone extension and this one scheduleAtFixedRate will be call every second and on each time this class will be update 500 room's variables ??? Every second changed 500 room's variables???
User avatar
rjgtav
Posts: 2813
Joined: 19 Apr 2009, 11:31
Location: Lisbon, Portugal

Re: Thread Count keeps increasing

Postby rjgtav » 08 Jul 2012, 16:55

Hi.
I forgot to mention that this "time" variabe is a hidden roomVariable, so it won't send any updates to any client. You can also use the room.getProperty() and room.setProperties() methods instead.
Skills: SFS Pro, SFS2X, AS2.0/AS3.0, Java, HTML5/CSS3/JS, C#
Portfolio: https://rjgtav.wordpress.com/
SFS Tutorials: http://sfs-tutor.blogspot.com/ - Discontinued. Some examples may be bugged.
bbranislav
Posts: 81
Joined: 13 Sep 2011, 15:59
Location: Nitra, Slovakia
Contact:

Re: Thread Count keeps increasing

Postby bbranislav » 09 Jul 2012, 12:27

Thank you rjgtav, plaese tell me about resizeThreadPool.
Is there some dependencies how to set resizeThreadPool ?

Branislav Belohorec
nandan
Posts: 11
Joined: 08 Jul 2012, 07:04

Re: Thread Count keeps increasing

Postby nandan » 10 Jul 2012, 13:13

Hi rjgtav,

I now have a global task that runs every second at zone level and I iterate through all my rooms (the list can increase to any limit in future) to execute a set of statements to update the game state. How do I ensure that every room is updated at the precise instance of time? Should I write some event listener at room level and zone extension should dispatch a message every second for room extension to handle states. Please help.

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

Re: Thread Count keeps increasing

Postby Lapo » 10 Jul 2012, 15:37

How do I ensure that every room is updated at the precise instance of time?

I don't fully understand your question.
The scheduler will fire an event every 1 second, so it will be precisely every second :)
Of course if the process of updating all rooms takes more than one second the next update will be handled by another thread (if the pool has more than one) and etc...
Of course it is unlikely that the process will take so long unless you are executing a very complex server side logic.
Lapo
--
gotoAndPlay()
...addicted to flash games
nandan
Posts: 11
Joined: 08 Jul 2012, 07:04

Re: Thread Count keeps increasing

Postby nandan » 11 Jul 2012, 01:33

Thanks so much Lapo for your reply, so you are saying that no matter how many rooms will I have in future, if I iterate through them and update their states it will all happen precisely within the same second without any delay. If it does take a little longer then I will have to resize the thread pool on fly, am I correct? And I assume the the number I must resize the thread pool to will again depend on the time my updates are taking.

Also, I got slightly confused after seeing this post viewtopic.php?t=10185, which says -
Use the master SmartFoxServer.getTaskScheduler with multiple runnables one per room.

This was what I was doing previously when I got into the continuously increasing thread count problem. I now have just one global scheduler at zone level. Please tell me that whatever I am doing right now is better.

Thanks a ton!
nandan
Posts: 11
Joined: 08 Jul 2012, 07:04

Re: Thread Count keeps increasing

Postby nandan » 11 Jul 2012, 15:08

Anyone, please reply.
bbranislav
Posts: 81
Joined: 13 Sep 2011, 15:59
Location: Nitra, Slovakia
Contact:

Re: Thread Count keeps increasing

Postby bbranislav » 11 Jul 2012, 15:34

My idea is using one scheduler on zone level, which will be iterate all rooms in zone every second. In this iteration it will be change room property (contain round seconds) decrement with number 1 and if the room property equal 0, scheduler update room variable (this variable detect end of game or round time is over) and it fire onRoomVariableUpade server event and onRoomVariableUpade function and here I use game logic like store data in DB , changing user variables (set new amout of score or whatever) . I think it can help to hold thread size.
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Thread Count keeps increasing

Postby Lapo » 12 Jul 2012, 07:31

Don't update the DB every second, store the changes in the game for longer time and then, once in a while, you store those changes.
It could be too onerous to hit the DB every second and it will require a larger thread pool to keep up with the tasks. Instead you can use a separate task that runs every 2-3 minutes to update the DB
Lapo

--

gotoAndPlay()

...addicted to flash games
bbranislav
Posts: 81
Joined: 13 Sep 2011, 15:59
Location: Nitra, Slovakia
Contact:

Re: Thread Count keeps increasing

Postby bbranislav » 13 Jul 2012, 09:23

Thank you Lapo, is possible to write custom message into smarfox.log via extension ?

BB

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 39 guests