Running out of background task threads?

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

Moderators: Lapo, Bax

noping
Posts: 27
Joined: 11 May 2020, 12:38

Running out of background task threads?

Postby noping » 09 Dec 2020, 22:54

Hi,

I have the following structure, each room (game) runs an extension (as SINGLE_INSTANCE) and each instance of the extension starts a task in the constructor to monitor game/status and perform certain actions as needed (i.e. kick player)

public MyServerExtention() {
SmartFoxServer sfs = SmartFoxServer.getInstance();
tr = new TaskRunner();
taskHandle = sfs.getTaskScheduler().scheduleAtFixedRate(tr, 0, 5, TimeUnit.SECONDS);
}

Now what happens is that at any given time, 20 (sometimes 19) tasks are triggered in the 5-second window, no more. I could have 70 rooms active, but only see the log entries for 19/20 entries. These 20 entries will repeat every 5 seconds (its not a random selection from the list of 70 active rooms).

The execution of each call should be very little, it just checks/sets a few parameters ( but I have not timed it )

I read somewhere there if this was limited by threads, more threads could be added, how so? is there a setting for this?

thanks
noping
Posts: 27
Joined: 11 May 2020, 12:38

Re: Running out of background task threads?

Postby noping » 10 Dec 2020, 05:35

Additional details,

checked at a later time, there are now 9 active tasks, even though there are ~30 active extenstions/rooms.
So it does not look like there is some limit of 20, it seems instead that a large portion of the tasks simply fail or do not run. For whatever reason.
User avatar
Lapo
Site Admin
Posts: 22999
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Running out of background task threads?

Postby Lapo » 10 Dec 2020, 10:06

Hi,
I would recommend making sure you're catching exceptions inside the run() method of your Tasks.
Otherwise, if an exception occurs, the Task will die.

Take a look at the example here:
https://smartfoxserver.com/blog/how-to- ... extension/

Let me know if it helps.
Lapo
--
gotoAndPlay()
...addicted to flash games
noping
Posts: 27
Joined: 11 May 2020, 12:38

Re: Running out of background task threads?

Postby noping » 10 Dec 2020, 14:02

this is what my run method looks like, I never catch any exceptions logs

Code: Select all

public void run() {
            try {
                Room theRoom = getParentExtension().getParentRoom();
                ManfeeExtension myEx = (ManfeeExtension) getParentExtension();

                //self cleanup
                if (myEx.extentionValid == false || (theRoom != null && theRoom.getPlayersList().size() == 0)) {
                    logExt("**TaskRunner: Room is invalid, quitting");
                    cleanup();
                    return;
                }

               // some logic goes here
               blah blah

            } catch (Exception e)
            {
                 logExt("**TaskRunner: exeption "+e.toString());
            }
}
User avatar
Lapo
Site Admin
Posts: 22999
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Running out of background task threads?

Postby Lapo » 10 Dec 2020, 15:16

The code you have posted looks correct, as it catches internal exceptions and therefore should not die for unexpected error conditions.
How exactly are you determining which Tasks work and which dont? Do you have debug logs?

Thanks
Lapo

--

gotoAndPlay()

...addicted to flash games
noping
Posts: 27
Joined: 11 May 2020, 12:38

Re: Running out of background task threads?

Postby noping » 10 Dec 2020, 15:37

Yes,

I have trace lines under the logic section. Again some portion of the rooms run fine. Could be timing/race condition in the initial call, perhaps I can add a delay when scheduling the task
noping
Posts: 27
Joined: 11 May 2020, 12:38

Re: Running out of background task threads?

Postby noping » 10 Dec 2020, 21:32

Update:

Issue resolved, added a few second delay scheduleAtFixedRate seems to have fixed it. Thanks, your input helped me focus on what could be causing the issue.

Return to “SFS2X Questions”

Who is online

Users browsing this forum: Google [Bot] and 38 guests