Live data from Hacker News

Ask HN: Event loop vs. Threads

news.ycombinator.com

31–36 of 36 posts

Re: Ask HN: Event loop vs. Threads

#31
WebWorkers are testament to the lack of mutual exclusivity between event loops and threads.

http://en.wikipedia.org/wiki/Web_worker

https://developer.mozilla.org/En/Using_web_workers

Once you start doing any heavy lifting or large amounts of parallelizable tasks you will find yourself drifting towards the threading model from within your event loop.

Re: Ask HN: Event loop vs. Threads

#32

I 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…

+1, if your job is number crunching, stay the hell away from JavaScript as it will bite you in the ass. http://stackoverflow.com/questions/307179/what-is-javascript...

You will find these problems have been solved: https://github.com/substack/node-bigint

Re: Ask HN: Event loop vs. Threads

#33

WebWorkers are testament to the lack of mutual exclusivity between event loops and threads. http://en.wikipedia.org/wiki/Web_worker https://developer.mozilla.org/En/Using_web_workers Once you start doing any heavy lifting or large amounts of parallelizable tasks you will find yourself drifting towards the threading model from within your event loop.

Unfortunately Node's implementation of web workers uses external processes and serializes all the data as JSON. This makes them considerably slower than Chrome's implementation of web workers, which use threads.

In general if you're doing something compute-bound, Node's single threaded event loop isn't going to help you.

Depending on your performance requirements you might take a look at LMAX and Disruptor. At the very least you could be writing Java instead of C++

Re: Ask HN: Event loop vs. Threads

#34

Hi, 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.

It probably depends, but the cost of creating a heap allocated closure and then running it and deallocating it can be quite high against the cost of 2 context switches.

Re: Ask HN: Event loop vs. Threads

#35
Hi villagefool,

so you've lots of legacy C++, then I'd suggest you better stay there and rewrite performance critical parts effectively with ANSI C code.

Honestly I think StackOverflow is a better Platform for questions like this. You'll see that the answer to your question is: "Yes, use both." source: http://stackoverflow.com/questions/953428/event-loop-vs-mult... I think YCombinator is more of a community of entrepreneurs and investors, who can give you concrete advice on questions regarding technology decisions, but even though you'll also get quality answers to to CompSci questions, those type of questions are betters answered over there at SO.

Coding-Standards exist to allow "easier maintenance" of your application. You better check if there's an ISO-Standard for your branch, that defines the best practices in your business.

Here are "Google's C++ Guidelines" for example: http://google-styleguide.googlecode.com/svn/trunk/cppguide.x... but you'll need Coding Guidelines that fit better to your branch. Maybe you'll find some guidelines on the pages of the SEC http://www.sec.gov

I think there are people who automatically build up prejudices when you say "App" to something large like a Trading-Platform, but that mustn't be the case. I believe there are also people who'll think that you know what they want when you talk about complex things in the form of an "App" (something they know). Just be aware of it.

Can you answer me a question? How is Cuppertino, CA for a Software-Developer? (I won't work for Apple, just about to stay there for a while)

Post reply on HN