Thousands of Scheduled Moving Caravans! How to optimize?

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

Moderators: Lapo, Bax

User avatar
Zenith
Posts: 55
Joined: 09 Oct 2017, 09:57

Thousands of Scheduled Moving Caravans! How to optimize?

Postby Zenith » 09 Oct 2017, 10:06

Hi,
We are developing an MMORTS.
Our use case is players each would be controlling a city and can mark their trade carts or armies to move at a path across other cities.

So imagine a player 'JOHN' can mark his caravan to move to and for between twenty cities .

Sicne each of the city is controlled by other player I want to have some approximate updates to caravan position so that each player of thsoe twenty cities can notice or get a notification about caravan currently arriving in his city, now is in his city and is now leaving the city.

Using MMOAPI I would need to periodically update position of caravan to next city say every 5 minutes. (5 minutes is time to go from one city to another , therefore total journey is more 100 minutes.)

Now I would be very thankful if you can suggest way to update position of caravan every 5 minutes. As this is a mmorts we need solution to be scalable once there are 100's 1000's of caravans .Eventually the journey times may scale upto multiple days.

What I thought?
I thought of making a table in db where I can list starting time of each caravan and then run a scheduled task every minute to check from that table
and update the positions of caravans which are listed in that table.
Will this be scalable and right approach?

I would be very thankful for any help regards. :? :? :?

Also if you are on this thread I am thinking of using a RDMS as database , do you have any opinion or suggestion with that?
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Thousands of Scheduled Moving Caravans! How to optimize?

Postby Lapo » 09 Oct 2017, 10:16

Hi,
a database could work but maybe it's not needed. You could keep the data in memory as well, unless it needs persistence.

Updating the position of the caravan should be a very simple operation, right? I suppose you will update its coordinates, and that's pretty much it. So, unless you're running a very complicated update logic, a single Scheduled Task can update 1000s of those without problems.

An alternative would be to run a Scheduler for each city so that each Scheduler manages the carts for that town. This would be okay if you're not planning to have 100s of cities.

Hope it helps
Lapo
--
gotoAndPlay()
...addicted to flash games
User avatar
Zenith
Posts: 55
Joined: 09 Oct 2017, 09:57

Re: Thousands of Scheduled Moving Caravans! How to optimize?

Postby Zenith » 09 Oct 2017, 18:13

Lapo wrote:Hi,
a database could work but maybe it's not needed. You could keep the data in memory as well, unless it needs persistence.

Updating the position of the caravan should be a very simple operation, right? I suppose you will update its coordinates, and that's pretty much it. So, unless you're running a very complicated update logic, a single Scheduled Task can update 1000s of those without problems.

An alternative would be to run a Scheduler for each city so that each Scheduler manages the carts for that town. This would be okay if you're not planning to have 100s of cities.

Hope it helps

Thanks for the reply. Yes I do need persistence reason being that as the time of journeys can extend upto days eventually so I would not want the caravans or armies be sent back to main city because of something going wrong on server end. If scheduler can update 1000's I would probably think of then a mixture of both techniques whereby will persist in DB once every 30 minutes maybe.

Also can you inform me of an estimated Jelastic server cost for say 100 CCU? Consider that I am running the database storage also in there , so include that in estimation if possible! The game is real-time but no people moving but people placing things which others can see mostly.

Thanks a lot!
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Thousands of Scheduled Moving Caravans! How to optimize?

Postby Lapo » 10 Oct 2017, 13:46

Hi,
Zenith wrote:Thanks for the reply. Yes I do need persistence reason being that as the time of journeys can extend upto days eventually so I would not want the caravans or armies be sent back to main city because of something going wrong on server end. If scheduler can update 1000's I would probably think of then a mixture of both techniques whereby will persist in DB once every 30 minutes maybe.

Sounds like a good idea.

Also can you inform me of an estimated Jelastic server cost for say 100 CCU? Consider that I am running the database storage also in there , so include that in estimation if possible! The game is real-time but no people moving but people placing things which others can see mostly.

