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
Running out of background task threads?
Re: Running out of background task threads?
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.
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.
Re: Running out of background task threads?
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.
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.
Re: Running out of background task threads?
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());
}
}
Re: Running out of background task threads?
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
How exactly are you determining which Tasks work and which dont? Do you have debug logs?
Thanks
Re: Running out of background task threads?
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
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
Re: Running out of background task threads?
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.
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.
Who is online
Users browsing this forum: No registered users and 45 guests