HAProxy and nodeJs server using SocketIO

1,250 views
Skip to first unread message

hd nguyen

unread,
Jul 30, 2012, 5:52:08 AM7/30/12
to sock...@googlegroups.com
Hi all,

I did some google search but not find any detail document described about combination between HAProxy and Nodejs apps(use socketIO), something for me to believe that it can work well.

I have another option is Nginx, but just want you guys help me to confirm that is it possible to use HAproxy as load balancer for Nodejs server farm (using SocketIO to transfer data)?

Thanks in advance.

--
Nguyen Hai Duy
Mobile : 0914 72 1900
Yahoo: nguyenhd_lucky

Łukasz Michalski

unread,
Jul 30, 2012, 7:33:30 AM7/30/12
to sock...@googlegroups.com
On 07/30/2012 11:52 AM, hd nguyen wrote:
> Hi all,
>
> I did some google search but not find any detail document described
> about combination between HAProxy and Nodejs apps(use socketIO),
> something for me to believe that it can work well.
>
> I have another option is Nginx, but just want you guys help me to
> confirm that is it possible to use HAproxy as load balancer for Nodejs
> server farm (using SocketIO to transfer data)?
>

Yes, using two instances of haproxy.

Look in the archives for my eariler posts.

Regards,
Luke

Jason Strimpel

unread,
Jul 30, 2012, 11:29:21 AM7/30/12
to sock...@googlegroups.com
I set up a proof of concept using haproxy a few months back. It worked well.  haproxy was listening on port 80 then directing socket traffic to node and static resource requests to nginx.

hd nguyen

unread,
Jul 30, 2012, 11:39:29 AM7/30/12
to sock...@googlegroups.com
Please send me the link to your earlier poet @Lucas.

Shripad K

unread,
Jul 30, 2012, 1:43:24 PM7/30/12
to sock...@googlegroups.com
@hd nguyen. I have put up a config file here : http://stackoverflow.com/questions/4360221/haproxy-websocket-disconnection/4737648#4737648

For polling transports you can balance source or use cookie based persistence. I would suggest you use cookie based persistence along with balance source coz IP based balancing alone doesn't work well when clients have dynamic address.

hd nguyen

unread,
Jul 30, 2012, 9:57:04 PM7/30/12
to sock...@googlegroups.com
Thanks Shripad,

I will take a look at it and get back to you later.

Philmod

unread,
Aug 1, 2012, 4:52:33 AM8/1/12
to sock...@googlegroups.com
Jason, can you provide more information about?  Maybe a blog post or github link?

Thanks,
Philmod

mgutz

unread,
Aug 1, 2012, 5:27:49 PM8/1/12
to sock...@googlegroups.com
Our setup in production is

Stud - SSL termination. HAProxy doesn't do SSL.

HAProxy - load Balancer. Can handle websockets. Basically, haproxy sends websocket traffic to 1 or more node servers. We didn't bother with node cluster.  Static requests are forwarded to nginx.

Nginx - serve static assets. Nginx doesn't yet support web sockets. Varnish would be a viable option but nginx will support websocket in the near future.

Arne de Bree

unread,
Aug 1, 2012, 5:33:52 PM8/1/12
to sock...@googlegroups.com
Same can be achieved using stunnel for ssl termination (or AWS ELB's in TCPssl mode)

Downside of all this is that you loose the Client IP. None of stud, stunnel or ELB in TCPssl mode will set the X-Forwarded-For, which caused me to fallback to xhr and jsonp polling transports and use regular HTTPS termination sollution.

You also want to watch out if you need stickyness or not, when you need to keep state in your Node.js server, and you have multiple of them. Keep some kind of stickyness in sight, or you need to share state between your nodes.

Regards,
Arne
--
Met vriendelijke groet / with kind regards,

Arne de Bree

@adebree

Jason Strimpel

unread,
Aug 1, 2012, 11:35:48 AM8/1/12
to sock...@googlegroups.com
Philmod

Unfortunately all the work was done on a centos box that no longer exists. I have a bunch old haproxy conf files hanging around on my desktop like https://gist.github.com/3227797. I am not sure which conf was the final. I kept changing the config because I ran into an issue like https://github.com/LearnBoost/socket.io/wiki/Socket.IO-and-firewall-software on a WIN7 box, but did not recognize it. Below are couple links that I think I used to get started.


Jason

mgutz

unread,
Aug 2, 2012, 6:39:58 PM8/2/12
to sock...@googlegroups.com
We create chat rooms based on client's remote address. Our deploy environment is close to this article, except we use stud since it performed better.


On Wednesday, August 1, 2012 2:33:52 PM UTC-7, Arne de Bree wrote:
Same can be achieved using stunnel for ssl termination (or AWS ELB's in TCPssl mode)

Downside of all this is that you loose the Client IP. None of stud, stunnel or ELB in TCPssl mode will set the X-Forwarded-For, which caused me to fallback to xhr and jsonp polling transports and use regular HTTPS termination sollution.

You also want to watch out if you need stickyness or not, when you need to keep state in your Node.js server, and you have multiple of them. Keep some kind of stickyness in sight, or you need to share state between your nodes.

Regards,
Arne

Reply all
Reply to author
Forward
0 new messages