Infrastructure

Notes from Node.js Interactive 2017

At Busbud we are big fans of Node.js and we use it for most of our projects: frontend applications, backend APIs, background workers…

Busbud covered my trip to the Node.js Interactive 2017 conference in Vancouver to learn more about the future of Node.js and to talk with passionate developers of the community.

Here are some notes I took during some of my favorites talks:

Keynote

The world runs on Node.js. Everybody is using Node (see more here).

Node 8 with a new version of V8 is going to be a major change for the Node.js platform.

Node is a first-class citizen in V8.

In the past the V8 team at Google was really focused on Chrome but
from now on the team is embracing Node.js:
it has dedicated people to improve Node.js support in V8, and no commit can land in the project if it is breaking Node.

Node.js Performance and Highly Scalable Micro-Services – Chris Bailey, IBM

Chris Bailey presented the tooling, and the instrumentation necessary to run highly scalable microservices.

It is nice to see many standards appearing around Node.js microservice deployment:

  • Docker to build containers
  • Kubernetes to run containers in production
  • OpenTracing and Zipkin to collect metrics accross multiple services
  • Prometheus for monitoring

He also presented the appmetrics module which allows you to collect a lot of Node.js metrics and run CPU profiling. There are integrations with all the major monitoring systems (statsd, promotheus, etc.). Combined with the dashboard from appmetrics-dash, it is a good way to start monitoring your application perfomance.

You can also use yo nodeserver to get a boilerplate Node.js microservice ready to deploy with all the instrumentation.

Slides

The Node.js Event Loop: Not So Single Threaded – Bryan Hughes, Microsoft

Bryan Hughes talk, about what part of your code is executed in the node main thread (JavaScript code and C++ sync code), what is executed in Node thread pool (async C++) and that some modules are using the C++ async primitive…
Modules using C++ primitives are different depending of the platform. For example, child_process is using the C++ async primitive on Unix systems but thread pool on Windows.

Take Your HTTP Server to Ludicrous Speed, Matteo Collina, nearForm

Matteo Collina presented a simple way to profile and benchmark a server, using 0x (a tool to easily generate a flamegraph) and autocannon (an HTTP benchmarking tool).

He then showed us how to construct step by step a blazing fast HTTP framework:

  • replace JSON.stringify with fast-json-stringify schema-based JSON rendering;
  • find-my-way a router built on a radix-tree;
  • finaly presents Fastify that implements a lot of optimizations for performance.

For most uses, however, express is fast enough, very popular and well supported.

Slides

High Performance JS in V8, Peter Marshall, Google

Peter Marshall presented how the JavaScript execution pipeline changed in V8 with the arrival of Ignition and TurboFan.

Forget all the tricks you know about optimizing JavaScript code for V8: the best way to optimize code for newer versions of V8 is to not optimize at all and just write pragmatic JavaScript.

We also learned how V8 tries to optimize hot code (i.e. code frequently runned).
The old optimizing compiler was doing too much guessing and premature optimization, causing it to be often wrong and actually creating deoptimizations. The new optimizing compiler TurboFan resolves this problem by guessing less.

Slides

Understanding and Debugging Memory Leaks in Your Node.js Applications – Ali Sheikh, Google

Debugging memory leaks is a problem that we had multiple times at Busbud, I was really excited to attend this talk.

After a brief introduction:

Don’t want any memory leaks? Don’t write any code or use anybody else’s!
Memory leaks happen when objects expected to be short-lived get attached to long-lived ones.

Ali goes on to talk about how it is hard to debug memory leaks, which metrics you need to monitor to detect JavaScript leaks (growing rss and growing heapTotal/heapUsed) and native leaks (growing rss, but stable heapTotal/heapUsed).

He showed us the tools available to detect and fix memory leaks:

  • Heap snapshot
  • Allocation Timeline
  • Sampling Heap Profiler (Doing a heap snapshop on a production environment is going to badly impact your application perfomance, the Sampling Heap Profiler will allow you to profile your application with very little performance impact)

What you need to remember from this talk: leaks are going to happen, be prepared and try these tools.

Slides

Conclusion

The Node.js Interactive 2017 was a great event, and I would like to thank the organizers for their hard work. It was a great occasion to meet the Node.js community and talk with other passionate actors of the ecosystem.

Source: Busbud engineering