Handwritten Text Recognition for manuscripts and early printed texts
Into the Wild with Node.js and Web Apps
1. INTOTHE WILD WITH
NODE.JS AND WEB APPS
Node.jsTalk at Klout, 2012
Chris Bumgardner
Friday, April 20, 12
2. ME
• Co-founder and Chief-Programmer of AskYourUsers.com
• @chrisbumgardner and cbumgard@gmail.com
• github.com/cbumgard
• My first ‘real’ production web app in Node.js
• Invite only beta, going live this week.
Friday, April 20, 12
3. THE STACK
• Node.js
• Express
• MongoDB
• Redis
• Apache Solr
• Nginx / Ubuntu 11 / 2 x LinodeVPS
Friday, April 20, 12
4. CONFIGURATION
• Partition your configuration by environment.
• E.g. Config[process.env.NODE_ENV]
• We have 3 environments: 2 dev and 1 production.
• Environment is top-level namespace (‘dev’,‘production’, etc)
for everything, including db. Keeps worlds from colliding.
• Makes life easy
Friday, April 20, 12
5. CONFIGURATION 2
• dev env 1: sessions in memory, clean db each start.
• dev env 2: persistent sessions & db, ssl.
• production env: aggressive caching, ssl, live payments, clustered,
fancier logging (more later), email/sms notifications.
Friday, April 20, 12
6. LOGGING
• Log early and often.
• Using Winston with the MongoDB transport.
• MongoDB logging: fast writes; pass json objs in log msgs; easy
ad-hoc queries; easy lru via capped collections.
• Client logging from browser: caught and logged to Google
Analytics as custom event. Easy monitoring/aggregation.
Friday, April 20, 12
7. DEPLOYMENT
• Custom CI system in node that responds pushes to github
• Post-Receive service hook. Github POSTs to us after a push.
• CI will pull code if it’s the right branch (say ‘staging’), restart,
and send SMS.
• Easy and low touch.Texts from your node are nice.
• Refactoring into a more modular/decoupled hook.io system.
Friday, April 20, 12
8. ALSO
• In development: use ‘nodemon’ to start server.
• Watches all files in project and restarts node if anything
changes.
• Great with persistent sessions, test changes immediately.
• In production: use ‘forever’ to start server as daemon. Restarts
node automatically if it crashes. Runs in background. Nice CLI.
Manages stdout/stderr logs.Tracks multiple processes.
Friday, April 20, 12
9. CLUSTERING
• In production, use ‘cluster’ module to fork separate node per
core
• App-wide initialization: if cluster.isMaster
• Otherwise per-proc initialization
Friday, April 20, 12
10. DEPENDENCIES
• Found out the hard way to control node, npm, and dependent
module versions.You don’t want to push a change to
production and have npm barf. No bueno.
• Keep them the same on all machines.
• Use npm in development.
• In production I recommend bundling/controlling the deps and
versions explicitly.
Friday, April 20, 12
11. PROFILING
• ‘ab’ is your friend.
• don’t forget ulimit.
• Joyent has great video on profiling with dtrace.
• ‘nodetime’ module: great in development, but my server got
hosed when I tried it in production. Probably user error.
Friday, April 20, 12
12. THANKS!
(you can email me at cbumgard@gmail.com)
Beyond the Closed Beta, Node.js from code to
production (at scale)
Node.js ++ (Serverside Javascripters) Club SF
Friday, April 20, 12