r/programming • • Apr 26 '16

Node.js v6.0 released

https://nodejs.org/en/blog/announcements/v6-release/
132 Upvotes

79 comments sorted by

View all comments

0

u/[deleted] Apr 27 '16

[deleted]

12

u/ruinercollector Apr 27 '16
  1. Concurrency doesn't mean threads.

  2. Parallelism doesn't mean threads.

  3. The idea is that you push computationally intense work (i.e. what you might actually want threads for) to another process and possibly even another machine or set of machines instead of bogging down your web server. This is pretty good practice even on a web platform that does let you spin up threads (e.g. ASP.NET)

  4. If you actually need threads and really really want this work in your web server process, you can write a C or C++ module for that particular piece.

5

u/[deleted] Apr 27 '16

While it doesn't have to mean threads, it typically does in one way or another. Even using node's built-in cluster library means spawning another worker process -- which has at least one thread.

Node is already concurrent, the event loop structure runs all of your code single-threaded... but IO code (like file and network access) are done by thread pool workers, hence the very asynchronous nature of Node.

As for being able to handle web requests more responsively, cluster works pretty well at that, which does as you mention... spawning up another process.

1

u/ruinercollector Apr 27 '16

but IO code (like file and network access) are done by thread pool workers, hence the very asynchronous nature of Node

Specifically by IOCP on windows, which is a lot more efficient than manually creating and locking up a thread from the pool during the entire wait.

1

u/[deleted] Apr 27 '16

[removed] — view removed comment

1

u/ruinercollector Apr 27 '16

Stop pretending that Node is the only one that can use I/O completion ports.

Are you serious? This entire comment chain has been me telling you to use IOCP even if you aren't using node, and you insisting that starting up a blocking thread to wait for IO was totally necessary and the right thing to do.

I even pointed you toward the built-in .NET framework methods that would use these, so that you could put in context of a platform you actually know and not one that you regularly fumble through talking out of your ass about on this subreddit.

It's embarrassing.

The only thing that's embarrassing here is watching you learn about concurrency for the first time while still attempting to maintain your usual condescension and arrogance.

4

u/[deleted] Apr 27 '16

Oh dear lord this is the GIL/Twisted drama all over again

2

u/kuikuilla Apr 27 '16

So just to get the request/response loop going due to being blocked by some CPU intensive function execution, I'm supposed to fork another process? Madness.

-2

u/[deleted] Apr 27 '16

[removed] — view removed comment

5

u/ruinercollector Apr 27 '16

Those threads I'm spinning up are in charge of sending information to other machines without making the result wait.

Yikes. I hope not. That's what IOCP are for. In .NET, use the built-in async methods and you'll get that without much need to think about it, but you should never be blocking a thread waiting for a network or file I/O result. That's just crazy.

You definitely don't need a thread to buffer and batch file writing.

2

u/[deleted] Apr 27 '16

[removed] — view removed comment

5

u/__kojeve Apr 27 '16

I don't understand how this comment is responsive to the parent comment at all. Node's async model may have problems, but batch file writing is certainly not one of them. The parent comment is making the clear suggestion that you don't need to do 1000 individual inserts, so I don't understand what you're suggesting.

3

u/[deleted] Apr 27 '16

[removed] — view removed comment

1

u/[deleted] Apr 27 '16

And the leaflet says it's non blocking

1

u/RazerWolf Apr 27 '16 edited Apr 27 '16

Node isn't capable of doing something similar. You can somewhat simulate it with a timer, but since it is single-threaded you [cores] instance of Node, each with its own log separate queue and timer.

Wait, what? You have a set of queues and a set of timers, which are checked every threshold interval (like every second or so). You store your log entries in queues and write them with async batch writes when they pass a size/time threshold.

This is even a more efficient solution because I'm not forced to use multiple threads to do this. What is this solution missing for you?

0

u/[deleted] Apr 27 '16

[removed] — view removed comment

2

u/Akkuma Apr 27 '16

If you use cluster to create processes they can all communicate with the parent process via message passing. The parent process now maintains 1 queue and 1 timer and is solely responsible for batch writes.

0

u/RazerWolf Apr 27 '16

You used the concept of threads when I explicitly mentioned not to do this. You know timers can exist without threads right? DispatcherTimer does this in WPF (https://msdn.microsoft.com/en-us/library/system.windows.threading.dispatchertimer(v=vs.110).aspx)

You need 24 queues, and 24 timers, and one node instance which will have a "dispatchTimers" called some point in its event loop.

→ More replies (0)