4 ms·
This is the key paragraph: "When problems resist parallelization or have no appreciable latency to hide, the third way that concurrent execution can improve pe
by discreteevent 14y ago
This is the key paragraph:
"When problems resist parallelization or have no appreciable latency to hide, the third way that concurrent execution can improve performance is to increase the throughput of the system. Instead of using parallel logic to make a single operation faster, one can employ multiple concurrent executions of sequential logic to accommodate more simultaneous work. Importantly, a system using concurrency to increase throughput need not consist exclusively (or even largely) of multithreaded code. Rather, those components of the system that share no state can be left entirely sequential, with the system executing multiple instances of these components concurrently. The sharing in the system can then be offloaded to components explicitly designed around parallel execution on shared state, which can ideally be reduced to those elements already known to operate well in concurrent environments: the database and/or the operating system."
Even if you can't use the database or os and still want to get "multiple concurrent executions of sequential logic" then just use a message queue. That's what Go provides, what blocking queues in java provide, what most actor based systems provide (e.g. Akka, Dart), what unix pipes provide and what all kinds of inter process messaging systems provide. Most of your code can as impure, sequential and lock free as it always was. You only have to make your messages immutable.
- kaoD 14y agoAnd that's why I love Node.js: the single-threaded concurrency (or should I say non-concurrency?) is built-in in the execution model. Building your architecture decoupled from the ground up is useful, and Node.js does a great job at it. I found Redis is an awesome middleware for MQ purposes. Its builtin PubSub system, blocking POPs and amazing speed make it a perfect fit. But beware: it's easy to get it wrong and make the system a tangled mess of messages. Just make sure the message dispatch overhead is worth it.
- fforw 14y agoIs node actually able to use more than one core now?
- DonPellegrino 14y agoIt has been able to for a while! Check out the cluster module, processes listening to the same port are load balanced and communication between processes is obviously (since each process only has 1 thread due to the event loop) done by message passing.
- kaoD 14y agoTechnically spakeaing: no, and it never will. Single-threading is by design, so the best bet is to run several processes, each using one core (see the other answer to your comment).