Delay to start the Scheduler task - SFS 2.13.7 Version

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

Moderators: Lapo, Bax

DigiTech
Posts: 1
Joined: 20 Jul 2022, 06:39

Delay to start the Scheduler task - SFS 2.13.7 Version

Postby DigiTech » 21 Jul 2022, 06:07

Hi,
Currently, we have an SFS 2.13.7 Version server in our system, and we are created more than 30 rooms (timer games) each room has a separate Scheduler task and keeps running with a one-sec delay. More than 100 players joined in the single room and place their bets, when the timer ended as '0' (Zero sec), we started each Scheduler task for a single player. fox example 100 players - 100 Scheduler tasks. Sometimes, the Scheduler task takes a 5 - 10 sec delay to execute the task. Can you give suggestions?

Code:

Code: Select all

Room Thread
-----------
ScheduledFuture<?> gameThread;

gameThread = SmartFoxServer.getInstance().getTaskScheduler().scheduleAtFixedRate(new gameRunner(), 0,1, TimeUnit.SECONDS);

private  class gameRunner implements Runnable {
      public void run() {
         try {
            switch(state) {
               case INITATEGAME      :    initateGame(); break;
               case START_PLAY         :   startPlay(); break;
               case WAIT_FOR_NEXT_GAME   :   nextRoundAction(); break;
               case STOP_THREAD      :   stopThread(); break;
               default:   break;   
            }
         } catch (Exception e) {
            logger.error("Room :: " + getParentRoom() + " Error :: " ,e);
         }
      }


   }
   private void initateGame() {
      // Code Development
      -- Change the state to START_PLAY
   }
   private void startPlay(){
    // call the player Thread here
    - Chante to  state to WAIT_FOR_NEXT_GAME
   }

   private void startPlay(){
    - Chante to  state to INITATEGAME
   }

   Note : suppose any issue in the above method, it will call the STOP_THREAD state

   private void stopThread() {
      if(gameThread!=null){
         gameThread.cancel(true);
      }
   }

Player Thread
-------------
SmartFoxServer.getInstance().getTaskScheduler().schedule(new PlayerGameRunner(user), 0,TimeUnit.MICROSECONDS);

private  class PlayerGameRunner implements Runnable {
      private User user1;
      ic PlayerGameRunner( User user) {
         this.user1 = user;
      }
      
      @Override
      public void run() {
         try {
            handleProcess(user1);
         } catch (Exception e) {
            logger.error("Room :: " + getParentRoom() + " Error :: " ,e);
         }
      }
      
      private void handleProcess(User user){
         Insert db records ( External db)
         Buy In service call (External Call)
      }
      
   }

Note : Please find the Thread pool Configuration
Attachments
Screen Shot 2022-07-21 at 10.44.47 AM.png
(96.14 KiB) Not downloaded yet
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Delay to start the Scheduler task - SFS 2.13.7 Version

Postby Lapo » 21 Jul 2022, 07:47

Hi,
we can't understand what might be going on because we can't see what your code does when changing states.

What I think it might be happening is that some of your Task code is taking a long time to execute and therefore it's blocking the thread it's running on. If this happens often the Scheduler will run out of threads to use (because they're all busy finishing whatever they're doing).

Can you briefly explain what happens in these Tasks? For example in your comments there's a "wait for next game" in the Task code. A Scheduled Task should never wait for something, unless it's for a few microseconds.

Thanks
Lapo
--
gotoAndPlay()
...addicted to flash games

Return to “SFS2X Questions”

Who is online

Users browsing this forum: Baidu [Spider] and 45 guests