Live data from Hacker News

Node-fib: Fast non-blocking fibonacci server

github.com

1–10 of 124 posts

Re: Node-fib: Fast non-blocking fibonacci server

#5
I wonder why I don't often see folks directly computing Fib(n) using the equation given in SICP exercise 1.13:

Fib(n) = round(φ^n / sqrt(5)), where φ = (1 + sqrt(5)) / 2.

Cites:

http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-11.html...

https://secure.wikimedia.org/wikipedia/en/wiki/Fibonacci_num...

Re: Node-fib: Fast non-blocking fibonacci server

#8
Author here, didn't really expect this to get picked up anywhere but since it has I'd like to point out the idea was to demonstrate that computationally expensive algorithms can be split across multiple iterations of the event loop to avoid blocking it.

In this case concurrent requests take advantage of each others' memoisation, which would be somewhat trickier to do with threads as you'd probably need to worry about locking.

Re: Node-fib: Fast non-blocking fibonacci server

#10
I'd like to point out that this uses important improvements over the naive Ziuba's strawman version: memoization and callbacks using the event loop. The callbacks improve concurrency, allowing a single process/thread to multitask requests, and memoization reduces total time spent per request.

Actually, if the async lib memoization facility shares values between requests, which seems quite sure to me, all requests but the first one are served from its cache in the test the author uses as example. This still doesn't highlight any strength of node.js IMO, asides from the easy shared memoization. It could be translated to Tornado-web, an async Python framework, almost literally.

Post reply on HN