-
Notifications
You must be signed in to change notification settings - Fork 285
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Does NodeJS have any plans for shared memory? #560
Comments
Not at the moment. It's not completely out of the question but:
|
Thanks for the info :) Wasn't expecting such a fast answer. Thanks for the alternative of a native module, too! |
Also, just fyi: https://github.com/audreyt/node-webworker-threads :) |
Thanks @addaleax ! I was under the impression those threads still shared memory, but sounds like I'm wrong. Also I realized that I kinda completely forgot about https://nodejs.org/api/vm.html and this whole thing is probably just a derp. Thanks for setting me straight! |
I don't know what a derp is, but the VM API is completely unrelated to threading or concurrency. |
But it does allow executing code in a separate context. If a threading
library used it to isolate the memory that different threads have access
to, they could still pass sharedArrayBuffers between those threads'
contexts. At least I think they could - my understanding of all of this is
very high level and I'm sure there's a devil in the details.
…On 5 Apr. 2017 00:20, "Sam Roberts" ***@***.***> wrote:
I don't know what a derp is, but the VM API is completely unrelated to
threading or concurrency.
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
<#560 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAmkBH-OOra8RQ0nYRlXic8KUJhWFf_Yks5rslGYgaJpZM4MyvaS>
.
|
@hitsthings Contexts are tied to their isolates, and those are not thread-safe. That is, you can't have two contexts in the same isolate and access them from different threads. (You can pass SharedArrayBuffers between contexts but there won't be any real concurrency, it'll be strictly sequential.) |
@hitsthings I would highly recommend just using different node.js processes instead of the node-webworker-threads lib; unfortunately the node-webworker-threads lib is not very stable and has major API deficiencies last time I checked. |
Thanks, I get that separate processes is the current standard. I posted this originally because shared memory seemed like a great opportunity for threads. Most cases are good with share-nothing concurrency which is what you get with processes (and anything you want to pass between them is slower over IPC afaik). I had a case a few years back where I was trying to implement real-time tracking and mapping for nodecopters (for fun, so meh on stability). One big performance hurdle was that I needed to pass large chunks of image data, edge detection data, etc between processes. That's where threads would help since I wouldn't have to pass anything around to access it in multiple threads. To be clear - I'm not asking about doing anything in production code. Was just curious about whether there were any ideas/plans for threading with sharedArrayBuffers in node that might help me with problems like that. Ben - thanks for the VM clarification. |
you can share memory between processes as well as between threads, bunch of stuff on npmjs, I vouch for the quality of none of it :-) https://www.npmjs.com/search?q=shared+memory |
Would love to see some sort of equivalent for Workers, transferable objects and SharedArrayBuffer's.
As it currently stands it is easier to take advantage of all cores and memory in the browser vs node. Which makes me sad :(. |
@icodeforlove Hey, just so you are aware: nodejs/node#13143, https://github.com/nodejs/worker. :) |
@addaleax talk about "hitting the nail of the head" 😄 |
@ORESoftware, @addaleax, That's not shared memory. It's using message parsing which is slow. |
I've been waiting for this for a loong time, when will they decide to implement this? Lack of shared memory capability is a dealbreaker, making me choose Java instead of Node for server apps. |
Linking this one with 14158 which is potentially capable of covering this requirement. |
Just to make that clearer — nodejs/node#14158 is a discussion about better supporting the embedding of node, in-process into other apps. It covers the use case of single process memory sharing, and also allows the embedder to implement inter-process memory sharing. |
I think the NodeJs arhitecture is not for threads, the is 2017, not like 1990 when they created Java some other languages. Thread is slow like hell. Threads are dead. |
Isn't SharedArrayBuffer part of V8? Apparently not. |
Which is obviously a pretty wonky hack to work around missing features. |
that's true, just for me it never be needed. |
After people get used to taking advantage of it in the browser, the sentiment will go pretty quickly from 'who needs this they must not know how to Node' to "why the heck didn't they implement this already". |
SharedArrayBuffer, haha, when we are building cluster system in different contents with shared data :) |
@p3x-robot Re "haha" Meaning? |
@runvnc, re "running headless Chrome on the server"; but what if ⨕ there's Oracle and its billions of $$ on proper Java support for real shared memory? |
While it's not a general solution, I ended up writing a module (in C++) to handle shared memory. It produces objects backed by a key-value store kept in shared memory. |
i think redis is faster then a file based solution. it is already there, why you guys want threads and share buffers, when process-es are faster and all people are thinking like this is |
Direct access to (shared) memory is definitely faster than either Redis or |
It is telling people continue to comment on this issue more than 8 months after it was closed. Experimentation with parallelism and shared memory in Node has been ongoing for years, and there is a diverse set of implementations for curious programmers to evaluate and use. I created a List of Parallel JS Projects that compares the various approaches. Some of these tools may be useful until there is built-in support. |
@p3x-robot, re "process.send is fast"; Ever did graphics and other baremetal code before? Re "why"; Because whatever's fast today is slow tomorrow as demands can only go up. Fact is NodeJS will remain a "kiddy" tool until it can do proper multi-processing. |
if you want speed, you use c++, if you want functional, use js, that's all. why do i would want to speed out of js??? it is a VM.... not how you receive the data, but have you process big large of data. i am settled with js with c++ if you receive with shared memory or with process.send or a file, db, not so big problem. i think i never think about threads etc. etc. etc. we all think on 1 server. how do you use shared memory with different servers??? i think, it is an interesting QUEST!!! 🔢 |
@p3x-robot , NodeJS wants to replace Java/C++/PHP/C/ASM/etc (other "server-side" environments). But it simply can't until it can do proper multi-processing. Re "how do you use shared memory with different servers"; It can be built the same way everything else is built as long as you first have shared memory on a single server. Without which, anything built will be slow. |
@allenluce Still people are suffering here :D My solution uses shared memory device shm (Linux, macOS / virtual shared memory page (Windows) based on my project libsharedmemory --> node-libsharedmemory If we'd merge our code bases, we could simply use my lib as the backend instead of your impl. and get the holy grail of a real shared memory for Node.js. Do you or anyone else have time and energy to join? :) |
So this API is being added to JS that allows different execution contexts to share a chunk of memory safely with interleaved access.
Meanwhile the Web Worker spec already exists for creating these separate execution contexts.
I know there are pre-existing user space modules for web-worker implementations. But they either 1) use separate processes for each thread (and thus can't really share memory well), or 2) they literally expose all memory to all threads and thus accept all the chaos that other multithreaded languages often have.
Combined, the Web Worker and Shared Memory APIs seem like a solid infrastructure to build multithreading on. There would be no bad interaction with old code since the old code would have to opt in to using the shared buffer (or a bad dev would have to pass a shared buffer to the old code and then write to it). Is there any plan for making use of shared memory and web workers in Node?
The text was updated successfully, but these errors were encountered: