Have you been reading multiple articles trying to understand whether Node.js is single-threaded or multi-threaded? Why are there many of them sayin...
For further actions, you may consider blocking this person and/or reporting abuse
NodeJS isn't more performant than Java. That's a common misconception. It's got better throughput since Javas old IO uses a thread per connection which doesn't scale (but is actually pretty fast). Async Java frameworks includes the benefits of threading and the throughput of NodeJS.
This will be resolved by project Loom which is fast approaching production. Project loom essentially turns threads "partially" green. That would mean you can code synchronously in Java using threads and the simpler stream IO. But the OS won't allocate a thread per Java thread. Only to the optimum amount of threads to get the most out of your CPU.
Thanks for setting the record straight. The author misspoke on true multithreading.
C# is even better it uses Tasks which always use the least busy CPU. It's not just another thread on a single process, it's an asynchronous call directly to the least busy CPU, which spins up, and queues up Task continuations. Only after the work is done are the results captured using an await. Similar to Javascript promise but many times speedier.
I have heard however that node too can spin up CPU agnostic instances. However this author omitted that discussion.
Node's async first architecture was a brilliant move and covers a lot of territory. However single node instances are nowhere the Speed of Java or C# using Tasks or other well defined threading techniques. The only problem is that browsers only speak Javascript.
Project loom aims to leapfrog C# by removing the need to denote tasks. It will make the JVM itself smart enough to use just the right amount of native threads seamlessly. It's currently in technology preview stage and hopefully will ship with Java 18 or 19.
Totally cool, I never liked the Task hoops to jump through but use it long enough and it's a second language.
Well I'm not an Java expert but every enterprise app using java like SAP products just feels slow and I instantly feel like I'm back in the 90's. Also he is saying that node is faster in this specific field which it is.
Statement means nothing really as we're not talking about any legacy product. We're talking about what can be done today. For true parallelism today, except on mainframes, the dotnet task construct is a true co-routine design which uses all CPUs in an agnostic way. There's nothing close to it today
If it is an server running an API, there are several programming languages with their respective frameworks that would work. C# could work using .NET Core or Entity Framework just like NodeJS with Express.js
Thanks for sharing! I didn't mean to say NodeJS is more performant than Java. The main reason I was providing the explanation was to give insights with regards to why it is widely used across several projects even though NodeJS architecture runs single-threaded as it provides the performance needed to develop APIs.
Hi @arealesramirez great article!
I would like to complement with the following:
Nice work! Keep it going :)
Please use the correct facts when referencing other environments like C# (and probably Java too on that topic). With dotnet (C#) you can choose to use AOT compilation when optimizing for startup time. But default it compiles to byte-code which during runtime is JIT compiled in multiple tiers, optimizing during the lifetime. It is even possible to create a profile from test runs to optimise before runtime.
Thanks for complementing.
As per my understanding, worker_threads will share memory but each will have each own independent event loop.
Kinda, the worker thread can share memory with other threads (made out of the same parent thread) or the parent thread itself. But they just create a new instance of the V8 engine, not another full Node process (where the Node process is who instantiate the event_loop). In Contrast, Cluster in fact instantiates one or more new Node process, for instance they come with it's own event_loop :)
Oh yeah! I see what you mean. Using pm2 is a good implementation of clusters where we could have a node per each core of the cpu.
Thanks for the clarifying about the event loop!
Exactly! 😄
No worries, happy to help! As I said, great work ;)
⚠️ I liked the way you try to clarify the matter, congratulations! I would say that having multiple instances of the V8 unable to communicate and not being fault tolerant only alleviates the problem. 😅
.NET can handle more than 7 million requests per second as of their .NET Core 2.2 back in 2019: ageofascent.com/2019/02/04/asp-net.... 8X faster than Node.js (at the time). .NET has seriously improved performance since then (as of .NET 6): https://www.techempower.com/benchmarks/#section=data-r20&hw=ph&test=plaintext&a=2 (now more than 10X faster than Node.js). Interpreted languages will likely never be able to complete with compiled languages as far as performance goes.
Javascript is Just in Time compiled via V8 engine but yes, still .NET is faster. C# gets JIT compiled via .NET runtime by the way.
The event loop link (nodejs.org/learn/the-nodejs-event-...) explanation does not exists. I think you can updated to this one: nodejs.org/en/learn/asynchronous-w....
Thanks for the great article!
Your descriptions of single thread Vs multi thread is nonsense. If you have a sequence of instructions a b c, then they must be executed in that order. You can't go and process c on another thread before b. Did you mean tasks?
Excellent article Andres.
Thanks @bendev12 !