Page refresh with nginx load balancer

551 views
Skip to first unread message

Phuoc Do

unread,
May 17, 2014, 3:17:25 AM5/17/14
to meteo...@googlegroups.com
Hello,

Our app is reaching a point where we need to scale horizontally. We have been using AWS and decide to go with nginx load balancer. We basically have two nodejs servers running behind nginx load balancer. I managed to compile nginx with stick session module.


It is running ok except one problem. Occasionally, meteor page continuously reloads. This generates request flood to our server. It doesn't happen all the time. When I reboot meteor server, it is back to normal. I haven't figured out how to reproduce the problem. I found meteor has one page reload here:


It seems like the problem is with meteor and nginx stick session. I know that nginx sticky session uses cookie. I wonder if that can conflict with meteor session tracking. Any insight would be appreciated.

Thanks,

Phuoc Do

Jonas Aschenbrenner

unread,
May 17, 2014, 2:52:36 PM5/17/14
to meteo...@googlegroups.com
I had the problem in the past too. I think I solved it by:
1. Restart the meteor app after an update was deployed
2. Add the reload and autoupdate packes to .meteor/packages. The are included in the standard-app-packages package but I don't use it and I forgot to add them.

Phuoc Do

unread,
May 19, 2014, 2:02:51 AM5/19/14
to meteo...@googlegroups.com
Hi Jonas,

Thanks. It seems like reload package is causing my app to reload the page. I wonder why adding it to .meteor/packages can fix the issue.

Phuoc

Phuoc Do

unread,
May 19, 2014, 3:07:42 AM5/19/14
to meteo...@googlegroups.com
Hi Jonas, just gave your suggestion. I still get page refresh.

Phuoc Do

unread,
May 19, 2014, 4:00:05 AM5/19/14
to meteo...@googlegroups.com
I found that meteor is trying to call reload. When I run locally, reload is never called. It seems to think that there is new code available on server. reload is called twice. I took 2 screenshots below. In the first time, function returns without refresh window. In the second time, reload is called from _maybeMigrate. Then page refreshes with location.reload.

The code hasn't changed. Could it be that load balancer interferes with hot code reload check?

Phuoc

Phuoc Do

unread,
May 20, 2014, 2:48:34 AM5/20/14
to meteo...@googlegroups.com
I've got nginx setup locally to debug the issue. It looks like my current code version is not the same as autoupdateVersion (see reload_code_version.png). So meteor reload kicks in to sync the code.

I check route cookies (see reload_route_cookies.png) and there are several of them. Browser is loading files from different servers. I suppose the problem is with multiple route cookies being assigned by nginx sticky session module. Maybe meteor doesn't submit all cookies with file request?

Andrew Mao

unread,
May 20, 2014, 4:18:28 PM5/20/14
to meteo...@googlegroups.com
Because sticky uses cookies, it might break things. We had a much lesser problem using ip_hash, although equal balancing is not as guaranteed.

Phuoc Do

unread,
May 20, 2014, 5:08:35 PM5/20/14
to meteo...@googlegroups.com
Hi Andrew, nginx sticky module warns not to use ip_hash. Is it working for you?


I found a way to work around by setting AUTOUPDATE_VERSION environment variable. But that will disable hot code reload.

Phuoc Do

unread,
May 21, 2014, 1:49:55 AM5/21/14
to meteo...@googlegroups.com
I changed sticky session to set cookie only on "/" path instead of letting browser decide. This seems to work. Thanks Arunoda for the suggestion. Here's my nginx config if anyone is interested:

Andrew Mao

unread,
May 22, 2014, 11:40:46 PM5/22/14
to meteo...@googlegroups.com
I don't think you can use sticky with ip_hash at the same time. it is one or the other.

Arunoda Susiripala

unread,
Jul 25, 2014, 4:06:10 AM7/25/14
to meteo...@googlegroups.com
It's possible receive a lot of requests from a single IP (due to transparent proxies and etc..)
So, there might be issues with load distributions.

Cookie based sticky sessions are the solution for that. Yes, it does fail over. Meteor trying to re-connet when the connection drops. 



On Fri, Jul 25, 2014 at 1:26 PM, Danijel Cole <dan.ba...@gmail.com> wrote:
Hmm...interesting idea. But are there any issues with using ip_hash to horizontally scale a Meteor site? 

Also any thoughts on what happens if a server node goes down...will subsequent meteor client request gracefully fail over to another meteor instance? 


Thanks 

--
You received this message because you are subscribed to the Google Groups "meteor-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to meteor-core...@googlegroups.com.
To post to this group, send email to meteo...@googlegroups.com.
Visit this group at http://groups.google.com/group/meteor-core.
For more options, visit https://groups.google.com/d/optout.

Adrian Lanning

unread,
Jul 25, 2014, 9:32:20 AM7/25/14
to meteo...@googlegroups.com
For those exploring other options, HAProxy has a nice balancing option, 'leastconn':


  leastconn   The server with the lowest number of connections receives the
              connection. Round-robin is performed within groups of servers
              of the same load to ensure that all servers will be used. Use
              of this algorithm is recommended where very long sessions are
              expected, such as LDAP, SQL, TSE, etc... but is not very well
              suited for protocols using short sessions such as HTTP. This
              algorithm is dynamic, which means that server weights may be
              adjusted on the fly for slow starts for instance.

"This only applies when no persistence information is available, or when a connection is redispatched to another server",  which means this only kicks in when no sticky session cookie is found.

Stephan Hochhaus

unread,
Jul 26, 2014, 12:07:08 PM7/26/14
to meteo...@googlegroups.com
There is a similar function in nginx called least_conn

Harshit Daga

unread,
Dec 3, 2014, 6:11:38 AM12/3/14
to meteo...@googlegroups.com
Hi Guys,

I am also facing similar issue. Request are going to multiple servers causing page continuous page reloads/refresh.


I am using DDP_DEFAULT_CONNECTION_URL since cloudflare is currently not supporting websockets. 


Thanks ,
 HD
Reply all
Reply to author
Forward
Message has been deleted
Message has been deleted
0 new messages