I was looking into a way to execute scheduled tasks. At first I thought about the native java Timer from java.util. However, some times later I found on this page that SFS recommends its own task scheduler.
I'm interested in knowing whether there is any significance difference between the two - are there any optimisation in the SFS scheduler; will that scale, etc.
Server tasks: Timer v. SFS scheduler
- Flying_Banana
- Posts: 42
- Joined: 04 May 2014, 07:03
Re: Server tasks: Timer v. SFS scheduler
Scheduler!
Timer is old and will not scale.
cheers
Timer is old and will not scale.
cheers
- Flying_Banana
- Posts: 42
- Joined: 04 May 2014, 07:03
Re: Server tasks: Timer v. SFS scheduler
I'm just wondering about how generous I should be dispatching new threads (timers).
For example, I can have a periodic thread called unit health regeneration that goes through all user controlled units every 10 seconds or so, and add health to them one by one. Or I can (preferably) have each unit create and manage its own scheduled future object when it gets damaged.
The former features a huge task with a lot of if-statements checking whether unit needs regeneration, the latter breaks that task down into fire-when-necessary bits, but I probably need to have about 100-500 threads running for it...
For example, I can have a periodic thread called unit health regeneration that goes through all user controlled units every 10 seconds or so, and add health to them one by one. Or I can (preferably) have each unit create and manage its own scheduled future object when it gets damaged.
The former features a huge task with a lot of if-statements checking whether unit needs regeneration, the latter breaks that task down into fire-when-necessary bits, but I probably need to have about 100-500 threads running for it...
Re: Server tasks: Timer v. SFS scheduler
Why so many threads?
Is the process blocking?
Is the process blocking?
- Flying_Banana
- Posts: 42
- Joined: 04 May 2014, 07:03
Re: Server tasks: Timer v. SFS scheduler
Not at all! But a unit timer has to fire every ten seconds until that unit's health is full! I mean the thread won't be doing much but it still takes a thread, right?
Re: Server tasks: Timer v. SFS scheduler
Then I am not sure why you need hundreds of those?
The thread in the Scheduler's thread pool executes and returns immediately so it's ready for a new task in a few microseconds, even less than that.
Thread pools can execute a lot of work with just a few threads.
The thread in the Scheduler's thread pool executes and returns immediately so it's ready for a new task in a few microseconds, even less than that.
Thread pools can execute a lot of work with just a few threads.
- Flying_Banana
- Posts: 42
- Joined: 04 May 2014, 07:03
Re: Server tasks: Timer v. SFS scheduler
Ahh great! I was thinking about the thread might be blocking while waiting.
Just curious, what would be the maximum number of threads you would recommend, if none of them are blocking? I realise this is a very vague question that depends on server and tasks executed, but I want to have a rough estimate on a typical server.
Just curious, what would be the maximum number of threads you would recommend, if none of them are blocking? I realise this is a very vague question that depends on server and tasks executed, but I want to have a rough estimate on a typical server.
Re: Server tasks: Timer v. SFS scheduler
With non blocking tasks (e.g no database or http calls) a setup with 3-6 threads is usually more than enough even for thousands of tasks.
- gabrielvpy
- Posts: 69
- Joined: 23 Jul 2015, 20:18
Re: Server tasks: Timer v. SFS scheduler
Excuse me. Can I ask how do I put a task in the Scheduler threadpool? I'm really lost here. I'm expanding the FPS demo and I need to implement a health regeneration every few seconds.
We made an awesome GPS - MOBA.
Try it out here: Get Fhacktions
Try it out here: Get Fhacktions
Re: Server tasks: Timer v. SFS scheduler
Look at the example here:
http://docs2x.smartfoxserver.com/Gettin ... wtos#item7
If there's anything unclear let us know
http://docs2x.smartfoxserver.com/Gettin ... wtos#item7
If there's anything unclear let us know
Who is online
Users browsing this forum: No registered users and 64 guests