There is no doubt that Node.js is one of the fastest growing platforms today. It can be found at start-ups and enterprises throughout all industries from high-tech to healthcare.

A lot of people have written about the reasons for its popularity and why it has made sense in “digital transformation” efforts. But when you implement Node.js, do you have to replace your mainframes and legacy software with a shiny new Node.js-based microservice architecture?

Let’s zoom out and walk in the shoes of those who oversee the whole digital value chain: operation and performance teams. What challenges do operation and performance teams face today when they begin to implement Node.js? Does it require an entire gutting of their system?

New Tier / New Paradigm / New Challenges

In many cases, Node.js acts as a new tier that augments the enterprise stack and connects it with new offerings. It’s the fast moving technology at the edge of the system.

Figure 2: The Number of Tiers, the Number of Stakeholders and the Complexity Grew Exponentially over the Last 30 Years

One often embraced benefit of Node.js is that it enables teams to move much faster. Add microservices and suddenly there are multiple deployments per day compared to one every few weeks. For many enterprises, this introduces a new paradigm and requires changes to processes that affect other parts of the organization, particularly with those that are in charge of availability and performance, i.e. the operations and performance teams.

These teams don’t consist of Node.js experts and don’t have to. They are driven by metrics like mean time to repair (MTTR). Their main concern is to find the root cause of performance degradations and outages fast. How can these teams make sure the transition to Node.js goes smoothly based on their bottom line? How can they keep their systems humming?

Below we’ve listed out a few common Node.js problems that occur when you introduce it in the enterprise, and how best to manage and solve these problems.

Top Node.js Problems and How to Track Them Down

Node.js applications in enterprise scenarios are rather simple.

Common use cases are:

  • Fetching data from backends.
  • Performing authentication for incoming requests.
  • Rendering views.

Node.js uses Google V8 — the JavaScript engine of Chrome — as a runtime and a library called libuv that provides an event loop to perform asynchronous tasks. All of that is abstracted away from the user by a well-defined JavaScriptAPI — not much can go wrong, e.g. there is no way to introduce thread locking issues and generally tracking down root causes is easier than in other platforms.

Still, some typical problem sources need to be watched closely.

1. Memory Leaks

Node.js is more similar to Java when it comes to runtime behavior. It’s a long running process and because of this, it is prone to memory leaks of all kinds. Like in other platform, memory leaks materialize in a steadily growing heap usage, which causes a crash when the maximum allocate able heap is exhausted. Often this is accompanied by high garbage collector churn while the runtime desperately tries to free memory.

Possible causes can be as simple as large objects that are hooked to the root scope and hence never freed. But, there are also more difficult cases caused by so-called closures (functions that rely on their enclosing scope) giving the garbage collector a hard time to dereference the dependencies. There are also cases where the host simply has too low of a memory configuration causing the garbage collector not to run in time.

To track down memory leaks, heap dumps are the tool of choice. There are several modules that export V8 hooks to JavaScript. Using them, it is fairly easy to trigger a dump whenever certain memory thresholds are exceeded. Here is an example that uses simple anomaly detection and utilizes the module v8-profiler to create dump files that can be consumed by Chrome Developer Tools.

2. CPU Problems

Node.js runs in a single thread. Hence it’s not a good fit for CPU-heavy operations. If the CPU is occupied, e.g. because it’s transforming a large chunk of JSON – no other requests can be handled during this time.

Netflix — a big Node.js shop — had such a problem when an automated script created routes without disposing of the old ones, causing the routing table to fill up over time. At some point, discovering the right function to call for an incoming request took so much time that it severely affected performance. Read their blog post about that.

Node.js out-of-the-box comes with hooks to switch on CPU sampling — the data produced by the sampler can then be consumed by various tools. Using this data, it is rather easy to find out where the time is spent.

Like for memory introspection, there are several ways to capture CPU samples from within JavaScript to analyze them in various tools.

