jaclar / banode-node-migration-0.10

Slides from my March BANode Talk

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Migración de node 0.10.x a 4.x.x LTS en produccion

Node in Production

Node VersionCountPercentage
0.10.x120
0.12.x120
io.js120
4.x LTS120
5.x Stable120

./lts-schedule.png

Migration

The main challange is the API change

Migrating from node 0.10.x to …

  • 0.12.x - lame!
  • 4.2.x - yes!
  • 4.4.1! - wait?! when did this happen?

Packeges to update

Bcrypt

A simple version bump did the trick. (thanks nan!)

Redis/HiRedis

A simple version bump did the trick. (thanks nan!)

MongoDB

The MongoDB driver was the biggest issue. There are 2 major releases of the MongoDB driver:

  • 2.x
  • 1.x

We were still on the 1.3.x release train..

  • native BSON driver wouldn’t compile on 4.x
  • new methods (updateOne, updateMany, etc) are introduce in 1.4.x
Driver/Node.js0.10.x0.12.x4.x
<= 1.3.15yesno (tests failed)no (no native BSON
^1.4.39yesyesno (no native BSON)
^2.0.39no (tests failed)yesyes

Conclusion:

We couldn’t go straight from 0.10.x to 4.x. A short pitstop at 0.12.x was necesarry. The new method names helped to detect code which wasn’t migrated yet.

New Methods

insert
  • insertOne
// before
db.collection("whatever")
    .insert(data, {"w": 1}, function (err, doc) {

        console.log(doc[0]._id);
    });

// after
db.collection("whatever")
    .insertOne(data, {"w": 1}, function (err, result) {

        console.log(result.ops[0]._id.toString())
     });
  • insertMany
// before
db.collection("whatever")
    .insert([data0, data1], {"w": 1}, function (err, doc) {

        console.log(doc[0]._id);
        console.log(doc[1]._id);
    });

// after
db.collection("whatever")
    .insertMany([data0, data1], {"w": 1}, function (err, result) {

        console.log(result.ops[0]._id)
        console.log(result.ops[1]._id)
    });
update
  • updateOne -> Trivial
  • updateMany
// before
db.collection("whatever")
    .update(query, update, {w:1, multi: true}, function(err, updateCount) {
        console.log(updateCount);
    });

// after
db.collection("whatever")
    .updateMany(query, update, {w:1}, function(err, result) {
        console.log(result.matchedCount);
    });
remove
  • removeOne -> Trivial
  • removeMany
// before
db.collection("whatever")
    .remove(query, {w:1, multi: true}, function(err, updateCount) {
        console.log(updateCount);
    });

// after
db.collection("whatever")
    .removeMany(query, update, {w:1}, function(err, result) {
        console.log(result.matchedCount);
    });

Testing

  • mocha/chai
  • Codeship for continous integration
  • indepentend staging environment for manual testing

Tools

Results

ES6 FTW

  • template strings -> great for logging
  • const/let

=> Arrow Functions!

  • all the other ES6 goodness

v8’s better memory managment

Memory usage drop 0.12.x to 4.2.x ./memory-short.png

Memory profile 0.10.x -> 0.12.x -> 4.2.x ./memory-long.png

v8’s performance improvements

@thlorenz run some nice benchmarks on node 0.10, 0.12 vs. io.js http://thlorenz.com/benchgraph/#linux-arrays

Ready for the future!

  • Node from 4.x onwards has a much more stable and predictable release train.
  • Hopefully we won’t have to go through such an major update again.

References

Monitoring

What to measure?

OS Specific

  • CPU (System vs. User)
  • Memory
  • Network (in/out)
  • Disk I/O ?

App Metrics

  • request count/througput
  • response time (internal/external)
  • log aggregation
  • Event Loop
  • Custom App Metrics

Database

  • Query types
  • Queries per second
  • Slow queries

Tooling

Logging

  • Papertrail
  • Google Cloud Logging
  • Bigquery

Graphing

  • Librato
  • Google Cloud Monitoring

App performance

  • New Relic with custom metrics

https://docs.newrelic.com/docs/agents/nodejs-agent/supported-features/nodejs-custom-instrumentation

  • Opbeat (getting better)

Cool Ideas/Recomendations

Any Questsions?

Twitter: @jaclar Lars Jacob

  • I am at -

About

Slides from my March BANode Talk