If one of my developers posted something like this, I would fire them on the spot. You've got a "lot of legacy C++ code", and it seems like you're just randomly deciding whether or not to port it. You're basing this decision not on measurement, team considerations, or the needs of your project. Instead you're soliciting opinions from random people on the internet on what is a very religious issue. If you have problem…
Ask HN: Event loop vs. Threads
21–30 of 36 posts
Re: Ask HN: Event loop vs. Threads
#22And "threads" is two things. There's programming in a threaded style, and there's using native operating system threads. They don't have to go together. For example, if you use a green thread library, you end up with the exact same benefits and limitations as an event loop, but with simpler, easier to understand code. A really good thread library could then handle multiplexing green threads over OS threads to get you parallelism too (see haskell).
Re: Ask HN: Event loop vs. Threads
#23I would view Node.js as an effective tool for leveraging js/v8. What's attractive for me when prototyping is throwing js/HTML UI over the top without having to switch gears. Look at raw node as an IO multiplexer and dispatcher but not a compute capable platform. The GC is weak for large data sets and the CPU efficiency is extremely poor for any heavy processing - very hard to manage your cache lines efficiently. Node sweet spot is packet and stream switching in webby stacks where the solid http, ssl and so forth are invaluable. Check out fabric (I forget the name) if you want to look at extracting more from JavaScript.
Suggest you check out LMAX and kx systems. And think how close you can get to a pure event sourced or stream processing model.
You will need the equivalent of one thread per (hyper)core to maximise effective instructions per clock - whether you need to do that will depend on your sustained memory bandwidth. So there a few C/C++ threads is not necessarily a bad thing.
Its possible to build a world class system in erlang with custom DSP, FPGA logic or using a GPU farm if you have the budget. This is the approach I would use if you have millions of decision sources.
If you want to maximise performance on x86 with a simple code base - and leverage SIMD it's hard to beat a combination of intel fortran and intel C/C++ compiler. You can roll your own messaging layer and put the compute node code in fortran - where you'll get great AVX throughput out of ifort.
Re: Ask HN: Event loop vs. Threads
#24I am extremely proud of my recent decision to rewrite it in JavaScript and use Node.js. In the C implementation, I used standard FS functions (e.g. unlink, fwrite, fread) and of course, they are synchronous. In order to optimize the I/O, the entire daemon needed to be rewritten to use threads for the basic worker units, which were at least 5-6, each doing a very simple job. The alternative was to use async FS library in C, but I had to name every single callback.
So I scratched the C code and rewrote the daemon in Node.js. It is much faster because it manages to utilize the system resource much more efficiently, and the code is 3-4 times smaller.
The point is. If you have to do a lot of computation, DO NOT switch to Node or DO switch to Haskell. If you simply have to manage I/O operations, writing in Node might actually decrease complexity.
Re: Ask HN: Event loop vs. Threads
#25Earlier quoted context omitted.
Really not sure, why someone voted this down? The only open experiments on the issue of threads vs. events - at least I don't know of any other.
That has nothing to do with threads vs events at all. It is Zed going "I am going to make up some imaginary fallacies about poll and epoll and then prove them wrong, by proving epoll does exactly what it says it does". These are both ways of checking file descriptors for activity, which says nothing about threads vs event loops vs cps.
Poll usually is run with threads on incoming connections/work, while epoll is keeping conections sleeping and wake up on incoming work. So in which way does this have "nothing to do with threads vs events at all"?
For sure the ratio of sleeping vs. active connections is important in the discussion on node.js model vs. a thread pool with a thread-per-connection setup. If you have very few active connections, poll and a thread-per-connection setup is more efficient (which does say nothing about the ratio of threads per CPU, context switches etc.), if you have a high number of inactive connections, say server-push or chat scenarios, event based connections are more efficient. The OP asked for efficiency.
I don't think the node.js is in any way relevant or efficient for event queues / single thread setups in high throughput scenarios like LMAX where poll/epoll is not relevant. But for node.js, poll vs. epoll setups are highly relevant as they show e.g. node.js vs. standard thread based behaviour.
Re: Ask HN: Event loop vs. Threads
#26Hi, I work at a company that makes heavy use of event loops. I'll try to accurately convey what I know: From an efficiency standpoint, using event loops requires much less memory, but marginally more CPU time than threaded approaches. In terms of maintenance, you're essentially writing your programs in continuation passing style which means error handling is explicit everywhere. There are tools that allow you to hide…
At high concurrency, I'd argue you will probably end up being more cpu efficient as well. The cost of context switching effectively larger frames and getting into and out of privileged mode can get expensive.
Re: Ask HN: Event loop vs. Threads
#27They have incoming work, I/O for incoming and outgoing work is done multi threaded while work on events is single threaded.
The architecture is quite clever as more than one event processor can work on the data structure and event processors can have dependencies on each other. Independent processors can race past each other.
It was written for trading and might be portable to C++, but if you consider switching to JS it might also be ok for you to switch to Java. Their framework is called Disruptor and open source
http://code.google.com/p/disruptor/
"LMAX aims to be the fastest trading platform in the world. Clearly, in order to achieve this we needed to do something special to achieve very low-latency and high-throughput with our Java platform. Performance testing showed that using queues to pass data between stages of the system was introducing latency, so we focused on optimising this area."
Re: Ask HN: Event loop vs. Threads
#28Re: Ask HN: Event loop vs. Threads
#29Earlier quoted context omitted.
That has nothing to do with threads vs events at all. It is Zed going "I am going to make up some imaginary fallacies about poll and epoll and then prove them wrong, by proving epoll does exactly what it says it does". These are both ways of checking file descriptors for activity, which says nothing about threads vs event loops vs cps.
Events can either mean single-thread/event queue (like the LMAX architecture), or async/sleeping with wake up on event trigger. Or both. Poll usually is run with threads on incoming connections/work, while epoll is keeping conections sleeping and wake up on incoming work. So in which way does this have "nothing to do with threads vs events at all"? For sure the ratio of sleeping vs. active connections is important in…
Poll and epoll are trivial implementation details in both cases. Nobody is going to be choosing threads vs event loops based on poll vs epoll, you are using one or the other in both cases, and it is no more relevant to the decision than what you had for breakfast in either case.
Re: Ask HN: Event loop vs. Threads
#30Most developers with no background in electroncis do not understand asynchronuous paradigm : Transitions = factorial(state). In best case if they don't confuse states and transitions (wich is common) you'll end up with a spaghetti code where goto are replaced with callbacks on events. In common case they will make intricated state models without making the docs (state transition diagrams are a MUST have (like RFCs on…
> Transitions = factorial(state). In best case if they don't confuse states and transitions (wich is common) you'll end up with a spaghetti code where goto are replaced with callbacks on events. Hey could you expand on this? I don't understand what you mean by transitions = factorial(state) and why this leads to spaghetti code when you confuse state and transitions.
So I may have a little over stated the number of transitions. :/ (what an idiot)
* 7 states 49 possible transitions, * 8 states 64 possible transitions.
Possibilities are increasing in a more than polynomial way, with a brain that can remember at most 7 items in memory.
A good example of a state transition diagram is in section 7.2.2 http://www.ietf.org/rfc/rfc3720.txt
Soz, for miscalculating.