10

I have heard a lot and read about the Javascript server side language i.e Node.js, and saw many comparisons in favor of Node.

I don't understand what makes it better or faster, or how it even relates to something as mature as Java Servlets.

But Servlets are built on top of a multithreaded programming language as opposed to Node.js. Then how can node.js be faster?

If suppose 1000K users query for a database records, then shouldn't Node.js be slower than Servlets.

Also Don't servlets have better security compared to Node.js?

Yam Marcovic
  • 9,270
  • 2
  • 27
  • 29
log N
  • 487
  • 2
  • 7
  • 13
  • Both processes and threads can be used to scale any application for multi-core utilization. You don't need both. – Raynos Oct 11 '12 at 16:00
  • @Raynos Can't the bound C functionality also be threaded? I just took JS's role to be as non-blocking auto-queuing messenger to hand things off to lower-level stuff but I still haven't gotten my paws on Node yet. – Erik Reppen Oct 11 '12 at 21:28

1 Answers1

12

You're mixing apples and oranges, kind of.

Servlets (or inheriting from HttpServlet) let you access HTTP request parameters and respond with something, via (or on top of) an existing HTTP server implementation.

Although using Javascript as the language, Node.js is at a lower level than that. It starts from actually implementing the HTTP server. You can go on to doing more high-level stuff in it nonetheless, such as web applications.

About multi-threading, it's not necessary. Node.js servers aren't faster because of multi-threading, they're faster because they don't block on IO requests, so they can keep pumping them up in the queue, while doing other things. They only work when there's work to be done - they don't wait for it - and that causes a serious performance enhancement, as it turned out.

As for database queries, it's really more about constraints in the database model and API than it is about the client.

As for security - it's really a different topic, and is ultimately in the hands of any developer anyway, not so much in the library.

Yam Marcovic
  • 9,270
  • 2
  • 27
  • 29
  • 3
    Servlet 3 supports asynch IO just like Node – jiggy Jul 19 '13 at 15:33
  • 3
    jiggy - There's a big difference between *supporting* something and being *designed from the ground up* for something. Node asynchrony is the latter. – Jack Sep 05 '15 at 02:38
  • 1
    @Yam Marcovic I still don't understand what you mean by *"they don't block on IO requests"* Even in JEE the a thread would run independently that wouldn't stop another request to be served. As a new thread is created per request. Am I making sense? – Oliver Nov 28 '17 at 09:18