Here is an example that uses v8-profiler again. This time for getting CPU sampling data to find out what was on the CPU at a given time slice.

Figure 6: By Using D3.js to Create a Sunburst Chart, We See the Distribution of CPU Time, Showing that More than 25% Is Contributed to Finding the Right Function to Call for a Route in a Huge Routing Table.

3. Back Pressure

When Node.js acts as a gluing tier connecting different parts of the stack, problems down the stack may surface first in Node.js. Back pressure occurs, when Node.js dispatches requests to slow backends. While Node.js has excellent capabilities for performing outbound requests, slow backends can cause congestion of the machinery waiting for those requests to come back. Degraded performance and even exceptions can be the result.

The metric to look at in this case is the number of dispatched vs. the number of returning requests at any given time.

Figure 7: Back Pressure Occurs When the Requests Pile up in Node.js Because a Backend Is Replying too Slowly

Such problems can only be tracked down to its root cause by using a monitoring solution that traces transactions passing through all tiers, providing metrics about inter-tier communication. Every major vendor in the APM space today provides agents that monitor requests going in and out to and from Node.js.

4. Security

Node.js offers a huge repository of small composable modules. Using the Node.js package manager (npm), it is a matter of seconds to add modules to a project, well-known frameworks like HAPI or Express build on them, and it would be highly inefficient to relinquish their use completely.

Still, every module installed is third party code. It can be poorly maintained and contain bugs that are never fixed or — even worse — security issues. Before using a module, a developer should always check its quality and make sure that it’s not trivial enough to be done themselves.

To tackle the problem, many enterprises also run their own, private npm repository where only packages that went through some auditing process can be found.

Tools like the Node Security Platform or Snyk can streamline this process by using exploit databases to find and fix possible security issues in installed modules.

Outlook

The Node.js diagnostics and the post mortem working groups solely focus on ways to extend and unify the tracing and debugging capabilities within Node.js.

A few highlights from them include:

  • A new tracing facility is around the corner. It will allow low overhead process level tracing.
  • There are current initiatives to unify the way core dumps can be analyzed.
  • With async-hooks, there will be finally a generic way to accomplish long stack traces and transactional tracing through callbacks.

Given the current pace of development and how active the community is driving performance topics; Node.js enterprise capabilities will make another leap in 2017.

Summary

Very often Node.js applications are small and not complex. Communication between tiers, memory leaks and CPU congestion can cause issues. Luckily the platform isn’t a black box, and for every problem, there are ways to introspect running applications to find the root cause.

Monitoring is a topic taken seriously by the Node.js project, and within the next releases, additional ways to trace, debug and monitor Node.js will be introduced adding, even more, capabilities to fix problems fast.

The next time your development team wants to implement Node.js, have no fear, Ops.

转自:http://thenewstack.io/top-four-items-operations-performance-team-know-implementing-node-js/

