sfs.getTaskScheduler().schedule not scheduling on time

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

Moderators: Lapo, Bax

snehil89
Posts: 21
Joined: 25 Sep 2014, 08:52

sfs.getTaskScheduler().schedule not scheduling on time

Postby snehil89 » 29 Nov 2021, 12:20

Hi ,

Sometimes its seen on prod that schedulers are not running on the specified time , on debugging it thoroughly, found through logs that the

Code: Select all

SmartFoxServer sfs = SmartFoxServer.getInstance();
       return sfs.getTaskScheduler().schedule(new SeatReservationExpireTask........
does not return for many seconds ; what could be the reason ? is it the load on scheduler threads ? I have configured 8 scheduler threads on 2.16.0 version which seems to be taking 7 % of the CPU time, each thread.


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

Re: sfs.getTaskScheduler().schedule not scheduling on time

Postby Lapo » 29 Nov 2021, 16:43

Hi,
are you running tasks that wait on external I/O such as database or HTTP calls and such?

Also keep in mind that uncaught exceptions inside the Runnable task will effectively stop it from running, if the task is supposed to be repeated. To avoid that you should catch exceptions inside the run() method.

Cheers
Lapo
--
gotoAndPlay()
...addicted to flash games
snehil89
Posts: 21
Joined: 25 Sep 2014, 08:52

Re: sfs.getTaskScheduler().schedule not scheduling on time

Postby snehil89 » 30 Nov 2021, 04:53

hi ,

are you running tasks that wait on external I/O such as database or HTTP calls and such?
I agree task itself will take time to execute/complete when there are long external calls.

what i meant to say is that the task scheduling should be done instantly whenever the instruction is given like

Code: Select all

SmartFoxServer sfs = SmartFoxServer.getInstance();
       return sfs.getTaskScheduler().schedule(new SeatReservationExpireTask........
, what could be the reason that the task-handle is not return immediately.
User avatar
Lapo
Site Admin
Posts: 22999
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: sfs.getTaskScheduler().schedule not scheduling on time

Postby Lapo » 30 Nov 2021, 08:35

Hi,
you didn't answer my question though, are these tasks that you're scheduling dependent on external I/O operations?

If yes, you have the answer to your problem. The scheduler borrows one thread from the pool for every Task to execute, and if the majority of tasks takes a relatively long time to complete the scheduler will eventually run out of threads and become laggy.

Cheers
Lapo

--

gotoAndPlay()

...addicted to flash games
snehil89
Posts: 21
Joined: 25 Sep 2014, 08:52

Re: sfs.getTaskScheduler().schedule not scheduling on time

Postby snehil89 » 30 Nov 2021, 11:49

you didn't answer my question though, are these tasks that you're scheduling dependent on external I/O operations?
Yes these tasks dependent on external calls. But I am curious about how does the submission of task causing a delay in returning a task-handle via the code that i mentioned above.
snehil89
Posts: 21
Joined: 25 Sep 2014, 08:52

Re: sfs.getTaskScheduler().schedule not scheduling on time

Postby snehil89 » 30 Nov 2021, 12:47

The scheduler borrows one thread from the pool for every Task to execute, and if the majority of tasks takes a relatively long time to complete the scheduler will eventually run out of threads and become laggy.
If the schedular is laggy will it not even submit any new tasks, i thought it utilizes a queue to hold tasks.
User avatar
Lapo
Site Admin
Posts: 22999
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: sfs.getTaskScheduler().schedule not scheduling on time

Postby Lapo » 01 Dec 2021, 07:31

snehil89 wrote:
you didn't answer my question though, are these tasks that you're scheduling dependent on external I/O operations?
Yes these tasks dependent on external calls. But I am curious about how does the submission of task causing a delay in returning a task-handle via the code that i mentioned above.

This is not very clear. Can you be more specific?
Returning a task handle is slow? That should not happen, because the schedule() and scheduleAtFixedRate() methods are non-blocking
Lapo

--

gotoAndPlay()

...addicted to flash games
User avatar
Lapo
Site Admin
Posts: 22999
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: sfs.getTaskScheduler().schedule not scheduling on time

Postby Lapo » 01 Dec 2021, 07:34

snehil89 wrote:
The scheduler borrows one thread from the pool for every Task to execute, and if the majority of tasks takes a relatively long time to complete the scheduler will eventually run out of threads and become laggy.
If the schedular is laggy will it not even submit any new tasks, i thought it utilizes a queue to hold tasks.

No, you can add more tasks while the threads are busy. The Scheduler cannot predict when the next thread will be available for work, it could take 1 millisecond or 1 minute. There's no reason to deny the task submission.

Since you already have said that Tasks are dependent on external I/O then the solution is to either optimize these calls so that they take less time to complete or fine tune the thread pool so that you don't end up with all threads busy at the same time.

Cheers
Lapo

--

gotoAndPlay()

...addicted to flash games

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 43 guests