Method got delay around 1 sec for every user

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

Moderators: Lapo, Bax

foxie
Posts: 2
Joined: 02 Mar 2018, 02:54

Method got delay around 1 sec for every user

Postby foxie » 02 Mar 2018, 03:45

Hi guys, I'm new in SmartFoxServer and I'm try to connect to my SQL server.
The SFS2x version I use is 2.13.

I put the SFS2X on the server. The SFS2X server and DB server is on diff location.

Like the subject, there's a delay on the method I called.

The scenario is, when the player ready, the server check all the player data then update the data to database.
The delay is depends on how much the player on the room (max player is 6 for each room and the requirement is min 2 player ready to start the game). Let say there are 2 players ready, then it got delay for 1 second ( 1st player doesn't count), if 3 players ready then it got delayed for 2 second.

I didn't put any scheduler task and it is just a simple for looping.
Here's the loop code that I use :

Code: Select all

for (int userPos = 0; userPos < userList.size(); userPos++) {
         if (!userList.get(userPos).equals("")) {
            int userB = bList.get(userPos);
            String userName = userList.get(userPos);
            
            
            if (userB == -1 && userPos != 3) {
               userB = minB;
               sendToClient(userPos, userB);
            }
            
            updateData(userB, userName);
            
            
            bList.set(userPos, userB);
         }
      }
      


It got delayed when call updateData() on the next player. Inside updateData is just a simple Query declaration, then I called the executeUpdate() using IDBManager.

Is the SFS2X server waiting for return on executeUpdate() ? Or maybe waiting for something until the executeUpdate() success then running the next task?

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

Re: Method got delay around 1 sec for every user

Postby Lapo » 02 Mar 2018, 08:44

Hi and welcome.
Every call to the database is synchronous, meaning that your code will stop executing for as long as it takes for the database operation to complete.

This is why, normally, running a remote database is a problem. The problem being the added delay due to the slow communication over the network between SFS2X and the DB.

Usually we highly recommend to run the DB and SFS2X in the same local network, as it makes your life much simpler and it avoids performance bottlenecks. If this is not possible in your architecture then you need to work with the DB in asynchronous mode, meaning that you need to run DB operations in a different thread than your main code.

Fortunately Java makes it pretty easy to work with thread pools.
If you're entirely new to this I have to warn you that the learning curve is a bit steep... and I would still consider the possibility of putting the DB local to SFS2X, as it makes your life much simpler.

In any case here's a intro to the subject:
https://technology.amis.nl/2009/02/19/a ... lti-cores/

Hope it helps
Lapo
--
gotoAndPlay()
...addicted to flash games
foxie
Posts: 2
Joined: 02 Mar 2018, 02:54

Re: Method got delay around 1 sec for every user

Postby foxie » 06 Mar 2018, 02:58

Hi Lapo, thank you for yourhelp.
I already try it and it works, but since the game always need the newest data. I cant use that one.
But thank you. I really appreciate ur help :D

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 39 guests