Load balancing with sessions

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Load balancing with sessions

Peter Jakobsson-2
Hi

I’m about to embark on a project that will require Active4D sessions to be load balanced across multiple 4D Client (4D Remote in modern parlance) web servers running ITK.

The current configuration is:

[Tier 1] - 4D Server running data queries

[Tier 2] - multiple 4D Client web servers

[Tier 3] - Apache with load balancer distributing requests to the 4D Client web servers

At the moment, when a session based request comes in it gets directed to a single ‘master’ web server from that point on, so there is currently no load balancing for session based requests.

We are going to significantly extend the use of sessions now, and potentially need to think about how to load-distribute them. Clearly, we can’t have more than 1 machine handling a given session so maybe something like getting Apache allocate a web server to the session and make it ‘stick’ from then on is the way to go.

If anyone has any interesting input to contribute on this subject I’d much appreciate hearing it.

Best Regards

Peter

_______________________________________________
Active4D-dev mailing list
[hidden email]
http://list.aparajitaworld.com/listinfo/active4d-dev
Archives: http://active4d-nabble.aparajitaworld.com/
Reply | Threaded
Open this post in threaded view
|

Re: Load balancing with sessions

Aparajita Fishman
> We are going to significantly extend the use of sessions now, and potentially need to think about how to load-distribute them.

I have code in Active4D already to store sessions in the database, I have to activate and test that code.

Regards,

  Aparajita

_______________________________________________
Active4D-dev mailing list
[hidden email]
http://list.aparajitaworld.com/listinfo/active4d-dev
Archives: http://active4d-nabble.aparajitaworld.com/
Reply | Threaded
Open this post in threaded view
|

Re: Load balancing with sessions

Peter Jakobsson-2

> I have code in Active4D already to store sessions in the database, I have to activate and test that code.

Very interesting. Database sessions hadn’t crossed my mind but now I remember you mentioning that at some point.

Is this going to be a low level thing (or intermediate - e.g. a4d shell or fusebox shell) that just runs one query per request to retrieve the session and then all our existing session code continues to work without major revision ?

That would be kind of awesome and take us even deeper into industrial territory in terms of scaleability.

Peter
_______________________________________________
Active4D-dev mailing list
[hidden email]
http://list.aparajitaworld.com/listinfo/active4d-dev
Archives: http://active4d-nabble.aparajitaworld.com/
Reply | Threaded
Open this post in threaded view
|

Re: Load balancing with sessions

Justin Will
In reply to this post by Peter Jakobsson-2
Peter,

I have done 4D Client load balancing with NGINX and NTK for several years.
In the last few months we have been working on a project to convert from 4D
Methods to Active4D as our html generation mechanism.  We have written our
own session storage to the database and it seems to work quite well.

Saving the session data to 4D records solves a couple of problems for you.

1.  You do not have to bind a web user to a single 4D Client webserver.
This is a big deal because if a particular webserver fails all clients bound
to that webserver lose their state.

2.  If you have to restart a client or 4d server for some reason all of you
sessions are maintained.  This is not the case in A4D's current memory based
session handling.

3.  Having load balancing with 4D Clients can really help with performance
of your site under heavy load.  It really helps solve the problem that 4D
can only use 1 CPU core for executing 4D code.


A couple of drawbacks with load balancing are:

1.  If you get a webserver that is slow to respond to a request the request
can be submitted to the next webserver.  You can end up with duplicate
records as a result of this.  You have to code defensively for this
situation.  Semaphores are your friend for handling this.

2.  Record based sessions are just not as fast as memory based.  I have not
found this to be a large problem but it's just not as fast.


Peter, if you want to chat further just drop me a line.

Thanks
Justin Will




_______________________________________________
Active4D-dev mailing list
[hidden email]
http://list.aparajitaworld.com/listinfo/active4d-dev
Archives: http://active4d-nabble.aparajitaworld.com/
Reply | Threaded
Open this post in threaded view
|

Re: Load balancing with sessions

Peter Jakobsson-2

On Jul 7, 2015, at 9:22 PM, Justin Will <[hidden email]> wrote:

> I have done 4D Client load balancing with NGINX and NTK for several years.
> In the last few months we have been working on a project to convert from 4D
> Methods to Active4D as our html generation mechanism.  We have written our
> own session storage to the database and it seems to work quite well.

Hi Justin

That was a very useful post. Many thanks.

It would be interesting to quantify the performance hit with DB based sessions. I imagine it depends on your existing code - i.e. if you’re already running 10 or 20 queries per request then 1 more doesn’t sound that much. On the other hand if you’re going from none to one then it’s likely more noticeable.

Peter

_______________________________________________
Active4D-dev mailing list
[hidden email]
http://list.aparajitaworld.com/listinfo/active4d-dev
Archives: http://active4d-nabble.aparajitaworld.com/