Re: scaling express.js

682 views
Skip to first unread message

tjholowaychuk

unread,
Oct 16, 2012, 2:42:54 PM10/16/12
to Express
Yeah you can use nginx, varnish, haproxy or similar to perform
balancing between nodes,
with no code changes at all to your application, assuming the app is
built without in-memory
requirements, for say sessions etc. Otherwise the only thing you need
is the ability to bind
to a different port, such as:

$ node app --port 3000
$ node app --port 3001
$ node app --port 3002
$ node app --port 3003

etc and then load balance to those nodes

On Oct 16, 11:30 am, chirag jain <cj.dev.d...@gmail.com> wrote:
> I completed my expressjs app. I wondering how would i scale my app to
> multiple servers with X cores.
>
> I did some research before posting. Closest i could get was to use nginx as
> load balancer on top of N expressjs app.
> I'm not sure how would i configure this nginx load balancer with N
> expressjs app instances on multiple servers. How much code changes will be
> required?
> Anyone with multiple expressjs deployment in production can share their
> thoughts and architecture.
>
> Best regards,
> Chirag Jain

chirag jain

unread,
Oct 16, 2012, 2:48:07 PM10/16/12
to expre...@googlegroups.com
I do have session requirements. For now its using memorystore. But m planning to move sessions to redis. Will that help?

chirag jain

unread,
Oct 16, 2012, 2:52:33 PM10/16/12
to expre...@googlegroups.com
Also, i have created the benchmark for my app.
https://gist.github.com/3888654

Can you please suggest if they are normal/ideal.

Thanks for the great effort TJ. :)

greelgorke

unread,
Oct 17, 2012, 7:15:38 AM10/17/12
to expre...@googlegroups.com
you can use nodes cluster api for usind cpu cores while sharing ports and use fleet + seaport to scale other mashines. http://substack.net/posts/16a9d8/multi-server-continuous-deployment-with-fleet

chirag jain

unread,
Oct 17, 2012, 12:52:42 PM10/17/12
to expre...@googlegroups.com
I moved sessions to redis. and the app the now binds to different ports.

Can you specify nginx configuration for load balancing?


On Wednesday, 17 October 2012 00:12:57 UTC+5:30, tjholowaychuk wrote:

Ryan Schmidt

unread,
Oct 18, 2012, 3:38:42 PM10/18/12
to expre...@googlegroups.com

On Oct 16, 2012, at 13:42, tjholowaychuk <tjholo...@gmail.com> wrote:

> Yeah you can use nginx, varnish, haproxy or similar to perform
> balancing between nodes,

How would this compare to using round-robin DNS, which seems favorable to me on the basis of not needing to learn how to install, configure and maintain another piece of software?


> Otherwise the only thing you need
> is the ability to bind
> to a different port, such as:
>
> $ node app --port 3000
> $ node app --port 3001
> $ node app --port 3002
> $ node app --port 3003
>
> etc and then load balance to those nodes

How would you compare this to using the cluster module?

http://nodejs.org/api/cluster.html

Which method would you recommend in which circumstances?

tjholowaychuk

unread,
Oct 18, 2012, 5:17:17 PM10/18/12
to Express
cluster module is fine too. if you're running behind a reverse proxy
cache you get
the load balancing for free so it depends on the case. I would
probably use cluster
for smaller non-critical apps but anything else I'd run behind varnish
or similar personally

On Oct 18, 12:38 pm, Ryan Schmidt <google-2...@ryandesign.com> wrote:

chirag jain

unread,
Oct 19, 2012, 2:33:11 PM10/19/12
to expre...@googlegroups.com
After looking through the options you mentioned i finally settled for HaProxy and nginx for serving static content. Big Win.

New app benchmark on my local machine with HaProxy : https://gist.github.com/3919767
Old benchmark : https://gist.github.com/3888654

Can some please comment on the abnormality / normality of the benchmarks?

mgutz

unread,
Oct 19, 2012, 2:56:24 PM10/19/12
to expre...@googlegroups.com
Benchmark are always relative to the environment they're running in. Try something like blitz.io. You can stress test your app for free. If you have haproxy, nginx configured properly you shouldn't get any timeouts. The biggest thing we found is to use not use node/express for static caching or SSL. Let nginx or varnish do that along with gzipping assets, etc. We use stud for SSL termination.
Reply all
Reply to author
Forward
0 new messages