I want to figure out why the TaskScheduler of Smartfox is starting up slower then if I use my own scheduler with ScheduledExecutorService.
I use scheduleAtFixedRate to do something every 2 seconds.
When I use Smartfox TaskScheduler, it runs my runnable for the first time after a few seconds @ startup.
Normaly I should see logs poping up every 2 seconds, but it doesn't until after a minute or more after the first one.
Than It shows all the remaining logs he should have shown in just a few milliseconds.
From then on, it pops every 2 seconds. Seems like he has troubles starting up his tasks or that there are a lot of other tasks preventing my task from firing correctly at startup.
When I use ScheduledExecutorService (= Executors.newScheduledThreadPool(1)) as mentioned, It starts perfectly at startup.
But, is it safe enough to use or should I stay with the Smartfox TaskScheduler? And why? I use SFS2X 2.9.3 (for Unity WebGL), but it is something previous versions had too.
Thanks in advance.
Extensions - Why is Smartfox TaskScheduler starting slow?
-
- Posts: 8
- Joined: 31 Oct 2012, 14:24
Re: Extensions - Why is Smartfox TaskScheduler starting slow
Hi,
I have no idea
I have a simple test Extension that uses the SFS internal scheduler and it works just fine, running exactly every 2 seconds and with no delay.
If I schedule it in the init() it starts right after the relative Zone initialization. If I schedule it in the SERVER_READY event it synchronizes with the server startup.
I am wondering if there's other stuff going on in your code that might cause this, although it's difficult to imagine how this could happen.
More details would be welcome.
Cheers
I have no idea
I have a simple test Extension that uses the SFS internal scheduler and it works just fine, running exactly every 2 seconds and with no delay.
If I schedule it in the init() it starts right after the relative Zone initialization. If I schedule it in the SERVER_READY event it synchronizes with the server startup.
I am wondering if there's other stuff going on in your code that might cause this, although it's difficult to imagine how this could happen.
More details would be welcome.
Cheers
-
- Posts: 8
- Joined: 31 Oct 2012, 14:24
Re: Extensions - Why is Smartfox TaskScheduler starting slow
Hi Lapo, Sure!
I have like +- 20 zones, 2 of them have about 20-30 rooms at startup. If you join those last 2, they also use runnables. But nobody was joining them at the moment.
In that specific zone (ZoneExtension), I do following in the init:
- I initialize that class with a static method: MyRefresher.Initialize(this.wsClient); (this.wsClient = new WebServiceClientImpl(this))
- Then start the runnable class with another static method: MyRefresher.StartUpdater(refreshTime, canActivate, parentExtension);
- In that start method I do following:
* myRunnable = new MyRunnable(delay, parentExtension);
* myTasks.scheduleAtFixedRate(myRunnable , 0, delay, TimeUnit.MILLISECONDS);
- And the run method just sends a method to every use in that zone (every 2 seconds): ...sendExtensionResponse(commandName,params, player, player.getLastJoinedRoom(),false)
Hope this helps.
I have like +- 20 zones, 2 of them have about 20-30 rooms at startup. If you join those last 2, they also use runnables. But nobody was joining them at the moment.
In that specific zone (ZoneExtension), I do following in the init:
- I initialize that class with a static method: MyRefresher.Initialize(this.wsClient); (this.wsClient = new WebServiceClientImpl(this))
- Then start the runnable class with another static method: MyRefresher.StartUpdater(refreshTime, canActivate, parentExtension);
- In that start method I do following:
* myRunnable = new MyRunnable(delay, parentExtension);
* myTasks.scheduleAtFixedRate(myRunnable , 0, delay, TimeUnit.MILLISECONDS);
- And the run method just sends a method to every use in that zone (every 2 seconds): ...sendExtensionResponse(commandName,params, player, player.getLastJoinedRoom(),false)
Hope this helps.
Re: Extensions - Why is Smartfox TaskScheduler starting slow
Well, if you are invoking external webservices it may explain something.
You should take a closer look at how much time does it take to initialize those. Typically HTTP calls are blocking so the current thread will be held until the external call is completed.
As an experiment, try removing any web-service initialization in your startup code and see the difference.
Cheers
You should take a closer look at how much time does it take to initialize those. Typically HTTP calls are blocking so the current thread will be held until the external call is completed.
As an experiment, try removing any web-service initialization in your startup code and see the difference.
Cheers
-
- Posts: 8
- Joined: 31 Oct 2012, 14:24
Re: Extensions - Why is Smartfox TaskScheduler starting slow
Ok thanks, I'll see if I find some time to try that.
It's really busy now.
But just another question: Is it a BAD idea to use ScheduledExecutorService like I mentioned instead of the taskscheduler of Smartfox?
It's really busy now.
But just another question: Is it a BAD idea to use ScheduledExecutorService like I mentioned instead of the taskscheduler of Smartfox?
Re: Extensions - Why is Smartfox TaskScheduler starting slow
No, the SFS Scheduler is based on the same class
We just make it simpler for users, since the JDK executors can be intimidating for beginners.
We just make it simpler for users, since the JDK executors can be intimidating for beginners.
Return to “SFS2X Java / Android API”
Who is online
Users browsing this forum: No registered users and 32 guests