This is an example of a small real world-ish program. It contains an import script (import-npm.js
) that imports the npm registry metadata into a mongodb running on localhost and a series of servers showcasing problems and improvements.
The mongodb will contain two collections slow
and fast
which contain the same data, except fast
will contain an index for doing fast lookups and slow
will not.
If you have docker installed you can install and run a mongo container by doing.
docker pull mongo
docker run -it -p 27017:27017 mongo
Some platforms may give a Docker error and require the following command instead
docker pull mongo
docker run -v $(pwd)/datadir:/data/db -p 27017:27017 -d mongo
Then to import some data
# note you can just run this for a bit and kill it
npm install
node import-npm.js
There are 4 iterations of a server that returns the 5 latest and 5 oldest updated modules on npm.
- Returns the latest and oldest 5 modules from an unindexed collection
- Returns the latest and oldest 5 modules from an indexed collection
- Returns the same as
2
but does the queries in parallel. - Caches the result from
3
in 5s in an LRU cache.
Each should produce different Bubbleprof results indicating the async profile of each. Running 1
you should see a ton of latency, running 2
you should see much more throughput, and running 3
you should see a few more branches in the async graph.
To run the first one do:
clinic bubbleprof --autocannon [ -c 5 -a 500 / ] -- node 1-server-with-no-index.js