Forum: Rails deployment Load balancing in Rails

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
7047ebbc6fc7cd4e5693e43a8356eba4?d=identicon&s=25 Ram Ravichandran (raam)
on 2007-06-23 05:07
Hey,

Can someone give me some advice in setting up load balancing (and
suggestions on some good cheap software load balancers.) I need a load
balancer which can look at the incoming http request, query a session
variable in the request, and based on the value, it should route the
request to 1 of 10 servers. My questions are:

a) Is it even possible to inspect session variables, or do the Load
balancers (LB) work at a higher level? Will it be a considerable
performance hit to do this level of lookup?

b) I have a hash which maps a value in the session variable to the
server to which we need to route the request. What's the best way to
maintain this hash? Keep it in memory in the LB? or have a database that
stores these values? Which is better given that I have about 10 million
values to choose from?

c) Any suggestions on a good software load balancer that can do this?

I would appreciate any help possible.
Thanks,

Ram
38a02bf7121a81be5be6f3d488ce23b5?d=identicon&s=25 Alexey Verkhovsky (Guest)
on 2007-06-23 06:16
(Received via mailing list)
On 6/22/07, Ram Ravichandran <ruby-forum-incoming@andreas-s.net> wrote:
> c) Any suggestions on a good software load balancer that can do this?

HAProxy

You may also want to use RubyWorks (http://rubyworks.rubyforge.org),
as a starting point.

--
Alex
6076c22b65b36f5d75c30bdcfb2fda85?d=identicon&s=25 Ezra Zygmuntowicz (Guest)
on 2007-06-23 06:28
(Received via mailing list)
On Jun 22, 2007, at 8:07 PM, Ram Ravichandran wrote:

> balancers (LB) work at a higher level? Will it be a considerable
> performance hit to do this level of lookup?

Are you talking about variables stored in your rails session? If so
then no there is no way to query the session variables and make
decisions based on that in the load balancer. Most load balancers can
do balancing based on some cookie or special header in the request.
But getting at the data in the rails session is only possible from
within a rails app and the load balancer works in front of rails ands
has no way to query the session values.


>
> b) I have a hash which maps a value in the session variable to the
> server to which we need to route the request. What's the best way to
> maintain this hash? Keep it in memory in the LB? or have a database
> that
> stores these values? Which is better given that I have about 10
> million
> values to choose from?

It is going to be a huge performance hit if your load balancer has to
check a database for each request it routes. Can you expound on what
problem you are trying to solve with this? Maybe there is a different
way to accomplish what you want that will still perform acceptably.

>
> c) Any suggestions on a good software load balancer that can do this.

  Second vote for HAProxy, it's probably the most flexible fast
software load balancer around. Although I know it will not be able to
inspect your rails sessions, thats not an option at the load
balancing point.

Cheers-
-- Ezra Zygmuntowicz
-- Lead Rails Evangelist
-- ez@engineyard.com
-- Engine Yard, Serious Rails Hosting
-- (866) 518-YARD (9273)
38a02bf7121a81be5be6f3d488ce23b5?d=identicon&s=25 Alexey Verkhovsky (Guest)
on 2007-06-23 06:39
(Received via mailing list)
On 6/22/07, Ezra Zygmuntowicz <ezmobius@gmail.com> wrote:
> Second vote for HAProxy, it's probably the most flexible fast
> software load balancer around. Although I know it will not be able to
> inspect your rails sessions, thats not an option at the load
> balancing point.

HAProxy has some rather fancy stuff around session affinity - it can
match sessions by patterns in cookies. Even though it obviously won't
have access to server-side Rails session data, you can copy enough of
that data to a cookie and have HAProxy look at that.

--
Alex
38a02bf7121a81be5be6f3d488ce23b5?d=identicon&s=25 Alexey Verkhovsky (Guest)
on 2007-06-23 06:40
(Received via mailing list)
On 6/22/07, Alexey Verkhovsky <alexey.verkhovsky@gmail.com> wrote:
> HAProxy has some rather fancy stuff around session affinity - it can
> match sessions by patterns in cookies.

Oh well, I should have read your entire reply first... :)
7047ebbc6fc7cd4e5693e43a8356eba4?d=identicon&s=25 Ram Ravichandran (raam)
on 2007-06-23 10:30
> It is going to be a huge performance hit if your load balancer has to
> check a database for each request it routes. Can you expound on what
> problem you are trying to solve with this? Maybe there is a different
> way to accomplish what you want that will still perform acceptably.
>

Thanks for the replies. I have a few hundred thousand users in around 10
servers. All information about a user is completely within one of the 10
servers. I was planning on using the load balancer to figure which
server contains a user's information by doing a database (with some sort
of memcache?)look up. When a new user signs up, he is assigned a server
according to the information he gives at signup. I would then update the
database on the load balancer with this information.

I am kind of lost actually... is there a better way of doing this?


Thanks,
Ram
539e19d44731cadf3180003d00ebef01?d=identicon&s=25 tmornini@engineyard.com (Guest)
on 2007-06-23 22:25
(Received via mailing list)
Hello Ram.

I'd love to discuss your deployment with you.

Perhaps we can be of service here?

Thanks!

--
-- Tom Mornini, CTO
-- Engine Yard, Ruby on Rails Hosting
-- Support, Scalability, Reliability
-- (866) 518-YARD (9273)

On Jun 23, 1:30 am, Ram Ravichandran <ruby-forum-incom...@andreas-
2e8848a777f7165f80da876ab1e6e7e5?d=identicon&s=25 dusty (Guest)
on 2007-06-26 05:12
(Received via mailing list)
On Jun 23, 4:30 am, Ram Ravichandran <ruby-forum-incom...@andreas-
s.net> wrote:
> according to the information he gives at signup. I would then update the
> database on the load balancer with this information.
>
> I am kind of lost actually... is there a better way of doing this?
>
> Thanks,
> Ram

If you are sending a user to a single specific server, then why bother
with the load balancer?  I would just do the simplest path, which is
send them a unique URL pointing to "their" server.  For example, login
to a main page, do your database lookup there and present them with a
link to continue.  The link will contain a url to "their" server (eg:
host9.x.com).

With your original route, you are now going to have to also manage a
load balancer (and its fault tolerant brother) and you'll be relying
on a database lookup for every page request.  Seems like a lot of
moving parts and it isn't even buying you any scalability.  Since you
are forced to one server per use, I'd just say go with it.  :)
7047ebbc6fc7cd4e5693e43a8356eba4?d=identicon&s=25 Ram Ravichandran (raam)
on 2007-06-26 06:32
>
> Perhaps we can be of service here?
>

Yeah, at some point very soon when I get enough dough from FFF (friends,
family and fools) for my startup :)

Ram
7047ebbc6fc7cd4e5693e43a8356eba4?d=identicon&s=25 Ram Ravichandran (raam)
on 2007-06-26 07:02
> If you are sending a user to a single specific server, then why bother
> with the load balancer?  I would just do the simplest path, which is
> send them a unique URL pointing to "their" server.  For example, login
> to a main page, do your database lookup there and present them with a
> link to continue.  The link will contain a url to "their" server (eg:
> host9.x.com).

Thanks for your suggestion. I guess I am going with something similar
(in lines of Ezra's suggestion). At first the user gets forwarded to any
of the servers which figures out which server he really belongs to. It
then sets a cookie for the load balancer for future forwarding to the
right server. It also serves the main page.

By doing it this way, the user notices nothing explicitly about the
redirection. He may notice the slower response time for just the first
request.

Thanks,
Ram
This topic is locked and can not be replied to.