Autoscaling on EC2 Instances

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

Moderators: Lapo, Bax

redquest
Posts: 6
Joined: 10 May 2020, 14:46

Autoscaling on EC2 Instances

Postby redquest » 10 May 2020, 14:51

In our current setup Smartfox and Webserver is inside a single AWS EC2 instance and when concurrent users increase we're facing sever downtimes.
So we want to attach a load balancer to this and setup a auto scaling group. In this case what is the right way of set up?
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Autoscaling on EC2 Instances

Postby Lapo » 10 May 2020, 16:19

Hi,
when you say "Webserver" you mean the embedded http server in SFS2X? Or are you talking about another web-server that is running on the same machine?

If it's the former adding a load balancer is not recommended as many of the functions it performs are dependent on the SFS2X instance it is attached to. (Encryption, websocket, BlueBox/HTTP tunneling)

Thanks
Lapo
--
gotoAndPlay()
...addicted to flash games
redquest
Posts: 6
Joined: 10 May 2020, 14:46

Re: Autoscaling on EC2 Instances

Postby redquest » 02 Jun 2020, 10:54

Hi,

Sorry for the late reply.

So my application is in Unity and its powered by PHP back-end and the Game-play is handled by SFS2X.

Currently the Apache Server & SFS2x server is running from a same EC2 instance in AWS and this is causing me troubles during Traffic Spike.
Currently I'm doing vertical scaling of my instance to handle load and now I want to configure horizontal scaling of the same by setting up a Load Balancer & Auto Scaling.

Is this a right approach or do I have to split Webserver (Apache) & SFS2X to different Servers?
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Autoscaling on EC2 Instances

Postby Lapo » 02 Jun 2020, 16:06

The apache web server and SFS2X scale very differently.
Where Apache may struggle with a couple hundreds active connections, SFS2X will be able to handle thousands of player without issues, so they need to be decoupled and scaled with different strategies.

I would recommend the http load balancing solution only for the web server. For SFS2X it's much easier to just scale vertically. An 8 core
machine should be able to handle pretty high loads, and if your game becomes very very popular you can still move to a bigger machine.

Granted, at some point you may need to split the load on SFS2X and maybe run multiple instances, but this is something you should consider when your game is already running 10s of thousands of CCU at all hours of the day. However you should approach this one step at a time.

Also, keep in mind that our 100K stress test (which is documented in our white papers section of the documentation) was done on a single dedicated machine with 10 cores.

Hope it helps
Lapo

--

gotoAndPlay()

...addicted to flash games
redquest
Posts: 6
Joined: 10 May 2020, 14:46

Re: Autoscaling on EC2 Instances

Postby redquest » 03 Jun 2020, 05:47

Thanks you for the reply. :D

I will decouple SFS & Apache and will put SFS on Vertical & Apache on Horizontal Scaling.
redquest
Posts: 6
Joined: 10 May 2020, 14:46

Re: Autoscaling on EC2 Instances

Postby redquest » 29 Jun 2020, 13:02

Hi,

We're still struggling with this Load Balancer Issue. As per you direction we have decoupled the Apache and Smartfox Server. These are the steps i followed:

1) Deployed 2 AWS servers in the same subnet
2) We have our PHP application in server 1 and SFS in server 2
3) We are using a load balancer to route the traffic accordingly. The traffic route is done via load-balancer listener rules.When the traffic is coming to 8443, we sending it to Server 2.
4) We are using the same domain (www.example.com) to access the application and sfs
aplication : www.example.com:80/443
sfs : www.example.com:8443
5) With this setup, we are not able to access sfs (www.example.com:8443)
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Autoscaling on EC2 Instances

Postby Lapo » 29 Jun 2020, 14:59

Isn't it just an issue with load balancing rules?
You said that the LB has a rule to send all the incoming traffic directed at port 8443 to Server2. If this is set up correctly all traffic towards port 8443 should indeed go to SFS2X's own http server.

Are you sure the LB is set up correctly?
Lapo

--

gotoAndPlay()

...addicted to flash games
redquest
Posts: 6
Joined: 10 May 2020, 14:46

Re: Autoscaling on EC2 Instances

Postby redquest » 30 Jun 2020, 07:23

Is there any documentation available on putting Smartfox behind a LoadBalancer? We tried multiple rules, but still the app communication & login to SFS admin dashboard is failing.

this is our current ALB Config: https://imagebin.ca/v/5RmnWtxz5VFA
Also we're using SFS elastic license. Is there any premium support available for paid users?
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Autoscaling on EC2 Instances

