• Stars
    star
    129
  • Rank 279,262 (Top 6 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 13 years ago
  • Updated over 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Fast non-blocking fibonacci server

node-fib

A little express server that gives you back whatever fibonacci number you ask for

Coming here from Hacker News?

Hello there! You've stumbled across a short script I wrote to see how effective a non-blocking implementation would be for the famous NodeJS cancer also known as calculating the fibonacci sequence recursively.

They key differences from the original algorithm are that process.nextTick is used agressively (probably too agressively), so ensure that the main event loop is not blocked. In addition, memoisation is used which is shared across concurrent and subsequent requests without having to worry about locking.

Obviously there are other algorithms to calculate the nth term of the fibonacci sequence, many of which will be more effective than this one (although I do like how easy it is to memoise this). Some people have already mentioned a few of these in the issues section. As this is a toy rather than a real project I'm unlikely to implement these improvements unless they sound particularly fun or I have some time to kill on a train.

I would encourage anyone with suggestions of improvements to have a go at them yourself, especially if you're not familiar with NodeJS - you may even like it. I would also encourage any similar implementations in non-reactor frameworks as a comparison of the relative merits and disadvantages of event loops vs threads.

Usage

node app.js &
curl localhost:3000/40

Replace 40 with whatever fibonacci number you want

Why?

To point out that implementation of whatever you're doing is far more important than which framework you're using, or whether you're using threads or an event loop to handle concurrency.

Is it any good?

Yes.

> ab -n 10000 -c 50 'http://127.0.0.1:3000/100'
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 127.0.0.1 (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests


Server Software:
Server Hostname:        127.0.0.1
Server Port:            3000

Document Path:          /100
Document Length:        21 bytes

Concurrency Level:      50
Time taken for tests:   2.114 seconds
Complete requests:      10000
Failed requests:        0
Write errors:           0
Total transferred:      1420000 bytes
HTML transferred:       210000 bytes
Requests per second:    4731.49 [#/sec] (mean)
Time per request:       10.568 [ms] (mean)
Time per request:       0.211 [ms] (mean, across all concurrent requests)
Transfer rate:          656.12 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.3      0       5
Processing:     2   10   3.0     10      28
Waiting:        2   10   3.0     10      28
Total:          3   10   3.0     10      28

Percentage of the requests served within a certain time (ms)
  50%     10
  66%     11
  75%     12
  80%     13
  90%     14
  95%     15
  98%     18
  99%     20
 100%     28 (longest request)

Related

Derivative project in python-twisted: https://github.com/zed/txfib

More Repositories

1

ultimate-hot-reloading-example

Hot reload all the things!
JavaScript
962
star
2

transit-immutable-js

Transit serialisation for Immutable.js
JavaScript
250
star
3

skin-deep

Test assertion helpers for use with React's shallowRender test utils
JavaScript
200
star
4

devboard

An interactive visual feedback tool for developing user interface code
JavaScript
87
star
5

mocha-multi

A bit of a hack to get multiple reporters working with mocha
JavaScript
75
star
6

jenkins-groovy-examples

Some samples of groovy scripts used in jenkins automation
47
star
7

ReactNativeFlexboxPlayground

Demo app to make it easy to experiment with flexbox layouts
JavaScript
40
star
8

react-hotkey

A simple mixin for application hotkeys
JavaScript
35
star
9

fluctuations

Yet another flux implementation
JavaScript
26
star
10

checkers

Property-based testing for JavaScript via ClojureScript's test.check
JavaScript
21
star
11

pretty-immutable

Pretty printing for ImmutableJS
JavaScript
12
star
12

cljs-webpack-deps

Trying out using npm dependencies via webpack in clojurescript.
Clojure
10
star
13

terrafiddle

Mini ruby dsl for generating terraform files
Ruby
9
star
14

node_modules

A curated list of beautiful node_modules that I like to use.
Makefile
7
star
15

typescript-xunit-xml

Produce xUnit-style XML output from typescript compiler messages
JavaScript
6
star
16

nodespec

A light-weight RSpec-esque testing framework for NodeJS with pluggable extensibility. I now recommend Mocha
JavaScript
6
star
17

hack-react-app

Zero Configuration, or is it?
JavaScript
6
star
18

fourten

An opinionated Go HTTP Client.
Go
5
star
19

git-mnemonic

Speakable, rememberable translations for git ref hashes
Python
5
star
20

npm-t-shirt

Bringing t-shirts to npm, sort of
JavaScript
5
star
21

react-calendar

Calendar example in React
JavaScript
4
star
22

phptea

A simple, flexible test harness for specifying tests in a SpecBDD style.
PHP
4
star
23

azure-terraform-generate

Generate terraform config from deployed azure resources.
Python
4
star
24

babblog-royale

Babble Royale log parser and viewer
TypeScript
3
star
25

vagrant-provider

Vagrant plugin for provider swapping
Ruby
3
star
26

react-element-to-string

Convert a ReactElement into a nice string useful for debugging
JavaScript
3
star
27

react-testing-workshop

Code for React Testing Workshop at jsconfco 2016.
JavaScript
3
star
28

byte-board

Like a whiteboard, but with bytes.
Elm
3
star
29

webpack-hot-client-overlay

An overlay for webpack-hot-client
JavaScript
2
star
30

present-express

Presenters + Hogan (mustache) for express
JavaScript
2
star
31

node-tracey

Find out how you got somewhere
JavaScript
2
star
32

flow-stuck-repro

JavaScript
2
star
33

q

Fakes stubs and spies for Clojure testing
Clojure
2
star
34

kaniko-publish-orb

CircleCI Orb to build and publish container images to container registries *without* docker.
Dockerfile
2
star
35

node-intro

Presentation and example sources for a NodeJS introduction
JavaScript
2
star
36

connect-hopeful-body-parser

Attempt to parse body data without an Accept header
JavaScript
2
star
37

CanDB

Database for storing potential recruitment candidates
JavaScript
2
star
38

github-cookbook

Chef Library Cookbook for declaring resources on GitHub
Ruby
1
star
39

in-the-loop

Simple pub/sub on a single HTML page - handy for hackday activity feeds
JavaScript
1
star
40

nodeschool-learnyounode

Solutions to nodeschool.io's learnyounode tutorial
JavaScript
1
star
41

raspbian-kiosk-maker

Some ansible-powered steps to getting a super-simple information radiator on a raspberry pi
1
star
42

shared-user-agent

A simple way to click links on one computer and have them open on another
Python
1
star
43

zombie-server

A REST-like HTTP server wrapping zombie.js sessions
JavaScript
1
star
44

merb-breadcrumbs

A simple merb plugin to provide useful hooks for breadcrumb links.
Ruby
1
star
45

epic-trello

An attempt at providing an epic-level view across a trello board.
JavaScript
1
star
46

magic-of-hot-code

Code samples for talk
JavaScript
1
star
47

lein-new-reflection

Clojure
1
star
48

eslint-samples

My standard eslint configs
JavaScript
1
star
49

ribbit

Provides a Module to handle sending notifications to hoptoad.
Ruby
1
star
50

not-talking

Slides for presentation on "Scaling Agile by not Talking to Each Other"
CSS
1
star
51

circles-and-arrows

HTML Canvas based Super-simple State Machine Diagram Tool
JavaScript
1
star
52

defmulti

Flexible JavaScript polymorphism without requiring inheritance or object orientism
JavaScript
1
star
53

tel

Super simple DI for JavaScript, targetted mainly at spec test setup
JavaScript
1
star
54

node-intro-challenge

Short programming excercise as a companion to a NodeJS intro presentation
JavaScript
1
star
55

glenjamin.github.com

Github presence
JavaScript
1
star
56

confident-user-interface-programming

A talk at CodeMesh 2016 by Glen Mailer
1
star
57

emojifight

Hot Module Reloading demo application
JavaScript
1
star
58

video-voting

Video Voting App for youtube movie nights
JavaScript
1
star
59

BehatMultiFormatter

A Behat extension adding a multipage HTML formatter with index and summary
1
star
60

node-controlled-amd

An AMD loader for NodeJS that keeps you in control by using minimal magic. Aimed primarily at loading frontend modules for unit testing.
JavaScript
1
star