EDIT: more details about the application - it is a trading app that communicates with multiple sources at high rates to gather information and send commands, but it also does quite alot of number crunching.
Ask HN: Event loop vs. Threads
1–10 of 36 posts
Re: Ask HN: Event loop vs. Threads
#2Tk has had an event loop based paradigm from its start, and straight Tcl also has the ability to explicitly enter an event loop.
Re: Ask HN: Event loop vs. Threads
#3Re: Ask HN: Event loop vs. Threads
#4From 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 this like streamlinejs, Haskell's continuation monad transformer and to a lesser degree, promises/futures/deferrables. If you decide to stick with callback passing, then a good knowledge of functional programming is useful as all loops require recursion. If your application is single threaded, that tends to make finding race conditions easier, but on the whole I'd say it's harder to write good asynchronous code than it is to write good synchronous code.
Re: Ask HN: Event loop vs. Threads
#5Executive note : - if event model : have all state transition models DOCUMENTED ; - if multi-threading : once you have shared a context (config), uncouple all the data passed to your thread (and handle a SIGHUP to reload the conf safely).
Event model done wrong will cry havoc on your code maintability the same as multitreading done wrong.
Re: Ask HN: Event loop vs. Threads
#6As for efficiency: Threads and Processes are what the OS offers. Any parallel programming model will have to use these in one way or another, so does Node.js. The discussion is kind of similar to assembly vs. high level programming languages. You can always write an assembly program that is as fast as the program compiled from a high level language. However, it will take you a lot more time to write it.
In the end, it comes down to choosing the right tool for the job. Therefore you should try find out what people with a similar job choose and what their experiences are; and also for which job a framework has been created.
E.g. Node.js is good at a job where there are lots of events and I/O is involved. If your job is number crunching, then Node.js is the wrong tool.
Re: Ask HN: Event loop vs. Threads
#7Re: Ask HN: Event loop vs. Threads
#8What does that result in?
- If you have lots of code that is blocking on IO operations (like file/socket) then you will see some improvements in performance. - If your code utilizes your cpu, then node.js will be slower then your current thread implementation.
Re: Ask HN: Event loop vs. Threads
#9http://sheddingbikes.com/posts/1280829388.html
"epoll is faster than poll when the active/total FD ratio is 0.6."
Re: Ask HN: Event loop vs. Threads
#10I think a lot has been written on why threads, locks etc. are hard to program (= i.e. hard to maintain) and are considered the "assembly of parallel programming". As for efficiency: Threads and Processes are what the OS offers. Any parallel programming model will have to use these in one way or another, so does Node.js. The discussion is kind of similar to assembly vs. high level programming languages. You can always…