Four Node.js Gotchas that Operations Teams Should Know about的更多相关文章

  1. Docker学习之——Node.js+MongoDB+Nginx环境搭建(一)

    最近在学习Node.js相关知识,在环境搭建上耗费了不少功夫,故此把这个过程写下来同大家分享一下,今天我先来介绍一下Docker,有很多人都写过相关知识,还有一些教程,在此我只想写一下,我的学习过程中 ...

  2. 2015年最佳的15个 Node.js 开发工具

    Node.js 越来月流行,这个基于 Google V8 引擎建立的平台, 用于方便地搭建响应速度快.易于扩展的网络应用.在本文中,我们列出了2015年最佳的15个 Node.js 开发工具.这些工具 ...

  3. Node.js高级编程读书笔记 - 4 构建Web应用程序

    Outline 5 构建Web应用程序 5.1 构建和使用HTTP中间件 5.2 用Express.js创建Web应用程序 5.3 使用Socket.IO创建通用的实时Web应用程序 5 构建Web应 ...

  4. Understanding Asynchronous IO With Python 3.4's Asyncio And Node.js

    [转自]http://sahandsaba.com/understanding-asyncio-node-js-python-3-4.html Introduction I spent this su ...

  5. node.js 使用 UglifyJS2 高效率压缩 javascript 文件

    UglifyJS2 这个工具使用很长时间了,但之前都是在 gulp 自动构建 时用到了 UglifyJS 算法进行压缩. 最近玩了一下 UglifyJS2 ,做了一个 在线压缩javascript工具 ...

  6. 指令式Callback,函数式Promise:对node.js的一声叹息

    原文:Callbacks are imperative, promises are functional: Node's biggest missed opportunity promises 天生就 ...

  7. [转] Creating a Simple RESTful Web App with Node.js, Express, and MongoDB

    You can find/fork the sample project on GitHub Hey! This and all my other tutorials will soon be mov ...

  8. Node.js流

    什么是流? 流是可以从一个源读取或写入数据到连续的目标对象.在Node.js,有四种类型的数据流. Readable - 其是用于读操作. Writable - 用在写操作. Duplex - 其可以 ...

  9. Node.js快速入门

    Node.js是什么? Node.js是建立在谷歌Chrome的JavaScript引擎(V8引擎)的Web应用程序框架. 它的最新版本是:v0.12.7(在编写本教程时的版本).Node.js在官方 ...

随机推荐

  1. java相关知识集锦

    java语言基础知识: Java8 Stream语法详解 不用循环 java 8系列之Stream的基本语法详解 java8 stream filter等功能代替for Java中try catch ...

  2. 移动端H5的一些基本知识点总结

    移动端H5的一些基本知识点总结 来到这家公司之后,和曾经的工作发生了非常大的转变.曾经我一直是做PC端页面的.来到如今这家公司之后,主要是做手机移动端的页面. 移动端的页面在我这个做习惯了PC端页面的 ...

  3. Android玩转百度地图Sha1获取正确姿势?

    场景一 由于近期项目钟要用到定位功能因此肯定须要用到地图以及地位功能,相信大家也知道眼下国内比較出名的地图像百度.高德.腾讯等这些还是用到比較多的.于是思考了一下决定还是用百度,相信老司机们都知道的哈 ...

  4. Windows在cmd杀掉进程

    问题描述: 在windows根据pid杀进程 问题解决: tasklist查看当前系统中的进程列表,然后针对你要杀的进程使用taskkill命令 #根据服务名taskkill /im nginx.ex ...

  5. Win10易升-在线升级工具

    Win7盗版激活,直接用win10官方推荐的工具在线升级W10直接升级为正版用户... 00.升级协议 11.兼容检测 22.工具下载 Window10官方在线升级工具:https://pan.bai ...

  6. JAVA微信扫码支付模式二功能实现完整例子

    概述 本例子实现微信扫码支付模式二的支付功能,应用场景是,web网站微信扫码支付.实现从点击付费按钮.到弹出二维码.到用户用手机微信扫码支付.到手机上用户付费成功.web网页再自动调整到支付成功后的页 ...

  7. <图形图像,动画,多媒体> 读书笔记 --- 音效

    音频多媒体文件主要是存放音频数据信息,音频文件在录制的过程中把声音信号,通过音频编码,变成音频数字信号保存到某种格式文件里.在播放过程中在对音频文件解码,解码出的信号通过扬声器等设备就能够转成音波.音 ...

  8. js template实现方法

    <script type="text/html" id="template"> <li class="list-item" ...

  9. 【TP3.2.*】解决session过期不失效 和 设置不成功问题

    // ---------- 更新与 2019/01/23日 -------------// 1.问题:本来我想设置session有效期1800秒即30分钟 失效的,可是实际使用TP3.2.0的时候发现 ...

  10. 最常用的Java库一览(13年的文章)

    来源于:http://www.importnew.com/7530.html 本文由 ImportNew - 邢 敏 翻译自 programcreek.欢迎加入翻译小组.转载请见文末要求. 写在前面: ...