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?

2
  • Both processes and threads can be used to scale any application for multi-core utilization. You don't need both.
    – Raynos
    Commented Oct 11, 2012 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. Commented Oct 11, 2012 at 21:28

1 Answer 1

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.

3
  • 3
    Servlet 3 supports asynch IO just like Node
    – jiggy
    Commented Jul 19, 2013 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
    Commented Sep 5, 2015 at 2: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
    Commented Nov 28, 2017 at 9:18

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.