Proxying Smartfox connections using Nginx/HAProxy

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

Moderators: Lapo, Bax

pratts
Posts: 34
Joined: 23 Aug 2016, 17:46

Proxying Smartfox connections using Nginx/HAProxy

Postby pratts » 05 Jun 2018, 09:04

Hello,

We are trying to work on a condition where if one of our server is out, then we can redirect our smartfox server traffic to another server.
We are planning to use a proxy server for our HTTP requests. We have even found out that nginx/haproxy supports https://www.nginx.com/blog/websocket-nginx/.
What we want is to transfer the entire smartfox traffic to another server. Is it possible using proxying (using multiple smartfox servers) ? Our current only supports one smartfox and we are planning to keep it that way. We want more than 1 smartfox server to run on passive mode. When main server gets blown/down, we want to migrate traffic to another server automatically.

Can you please help with some insights is this is possible and any opinions on the effectiveness of the solution ?
User avatar
Lapo
Site Admin
Posts: 23026
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Proxying Smartfox connections using Nginx/HAProxy

Postby Lapo » 05 Jun 2018, 13:21

Hi,
What we want is to transfer the entire smartfox traffic to another server. Is it possible using proxying (using multiple smartfox servers) ?


No, at least not like you would do for HTTP clients.
SmartFoxServer uses persistent connections, so connections cannot be "moved". In an active/passive scenario if the active dies the passive can take over but most of the runtime state is lost because it was running on the other machine.

Similarly if a proxy sits between client and server you would still loose the server side state, unless you maintain the state in an external central server. But this complicates things substantially, as a distributed state involves lots of performance headaches and complex architectures.

Hope it helps
Lapo
--
gotoAndPlay()
...addicted to flash games
pratts
Posts: 34
Joined: 23 Aug 2016, 17:46

Re: Proxying Smartfox connections using Nginx/HAProxy

Postby pratts » 06 Jun 2018, 11:10

Thank you for the response.

We are trying to create a strategy to recover from a disaster, i.e. disaster recovery. We know that clients will be disconnected and new connections will be made to the new server once the traffic is migrated to it.

We are trying to figure out a strategy to restored the games from a certain checkpoint (to be decided, probably before game starts) when disaster occurs.

Can you please provide any strategy/use cases/materials you know that might be helpful to us to achieve the goal of recovering from a disaster ?
User avatar
Lapo
Site Admin
Posts: 23026
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Proxying Smartfox connections using Nginx/HAProxy

Postby Lapo » 06 Jun 2018, 14:04

We are trying to figure out a strategy to restored the games from a certain checkpoint (to be decided, probably before game starts) when disaster occurs.

If you can periodically store the state of the game on a DB you should be able to restart it from the point it was stopped.
Of course certain type of games are more better fits for this approach than others (i.e. turn based as opposed to realtime)

An alternative is to run a distributed, in-memory datastore, such as Hazelcast and similar. It's kind of equivalent to running a DB but it can be faster if you opt for the in-memory feature, and it can also store data on disk for extra safety.
It's also convenient because you can directly store your Java objects to the DB, instead of converting them to SQL.

The idea would be to keep the game state local to SFS2X and a copy onto the distributed cache/memory. Then, if disaster ensues, the new servers can take over and hopefully continue from where things were interrupted.

We wrote a detailed white paper on this subject here:
http://docs2x.smartfoxserver.com/Overview/white-papers

Second to last PDF.

Hope it helps
Lapo

--

gotoAndPlay()

...addicted to flash games

Return to “SFS2X Questions”

Who is online

Users browsing this forum: Baidu [Spider], Ronaldniff and 68 guests