users@shoal.java.net

Re: Shoal & load balancing

From: Shreedhar Ganapathy <shreedhar.ganapathy_at_oracle.com>
Date: Sun, 10 Jul 2011 11:07:33 -0700

Hi Zlaja
I have put in responses below.

On 7/9/11 10:04 AM, Zlatko Josic wrote:
> *
> *
> First, thank you all. Now, I get idea about load balancers.
>
> My company has developed own server we use for recharge prepaid
> accounts for mobile phones and it works fine.
> System now has 2000 clients permanently connected to the server. Now
> we want to add clustering feature to this server.
> I have explored how clustering/shoal is used in GlassFish server and
> have some questions.
>
> 1. GlassFish uses Shoal for web sessions and ejb stateful states
> replication and etc. Suppose we have a cluster of three nodes, A,B and C.
> If user writes some data to web session on node A does the result of
> the write operation going to replicate on nodes A and B.

Spreading sessions across all instances in a cluster would eventually
become a scaling problem either when large number of users become part
of the system or a limited number of users send in large number of
requests.

The shoal replication algorithm for GlassFish employs a consistently
scalable approach by replicating each request under a user session to
one replica among the cluster of instances, using a consistent hashing
algorithm.

This ensures that for each session sent to A, B or C, the data is
replicated to one replica partner for that session. For instance session
1 sent to A may be computed to replicate to B, session 2 sent to A may
be computed to replicate to C, while session 3 sent to B may replicate
to C and so on.

This ensures that all data is replicated in a consistently distributed
manner without loading one particular instance as a buddy partner for
another instance and also not spreading the data to all instances.
>
> 2. Suppose that only two nodes work in the cluster, A and B. Now we
> start third node, C. After C node started would it ask the cluster
> for web sessions to be replicated on it, node C?
To avoid spreading all sessions across the cluster, any new session sent
to A or B may have a computation result of replicating to C. Likewise,
any session sent to C will now get computed to be replicated to A or B.

>
> 3. As I mention above all ours clients are permanently connected to
> the server. Suppose we have cluster of two nodes, A and B. Also we
> have a client
> connected to node A (the client has created socket connection to
> communicate to the server. We have Mina based connectors on the server) .
> At some moment at the time node A crashed. Does the client has to
> create new socket connection to work with node B or it is possibility of
> load balancer to dispatch request to node B? I am not shure if it can
> work at all because at that moment node B has not server's socket that
> is pair with
> the client's socket.

The way I see this working is A, B and C are fronted by a Load Balancer.
The clients only know about the LB and do not know about any of A, B, C
or any other new instance you add as you scale up. From a security
standpoint, this is also safer since details of your cluster are not
exposed to clients on the internet.

The LB proxies the request to any one of the A, B or C instances. Lets
assume it sent a new session to A. When you set up the LB for sticky
sessions, all subsequent requests under that session will be sent by the
LB to that instance A, for that session. The session's data is
replication by instance A's replication module using the consistent
hashing algorithm - Lets assume that instance A replicated to instance C
for that session.

If instance A fails for any reason, the LB will route/failover the
request to another instance, say B, (based on its routing policies -
typically round robin). If this is a GlassFish cluster, instance B's web
container will receive that request and try to access the session in its
session cache and will not find it, and as a result will ask the
replication module in B to find this session's latest data. The
replication module will now use the consistent hashing algo to compute
which instance was the replica for this session and get C as a result -
it will send a request to C to load the latest data of that session and
return it to the Web Container to retain it in its cache. Subsequent
requests will be sticky to instance B until it fails or is stopped by
the administrator.

As you can see above, the Sticky Load Balancing allows you to ensure a
session continues until it is timed out for a given user. It does not
require you to have long running socket connections - you only need a
protocol to auto re-login a user when the user sends session data from
the client when the session has timed out on the server end. And
clustering with replication allows you to scale out as your user base
grows.

Hope this helps. Let us know if you have more questions. If you are a
GlassFish user, you can also post GlassFish related questions to users
[at] glassfish [dot] java [dot] net email address.

Shreedhar

>
> Thank you for any idea, link,...
>
> Zlaja
>
> On Fri, Jul 8, 2011 at 5:10 PM, Shreedhar Ganapathy
> <shreedhar.ganapathy_at_oracle.com
> <mailto:shreedhar.ganapathy_at_oracle.com>> wrote:
>
> Wow I am impressed with the community chipping in folks. Thanks
> very much for responding to this question.
>
> Zlaja, as mentioned by Jorge and Sri Narayanan, the load balancer
> can be anything from Apache with mod_jk to Linux HA to many others
> in the open source and closed source market - most of these
> support Http an TCP protocol in plain text and secure mode through
> ssl.
>
> Cheers
> Shreedhar
>
> On 7/8/11 6:01 AM, Jorge Falcão wrote:
>> It's HTTP based searvice?
>> You can integrate your app with http://www.jboss.org/mod_cluster
>>
>> On Fri, Jul 8, 2011 at 8:31 AM, Sri Narayanan
>> <sri.narayanan.gce_at_gmail.com
>> <mailto:sri.narayanan.gce_at_gmail.com>> wrote:
>>
>> Usually any clustered design has Load Balancer and it has
>> nothing to do with Shoal.
>> Shoal is just a clustering framework.
>> u can have a look at hazelcast also .
>> The design has to based on the logic
>>
>>
>> On Fri, Jul 8, 2011 at 4:33 PM, Zlatko Josic
>> <zlatko.josic_at_gmail.com <mailto:zlatko.josic_at_gmail.com>> wrote:
>>
>> Hi,
>>
>> I would like to include clustering in Java SE
>> application. Do I need load balancing in front of cluster?
>> Does Shoal support load balancing? If not what is the
>> solution for load balancing? Should I use any other framework
>> for load balancing or what?
>>
>> Thanks
>> Zlaja
>>
>>
>>
>>
>> --
>> Regards,
>> SriNarayanan
>>
>>
>>
>>
>> --
>> Jorge Falcão,
>> Intelie - Inteligência em operação
>> http://www.intelie.com.br/
>> 55 21 2240-1193 / 9373-8671
>
>