Ah, the 64k dollars question... :D
Very difficult to say, to be honest. It depends on what your app does, how much traffic, packet frequency etc... etc... I could throw around some numbers but my guess would be as good as yours :)

Instead of using a crystal ball I'd rather run a few simulations. Even running something as basic as 10 clients in a local server can give you a rough idea of the traffic generated and from there you could extrapolate a ballpark figure for bandwidth etc...

A better approach would be to run a larger simulation with at least, say, 500 CCU and see how the server and network do. This is relatively easy to do either locally or directly in the cloud with a bunch of servers.
Here's an article that may help:
http://smartfoxserver.com/blog/building ... test-tool/
Lapo

--

gotoAndPlay()

...addicted to flash games
User avatar
Zenith
Posts: 55
Joined: 09 Oct 2017, 09:57

Re: Thousands of Scheduled Moving Caravans! How to optimize?

Postby Zenith » 10 Oct 2017, 21:07

Lapo wrote:Ah, the 64k dollars question... :D
Very difficult to say, to be honest. It depends on what your app does, how much traffic, packet frequency etc... etc... I could throw around some numbers but my guess would be as good as yours :)

Instead of using a crystal ball I'd rather run a few simulations. Even running something as basic as 10 clients in a local server can give you a rough idea of the traffic generated and from there you could extrapolate a ballpark figure for bandwidth etc...

A better approach would be to run a larger simulation with at least, say, 500 CCU and see how the server and network do. This is relatively easy to do either locally or directly in the cloud with a bunch of servers.
Here's an article that may help:
http://smartfoxserver.com/blog/building ... test-tool/


Thats very helpful . Thanks a lot!
Taking this further. How should the simple counter in game be managed serverside?
I mean say building gets built in 20 minutes, army trained in 20 seconds another army in 40 minutes.
Then this type of info for all the players!!
All these things will also be handled in the same manner? Do you think Clash Of Clans etc manage it that way?
Can there be any different approach you can suggest?
Assume that everyone is trying to cheat the game and we can't keep things client-side and afford cheating!
Last edited by Zenith on 10 Oct 2017, 21:20, edited 1 time in total.
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Thousands of Scheduled Moving Caravans! How to optimize?

Postby Lapo » 11 Oct 2017, 07:27

Zenith wrote:
Thats very helpful . Thanks a lot!
Taking this further. How should the simple counter in game be managed serverside?

You mean how to implement the timers?
Using multiple scheduled tasks. Example: when a client requests to create a new building you launch add a Task to the Scheduler that will go off after 20 minutes.

The Task object can be any class that implements the Runnable interface so you can store in the Task itself whatever data you need to send back to clients when the time comes.

Take a look at a few examples of scheduled tasks here:
http://smartfoxserver.com/blog/how-to-s ... extension/

I mean say building gets built in 20 minutes, army trained in 20 seconds another army in 40 minutes.
Then this type of info for all the players!!

With one call to send() from server side you can broadcast an event to any number of players.

Assume that everyone is trying to cheat the game and we can't keep things client-side and afford cheating!

I am not sure what you're asking here.
Generally speaking the client should as dumb a rock :) Meaning that you'd want all of your client's calls to be validated by the server prior to being executed and, of course, timers will run on the server side to avoid cheating as well.

Makes sense?
Lapo

--

gotoAndPlay()

...addicted to flash games
User avatar
Zenith
Posts: 55
Joined: 09 Oct 2017, 09:57

Re: Thousands of Scheduled Moving Caravans! How to optimize?

Postby Zenith » 11 Oct 2017, 08:42

Lapo wrote:
Zenith wrote:
I am not sure what you're asking here.
Generally speaking the client should as dumb a rock :) Meaning that you'd want all of your client's calls to be validated by the server prior to being executed and, of course, timers will run on the server side to avoid cheating as well.

Makes sense?


It does. So all timers are to be run on serverside. That's what I needed to confirm. Thanks.

Return to “SFS2X Questions”

Who is online

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