Extensions - Why is Smartfox TaskScheduler starting slow?

Post here your questions about the Java client / Android API for SFS2X

Moderators: Lapo, Bax

Newfort_Kristof
Posts: 8
Joined: 31 Oct 2012, 14:24

Extensions - Why is Smartfox TaskScheduler starting slow?

Postby Newfort_Kristof » 20 May 2015, 11:00

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.
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Extensions - Why is Smartfox TaskScheduler starting slow

Postby Lapo » 20 May 2015, 14:27

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
Lapo
--
gotoAndPlay()
...addicted to flash games
Newfort_Kristof
Posts: 8
Joined: 31 Oct 2012, 14:24

Re: Extensions - Why is Smartfox TaskScheduler starting slow

Postby Newfort_Kristof » 21 May 2015, 07:01

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.
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Extensions - Why is Smartfox TaskScheduler starting slow

Postby Lapo » 21 May 2015, 09:04

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
Lapo

--

gotoAndPlay()

...addicted to flash games
Newfort_Kristof
Posts: 8
Joined: 31 Oct 2012, 14:24

Re: Extensions - Why is Smartfox TaskScheduler starting slow

Postby Newfort_Kristof » 22 May 2015, 09:06

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?
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Extensions - Why is Smartfox TaskScheduler starting slow

Postby Lapo » 22 May 2015, 09:53

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.
Lapo

--

gotoAndPlay()

...addicted to flash games

Return to “SFS2X Java / Android API”

Who is online

Users browsing this forum: No registered users and 15 guests