Postby Lapo » 30 Jun 2020, 08:18

redquest wrote:Is there any documentation available on putting Smartfox behind a LoadBalancer? We tried multiple rules, but still the app communication & login to SFS admin dashboard is failing.

There aren't any specific guides, because SmartFoxServer isn't special in regards to Load Balancers. It works like any other server.

this is our current ALB Config: https://imagebin.ca/v/5RmnWtxz5VFA
Also we're using SFS elastic license. Is there any premium support available for paid users?[/quote]
It looks like you're trying to use the LB for traffic on port 9933. This won't work, because the native SFS2X protocol is not based on HTTP, therefore the LB won't work, correctly. Which explains the problems logging in.

There might be ways to make it work if the LB supports raw TCP protocols, but it can get complicated and I wouldn't recommend it.

Also we're using SFS elastic license. Is there any premium support available for paid users?

Sorry, we don't provide generic sys-admin support. We only concentrate on SFS.
In any case I think there something incorrect with the approach you are using, imho.

You said your game uses SFS2X for the game part and an Apache web server for backend.
Also you're having issues scaling the backend when the traffic increases. We suggested to scale the web server horizontally but not SFS2X, which is easier to scale vertically (i.e. by switching to a more powerful machine if needed)

So, if the objective is to scale the web server horizontally you just need a Load Balancer for the web server(s) and not for SFS2X. In other words you need two entry points in your application:

1- A single SFS2X instance, not behind a load balancer
2- Multiple Apache server instances, behind a load balancer (typically Elastic Beanstalk in AWS)

Makes sense?
Lapo

--

gotoAndPlay()

...addicted to flash games
redquest
Posts: 6
Joined: 10 May 2020, 14:46

Re: Autoscaling on EC2 Instances

Postby redquest » 30 Jun 2020, 16:44

While accessing the admin page, first we are being taken to port 8443, and then after authentication, it gets redirected to port 9933. Is there any way that we can bypass this port forwarding.
In our environment, it will be good if the admin page is working solely in port 8443 or 9933.
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Autoscaling on EC2 Instances

Postby Lapo » 01 Jul 2020, 07:42

While accessing the admin page, first we are being taken to port 8443, and then after authentication, it gets redirected to port 9933. Is there any way that we can bypass this port forwarding.

I have no idea, this is not something SFS2X does.

Why don't you implement the system I proposed? It's the most simple and effective solution to what you've been asking.

1- A single SFS2X instance, not behind a load balancer
2- Multiple Apache server instances, behind a load balancer (typically Elastic Beanstalk in AWS)


Thanks
Lapo

--

gotoAndPlay()

...addicted to flash games
blackbird700
Posts: 8
Joined: 19 Dec 2018, 10:00

Re: Autoscaling on EC2 Instances

Postby blackbird700 » 06 Apr 2021, 10:06

Hi
I couldn't find more appropriate thread and I didn't want to open another one :)

Is there a way to handle single licence key on multiple instances? Our use-case is pretty specific and when user connects, we send pretty big initial dataset to client app (at the moment, we can't move that part away from Smartfox extension). We'd like to load balance multiple instances - for start 2 or 3 behind haproxy load balancer.

And is it possbile to deploy Smartfox inside kubernetes (for autoscaling purposes)?
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Autoscaling on EC2 Instances

Postby Lapo » 06 Apr 2021, 16:00

Essentially you'd need one license per server instance. Deploying via Kubernetes is possible, but you'd need to manage the licenses manually, maybe via a script that provisions the license internally when the server is launched.

I think we have seen a couple of customers doing this, where the licenses are stored on a central DB and the SFS2X instances acquire one when they are launched and release it when they shut down.

Cheers
Lapo

--

gotoAndPlay()

...addicted to flash games
blackbird700
Posts: 8
Joined: 19 Dec 2018, 10:00

Re: Autoscaling on EC2 Instances

Postby blackbird700 » 08 Apr 2021, 18:33

Tnx for reply

and one more quick question - is there built in health endpoint in SFS2X server?
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Autoscaling on EC2 Instances

Postby Lapo » 09 Apr 2021, 14:55

Hi,
short answer: no.

It also depends what you mean by "health". You could build a Java/C# client (using the relative client API) that connects to the server at regular intervals and if it fails more than 2-3 times in a row triggers an email warning or something like that.

Or you could do that plus logging into a Zone for extra health check, or it could be even expanded by also talking to a custom Extension that sends back other health-related parameters.

Hope it helps
Lapo

--

gotoAndPlay()

...addicted to flash games

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 53 guests