2

I have an application running behind a proxy, both on the same machine. Which approach is more suited regarding compression, while preserving reasonable performance.

  • turn on compression at the application level (which happens to be in nodejs)
  • leave it out to the proxy (which is nginx)
20
  • 2
    Questions having the phrase "what/which is better" in them generally don't make very good questions for this site, because we don't know what "better" means to you. We prefer that you describe the specific problem you're trying to solve. Commented Jan 15, 2015 at 19:42
  • 1
    Means ? Well the question says "performanc"e Commented Jan 15, 2015 at 20:46
  • 1
    Ok how come people answered my unclear question, and gave a clear answer. And other faved the question. And yes, the question says compression AND performance. Life is not black or white, you can doze both. Commented Jan 26, 2015 at 16:09
  • 1
    It's exactly because of that "which is better" that I haven't posted my question to ServerFault or even Stackoverflow. programmers.se's description says "Q&A for professional programmers interested in conceptual questions" Commented Jan 26, 2015 at 16:21
  • 1
    That poorly-specified questions are not welcome here either, regardless of their supposed "conceptual" character. Real questions have answers, not opinions. Commented Jan 26, 2015 at 16:27

2 Answers 2

5

While this is probably a better question for ServerFault, I believe there is a clear answer: do compression on nginx.

There are a couple of reasons for this:

  • Compression is moderately CPU-intensive, and Node is single-threaded. Therefore, compression in node will potentially reduce the total number of requests a single server is able to handle.
  • You will almost certainly use nginx to serve static assets such as JavaScript, CSS, images, and static HTML. Which you will want to compress. So why not compress everything that goes through nginx, including forwarded traffic?

As for both: that's just wasted CPU.

5
  • Thanks for the answer PS: the third option was for fun :) Commented Jan 26, 2015 at 16:10
  • This answer is just sort of wrong. For one, you do not want to compress everything that goes through; images come to mind. Secondly, Node.js uses a reactor pattern and IO is async, like gzip. Nginx uses the same event loop and thread pooling pattern. It makes very little practical difference where it happens. Commented Oct 16, 2016 at 20:53
  • @Maletor - compression requires CPU, regardless of where it happens. If your Node server is spending its CPU doing compression, it doesn't have that CPU for other purposes. In any non-trivial web application, you want to offload as much as you can from the machines that are actually doing work. A front-end server is the standard solution to this. Commented Oct 20, 2016 at 11:36
  • Absolutely. But that prerequisites you have Nginx on another server. If it's on the same server I would imagine the end result would be of negligible difference; NGINX is superior in managing concurrency and would probably be slightly faster. Commented Oct 20, 2016 at 19:49
  • 2
    A lot more opinions also on this reddit thread, interestingly they lean more towards letting node handle it - reddit.com/r/webdev/comments/3l1n5h/… Commented Sep 21, 2017 at 15:51
3

Presuming your nginx server fronting node is proximate to said node server you get just about nothing out of using things like compression between the two. You've got plenty of bandwidth between the two, why waste CPU saving it? Moreover, if you are doing any rewrites in nginx it gets ugly as nginx has to unzip the contents, replace, and re-zip. If it lets ya do it at all.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.