tail latency in node.js · instrument the node.js runtime so that at runtime we could easily...

104
Wenzhi Cui Daniel Richins Yuhao Zhu Vijay Janapa Reddi Tail Latency in Node.js: Energy Efficient Turbo Boosting for Long Tail Requests in JavaScript

Upload: others

Post on 23-Mar-2020

17 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

Wenzhi Cui Daniel Richins Yuhao Zhu Vijay Janapa Reddi

Tail Latency in Node.js: Energy Efficient Turbo Boosting for Long Tail

Requests in JavaScript

Page 2: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

�2

Page 3: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

�3

Connecting People (2010s)

Page 4: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

�4

Connecting People (2010s)

Page 5: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

�5

Connecting Things (2020s)

Page 6: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

�5

Connecting Things (2020s)

50 Billion Devices

“The Internet of Things” — Cisco www.cisco.com/web/about/ac79/docs/innov/IoT_IBSG_0411FINAL.pdf

Page 7: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

�6

Thread-based Programming: Traditional Approach

Client Requests

Page 8: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

�6

Thread-based Programming: Traditional Approach

Client Requests

Blocking I/O

Client Response

Page 9: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

�6

Thread-based Programming: Traditional Approach

Client Requests

Blocking I/O

Client Response

Page 10: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

�6

Thread-based Programming: Traditional Approach

Client Requests

Limited resources & thrashing

Blocking I/O

Client Response

Page 11: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

�7

Thread-based Programming

[Welsh et al. ’00]

Page 12: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

�8

Event-driven Programming: Emerging Approach

Page 13: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

�8

Even

t Que

ueHead

Tail

Event-driven Programming: Emerging Approach

Page 14: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

�8

ApplicationTasks

Even

t Que

ueHead

Tail

Event-driven Programming: Emerging Approach

Page 15: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

�8

ApplicationTasks

Even

t Que

ueHead

Tail

fs.readFile(‘input.txt’, function (err, data) { if (err) return console.error(err); console.log(data.toString()); } );

console.log("Program continues…”);

Event-driven Programming: Emerging Approach

Page 16: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

�8

Single-threaded event loop

ApplicationTasks

Even

t Que

ueHead

Tail

fs.readFile(‘input.txt’, function (err, data) { if (err) return console.error(err); console.log(data.toString()); } );

console.log("Program continues…”);

Event-driven Programming: Emerging Approach

Page 17: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

�8

Single-threaded event loop

ApplicationTasks

Even

t Que

ueHead

Tail

fs.readFile(‘input.txt’, function (err, data) { if (err) return console.error(err); console.log(data.toString()); } );

console.log("Program continues…”);

Event-driven Programming: Emerging Approach

Page 18: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

�8

Single-threaded event loop

DB AccessFile I/O

Network

ApplicationTasks

Even

t Que

ueHead

Tail

Asynchronous I/O

fs.readFile(‘input.txt’, function (err, data) { if (err) return console.error(err); console.log(data.toString()); } );

console.log("Program continues…”);

Event-driven Programming: Emerging Approach

Page 19: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

�8

Single-threaded event loop

DB AccessFile I/O

Network

ApplicationTasks

Even

t Que

ueHead

Tail

Asynchronous I/O

fs.readFile(‘input.txt’, function (err, data) { if (err) return console.error(err); console.log(data.toString()); } );

console.log("Program continues…”);

Event-driven Programming: Emerging Approach

Page 20: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

�8

Single-threaded event loop

DB AccessFile I/O

Network

ApplicationTasks

Even

t Que

ueHead

Tail

Asynchronous I/O

fs.readFile(‘input.txt’, function (err, data) { if (err) return console.error(err); console.log(data.toString()); } );

console.log("Program continues…”);

Event-driven Programming: Emerging Approach

Page 21: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

�8

Single-threaded event loop

DB AccessFile I/O

Network

ApplicationTasks

Even

t Que

ueHead

Tail

Asynchronous I/O

fs.readFile(‘input.txt’, function (err, data) { if (err) return console.error(err); console.log(data.toString()); } );

console.log("Program continues…”);

Event-driven Programming: Emerging Approach

Page 22: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

�9

Thread-based Programming

Event-driven Programming

[Welsh et al. ’00]

Page 23: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

The Changing Programming Language Landscape

�10

Page 24: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

The Changing Programming Language Landscape

�10

Page 25: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

The Changing Programming Language Landscape

�10

Page 26: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

�11

ManagedLanguage

Event-drivenExecution Model

Page 27: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

�12

Page 28: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

Taming Tail Latencies in Event-Driven Web Services

�13

Frac

tion

of R

eque

sts

Request Latency

Tail

Page 29: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

Experimental Setup

�14

(1 Gbps Network)

Intel i7-4790K, 4 physical cores with hyper-threading, 32 GB DRAM, 240GB SSD

Wrk

2: A

cus

tom

ized

Load

Tes

ting

Tool

, sim

ulat

e re

al-w

orld

wor

kload

s

Page 30: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

Applications

�15

Benchmarks I/O Type #Requests Description

Etherpad lite N/A 20K Real time word processor.

Todo Redis 40K Online Task Manager.

Lighter Disk 40K Blogging Engine.

Let’s Chat MongoDB 10K Web-based Chat Application.

Client Manager MongoDB 40K Online Address book.

Github Repo: https://github.com/nodebenchmark/benchmarks

Page 31: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

Etherpad: An Example

�16

1.0

0.8

0.6

0.4

0.2

0.0

CDF

605040302010Latency (ms)

Page 32: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

Etherpad: An Example

�17

1.0

0.8

0.6

0.4

0.2

0.0

CDF

605040302010Latency (ms)

(1.85, 50%)

Page 33: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

Etherpad: An Example

�18

1.0

0.8

0.6

0.4

0.2

0.0

CDF

605040302010Latency (ms)

(1.85, 50%)

(7.30, 90%)

Page 34: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

Etherpad: An Example

�19

1.0

0.8

0.6

0.4

0.2

0.0

CDF

605040302010Latency (ms)

(1.85, 50%)

(7.30, 90%)(36.91, 99.9%)

Page 35: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

Etherpad: An Example

�19

Tail Region

1.0

0.8

0.6

0.4

0.2

0.0

CDF

605040302010Latency (ms)

(1.85, 50%)

(7.30, 90%)(36.91, 99.9%)

Page 36: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

Tail RegionTail Region

Tail RegionTail Region

�20

1.0

0.8

0.6

0.4

0.2

0.0

CDF

3.02.01.0Latency (ms)

(0.47, 50%)

(1.12, 90%)(1.80, 99.9%)

1.0

0.8

0.6

0.4

0.2

0.0

CDF

161284Latency (ms)

(0.81, 50%)

(1.40, 90%)(8.75, 99.9%)

1.0

0.8

0.6

0.4

0.2

0.0

CDF

40302010Latency (ms)

(12.52, 50%)

(20.30, 90%)(39.54, 99.9%)

1.0

0.8

0.6

0.4

0.2

0.0

CDF

2015105Latency (ms)

(1.65, 50%)

(2.66, 90%)(12.99, 99.9%)

Todo Lighter

Client ManagerLet’s Chat

Page 37: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

Tail RegionTail Region

Tail RegionTail Region

�20

1.0

0.8

0.6

0.4

0.2

0.0

CDF

3.02.01.0Latency (ms)

(0.47, 50%)

(1.12, 90%)(1.80, 99.9%)

1.0

0.8

0.6

0.4

0.2

0.0

CDF

161284Latency (ms)

(0.81, 50%)

(1.40, 90%)(8.75, 99.9%)

1.0

0.8

0.6

0.4

0.2

0.0

CDF

40302010Latency (ms)

(12.52, 50%)

(20.30, 90%)(39.54, 99.9%)

1.0

0.8

0.6

0.4

0.2

0.0

CDF

2015105Latency (ms)

(1.65, 50%)

(2.66, 90%)(12.99, 99.9%)

Todo Lighter

Client ManagerLet’s Chat

Tail latency (99.9%) is 9.1x longerthan median request latency

Page 38: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

System Overview

�21

Step 1 Step 2 Step 3

Page 39: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

System Overview

�21

Step 1 Step 2 Step 3

Tools to Root-cause Tail in

Node.js

Page 40: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

System Overview

�21

Tail LatencyReconstruction

Event-driven

runtime(libuv)

JS to C++ bindings

Req1 Req2 …

EventData

e1

e5

e3e4

e2

EventCritical Path

JavaScript runtime

(V8)

File/Net JS libraries

Event-DependencyGraph (EDG)

Step 1 Step 2 Step 3

Page 41: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

System Overview

�21

Tail LatencyReconstruction

Event-driven

runtime(libuv)

JS to C++ bindings

Req1 Req2 …

EventData

e1

e5

e3e4

e2

EventCritical Path

JavaScript runtime

(V8)

File/Net JS libraries

Event-DependencyGraph (EDG)

Step 1 Step 2 Step 3

Root-causing Tail in Node.js

Page 42: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

System Overview

�21

Tail LatencyReconstruction

Event-driven

runtime(libuv)

JS to C++ bindings

Req1 Req2 …

EventData

e1

e5

e3e4

e2

EventCritical Path

JavaScript runtime

(V8)

File/Net JS libraries

Event-DependencyGraph (EDG)

Exec

Queue

I/O

Req1Exec

Queue

I/OReq2

Requ

est L

aten

cy

Tail LatencyBottleneck Anaysis

IO (%)Queue (%)Exec (%) GC (%) JIT (%) …

Step 1 Step 2 Step 3

Page 43: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

System Overview

�21

Tail LatencyReconstruction

Event-driven

runtime(libuv)

JS to C++ bindings

Req1 Req2 …

EventData

e1

e5

e3e4

e2

EventCritical Path

JavaScript runtime

(V8)

File/Net JS libraries

Event-DependencyGraph (EDG)

Exec

Queue

I/O

Req1Exec

Queue

I/OReq2

Requ

est L

aten

cy

Tail LatencyBottleneck Anaysis

IO (%)Queue (%)Exec (%) GC (%) JIT (%) …

Step 1 Step 2 Step 3

Mitigating Tail in Node.js

Page 44: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

System Overview

�21

Tail LatencyReconstruction

Event-driven

runtime(libuv)

JS to C++ bindings

Req1 Req2 …

EventData

e1

e5

e3e4

e2

EventCritical Path

JavaScript runtime

(V8)

File/Net JS libraries

Event-DependencyGraph (EDG)

Exec

Queue

I/O

Req1Exec

Queue

I/OReq2

Requ

est L

aten

cy

Tail LatencyBottleneck Anaysis

IO (%)Queue (%)Exec (%) GC (%) JIT (%) …

Tail LatencyOptimization

Queue Boosting

VM Boosting

VM Optimization VM Tuning

Event Queue

Step 1 Step 2 Step 3

Page 45: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

System Overview

�21

Tail LatencyReconstruction

Event-driven

runtime(libuv)

JS to C++ bindings

Req1 Req2 …

EventData

e1

e5

e3e4

e2

EventCritical Path

JavaScript runtime

(V8)

File/Net JS libraries

Event-DependencyGraph (EDG)

Exec

Queue

I/O

Req1Exec

Queue

I/OReq2

Requ

est L

aten

cy

Tail LatencyBottleneck Anaysis

IO (%)Queue (%)Exec (%) GC (%) JIT (%) …

Tail LatencyOptimization

Queue Boosting

VM Boosting

VM Optimization VM Tuning

Event Queue

Step 1 Step 2 Step 3

Static Instrumentation

Page 46: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

System Overview

�21

Tail LatencyReconstruction

Event-driven

runtime(libuv)

JS to C++ bindings

Req1 Req2 …

EventData

e1

e5

e3e4

e2

EventCritical Path

JavaScript runtime

(V8)

File/Net JS libraries

Event-DependencyGraph (EDG)

Exec

Queue

I/O

Req1Exec

Queue

I/OReq2

Requ

est L

aten

cy

Tail LatencyBottleneck Anaysis

IO (%)Queue (%)Exec (%) GC (%) JIT (%) …

Tail LatencyOptimization

Queue Boosting

VM Boosting

VM Optimization VM Tuning

Event Queue

Step 1 Step 2 Step 3

Static Instrumentation

Dynamic Analysis & Optimization

Page 47: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

Step 1: Latency Reconstruction

�22

var count = N;fs.readdir(“/data”, function dir(err, files) { files.foreach(function file(f, index) { var fname = …; fs.readFile(fname, function read(err, data) { count -= 1; if (count == 0) sendResponse(); }); });});

Page 48: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

Step 1: Latency Reconstruction

�22

var count = N;fs.readdir(“/data”, function dir(err, files) { files.foreach(function file(f, index) { var fname = …; fs.readFile(fname, function read(err, data) { count -= 1; if (count == 0) sendResponse(); }); });});

Page 49: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

Step 1: Latency Reconstruction

�22

var count = N;fs.readdir(“/data”, function dir(err, files) { files.foreach(function file(f, index) { var fname = …; fs.readFile(fname, function read(err, data) { count -= 1; if (count == 0) sendResponse(); }); });});

Page 50: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

Step 1: Latency Reconstruction

�22

var count = N;fs.readdir(“/data”, function dir(err, files) { files.foreach(function file(f, index) { var fname = …; fs.readFile(fname, function read(err, data) { count -= 1; if (count == 0) sendResponse(); }); });});

Page 51: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

Step 1: Latency Reconstruction

�22

var count = N;fs.readdir(“/data”, function dir(err, files) { files.foreach(function file(f, index) { var fname = …; fs.readFile(fname, function read(err, data) { count -= 1; if (count == 0) sendResponse(); }); });});

Source

readdir

readFile1 readFile2Sink readFile3 readFileN

Page 52: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

Event Dependency Graph (EDG)

�23

Page 53: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

Event Dependency Graph (EDG)

�23

e1

e5

e3e4

e2

EventCritical Path

Event-DependencyGraph (EDG)

Page 54: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

Event Dependency Graph (EDG)

�23

e1

e5

e3e4

e2

EventCritical Path

Event-DependencyGraph (EDG)

Page 55: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

Event Dependency Graph (EDG)

�23

e1

e5

e3e4

e2

EventCritical Path

Event-DependencyGraph (EDG)

How do we obtain the latency of each event?

Page 56: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

Deconstructing Event Latency

Sever-side Latency

Page 57: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

Deconstructing Event Latency

Sever-side Latency

Queue. Exec.I/O

Page 58: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

Deconstructing Event Latency

Sever-side Latency

Queue. Exec.I/O Node.js RuntimeCompute Time

Page 59: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

Deconstructing Event Latency

Sever-side Latency

Queue. Exec.I/O Node.js Runtime

User CodeGC Interrupt IC Miss JIT Engine

Compute Time

Page 60: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

Offline Instrumentation + Online Analysis

�25

Event-driven

runtime(libuv)

JS to C++ bindings

Req1 Req2 …

JavaScript runtime

(V8)

File/Net JS libraries

Instrument the Node.js runtime so that at runtime

we could easily obtain: EDG & event latency info.

Page 61: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

Offline Instrumentation + Online Analysis

�25

Exec

Queue

I/O

Req1

Exec

Queue

I/O

Req2

Requ

est L

aten

cy

Tail LatencyBottleneck Anaysis

IO (%)Queue (%)Exec (%) GC (%) JIT (%) …

Event-driven

runtime(libuv)

JS to C++ bindings

Req1 Req2 …

JavaScript runtime

(V8)

File/Net JS libraries

Instrument the Node.js runtime so that at runtime

we could easily obtain: EDG & event latency info.

Identify root-causes of long tails at runtime.

Page 62: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

Step 2: EDG-based Bottleneck Analysis

�26

5040302010

0

Late

ncy

(ms)

A n B n C n D nAvg n A t B t C t D t

Avg t

Request Type

IO Queue ExecTailNon-tail

Page 63: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

Step 2: EDG-based Bottleneck Analysis

�26

5040302010

0

Late

ncy

(ms)

A n B n C n D nAvg n A t B t C t D t

Avg t

Request Type

IO Queue ExecTailNon-tail

Page 64: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

Step 2: EDG-based Bottleneck Analysis

�26

5040302010

0

Late

ncy

(ms)

A n B n C n D nAvg n A t B t C t D t

Avg t

Request Type

IO Queue ExecTailNon-tail

Page 65: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

Step 2: EDG-based Bottleneck Analysis

�26

5040302010

0

Late

ncy

(ms)

A n B n C n D nAvg n A t B t C t D t

Avg t

Request Type

IO Queue ExecTailNon-tail

Etherpad: Queue and Exec. latency increases in tails, and I/O latency is not dominant for this particular application.

Page 66: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

EDG-based Bottleneck Analysis

�27

16

12

8

4

0

Late

ncy

(ms)

V n W n X nAvg n V t W t X t

Avg t

Request Type

IO Queue ExecTailNon-tail

Page 67: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

EDG-based Bottleneck Analysis

�27

16

12

8

4

0

Late

ncy

(ms)

V n W n X nAvg n V t W t X t

Avg t

Request Type

IO Queue ExecTailNon-tail

Client Manager: Queue and Exec. latency dominate in tails, but unlike Etherpad I/O plays a notable role in the requests.

Page 68: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

EDG-based Bottleneck Analysis

�27

16

12

8

4

0

Late

ncy

(ms)

V n W n X nAvg n V t W t X t

Avg t

Request Type

IO Queue ExecTailNon-tail

Client Manager: Queue and Exec. latency dominate in tails, but unlike Etherpad I/O plays a notable role in the requests.

On average, queuing and native code execution time contribute to ~80% of the tail latencies.

Page 69: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

Breakdown Within Compute

�28

Compute Time

Page 70: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

Breakdown Within Compute

�28

Compute Time

Page 71: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

Breakdown Within Compute

�28

Compute Time

Page 72: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

Breakdown Within Compute

�28

Compute Time

Page 73: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

Breakdown Within Compute

�28

Compute Time

Page 74: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

Breakdown Within Compute

�28

Compute Time

Page 75: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

Breakdown Within Compute

�28

Compute Time

We should focus optimization efforts on Garbage Collection and Generated Native Code

Page 76: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

Step 3: Tail Latency Optimization

▸ Leveraging the turbo boosting capability of modern CPUs

▸ Key: wisely choose what to boost

▸ GC Boosting

▹ Boost GC

▸ Queue Boosting

▹ Boost when the system is “busy”

▹ Use event queue stats as “hints”

�29

Tail LatencyOptimization

Queue Boosting

VM Boosting

VM Optimization VM Tuning

Event Queue

(Intel Turbo Boosting)

Page 77: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

Optimization 1: VM Optimization (GC Boost)

Page 78: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

Optimization 1: VM Optimization (GC Boost)

▸ Observations:

▹ GCs are infrequent, little overall energy overhead

▹ IPC during GC is relatively high: ~1.3

Page 79: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

Optimization 1: VM Optimization (GC Boost)

▸ Observations:

▹ GCs are infrequent, little overall energy overhead

▹ IPC during GC is relatively high: ~1.3

▸ Implementation

▹ User-space DVFS embedded in Google V8: enter boosting at GC prologues and exit boosting at GC epilogues

▹ More benefits if we have access to fine-grained per-core DVFS mechanism

Page 80: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

Optimization 2: Queue Boost

�31

Queue Monitor

DVFS

Page 81: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

Optimization 2: Queue Boost

�31

▸ More general compute acceleration: Boost when the system is “busy”

Queue Monitor

DVFS

Page 82: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

Optimization 2: Queue Boost

�31

▸ More general compute acceleration: Boost when the system is “busy”▸ How do you detect that?

Queue Monitor

DVFS

Page 83: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

Optimization 2: Queue Boost

�31

▸ More general compute acceleration: Boost when the system is “busy”▸ How do you detect that?▸ Rely on two queue-related heuristics: ▹ # of events in the queue

▹ Processing time of the head-of-line event

Queue Monitor

DVFS

Page 84: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

Optimization 2: Queue Boost

�31

▸ More general compute acceleration: Boost when the system is “busy”▸ How do you detect that?▸ Rely on two queue-related heuristics: ▹ # of events in the queue

▹ Processing time of the head-of-line event

Queue Monitor

DVFS▸ Implementation: ▸ Periodic Sampling: Every 1 ms

▸ Dynamic Thresholding

▹ Sample the average value of event number and per event processing time

▹ Amplify the average value to decide a dynamic threshold by 2-3x

Page 85: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

Evaluation

▸ Our system: normal operating frequency at 2.6 GHz, boosts to max 4.0 GHz during GC boost and Queue boost

�32

Page 86: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

Evaluation

▸ Our system: normal operating frequency at 2.6 GHz, boosts to max 4.0 GHz during GC boost and Queue boost

▸ Different Variants:

�32

Page 87: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

Evaluation

▸ Our system: normal operating frequency at 2.6 GHz, boosts to max 4.0 GHz during GC boost and Queue boost

▸ Different Variants:

▹ GC Boost

�32

Page 88: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

Evaluation

▸ Our system: normal operating frequency at 2.6 GHz, boosts to max 4.0 GHz during GC boost and Queue boost

▸ Different Variants:

▹ GC Boost

▹ GC Boost with GC Parameter Tuning

�32

Page 89: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

Evaluation

▸ Our system: normal operating frequency at 2.6 GHz, boosts to max 4.0 GHz during GC boost and Queue boost

▸ Different Variants:

▹ GC Boost

▹ GC Boost with GC Parameter Tuning

▹ Queue Boost

�32

Page 90: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

Evaluation

▸ Our system: normal operating frequency at 2.6 GHz, boosts to max 4.0 GHz during GC boost and Queue boost

▸ Different Variants:

▹ GC Boost

▹ GC Boost with GC Parameter Tuning

▹ Queue Boost

▹ GC Tuning + GC Boost + Queue Boost

�32

Page 91: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

Evaluation

▸ Our system: normal operating frequency at 2.6 GHz, boosts to max 4.0 GHz during GC boost and Queue boost

▸ Different Variants:

▹ GC Boost

▹ GC Boost with GC Parameter Tuning

▹ Queue Boost

▹ GC Tuning + GC Boost + Queue Boost▸ Baseline

�32

Page 92: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

Evaluation

▸ Our system: normal operating frequency at 2.6 GHz, boosts to max 4.0 GHz during GC boost and Queue boost

▸ Different Variants:

▹ GC Boost

▹ GC Boost with GC Parameter Tuning

▹ Queue Boost

▹ GC Tuning + GC Boost + Queue Boost▸ Baseline▸ Static Frequency: 3.3GHz and 4.0GHz

�32

Page 93: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

Evaluation

▸ Our system: normal operating frequency at 2.6 GHz, boosts to max 4.0 GHz during GC boost and Queue boost

▸ Different Variants:

▹ GC Boost

▹ GC Boost with GC Parameter Tuning

▹ Queue Boost

▹ GC Tuning + GC Boost + Queue Boost▸ Baseline▸ Static Frequency: 3.3GHz and 4.0GHz

▸ Adrenaline [HPCA 2015]

�32

Page 94: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

Evaluation

▸ Our system: normal operating frequency at 2.6 GHz, boosts to max 4.0 GHz during GC boost and Queue boost

▸ Different Variants:

▹ GC Boost

▹ GC Boost with GC Parameter Tuning

▹ Queue Boost

▹ GC Tuning + GC Boost + Queue Boost▸ Baseline▸ Static Frequency: 3.3GHz and 4.0GHz

▸ Adrenaline [HPCA 2015]

▸ Rubik [MICRO 2015]

�32

Page 95: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

Evaluation

▸ Our system: normal operating frequency at 2.6 GHz, boosts to max 4.0 GHz during GC boost and Queue boost

▸ Different Variants:

▹ GC Boost

▹ GC Boost with GC Parameter Tuning

▹ Queue Boost

▹ GC Tuning + GC Boost + Queue Boost▸ Baseline▸ Static Frequency: 3.3GHz and 4.0GHz

▸ Adrenaline [HPCA 2015]

▸ Rubik [MICRO 2015]

�32

2.4

2.1

1.8

1.5

1.2

0.9

Nor

m. E

nerg

y

3228242016128

Tail Reduction (%)

Combined GC Boost GC Boost+Tuning QBoost

Etherpad Lite

Page 96: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

Evaluation

▸ Our system: normal operating frequency at 2.6 GHz, boosts to max 4.0 GHz during GC boost and Queue boost

▸ Different Variants:

▹ GC Boost

▹ GC Boost with GC Parameter Tuning

▹ Queue Boost

▹ GC Tuning + GC Boost + Queue Boost▸ Baseline▸ Static Frequency: 3.3GHz and 4.0GHz

▸ Adrenaline [HPCA 2015]

▸ Rubik [MICRO 2015]

�32

2.4

2.1

1.8

1.5

1.2

0.9

Nor

m. E

nerg

y

3228242016128

Tail Reduction (%)

Combined GC Boost GC Boost+Tuning QBoost

Etherpad Lite

Page 97: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

Evaluation

▸ Our system: normal operating frequency at 2.6 GHz, boosts to max 4.0 GHz during GC boost and Queue boost

▸ Different Variants:

▹ GC Boost

▹ GC Boost with GC Parameter Tuning

▹ Queue Boost

▹ GC Tuning + GC Boost + Queue Boost▸ Baseline▸ Static Frequency: 3.3GHz and 4.0GHz

▸ Adrenaline [HPCA 2015]

▸ Rubik [MICRO 2015]

�32

2.4

2.1

1.8

1.5

1.2

0.9

Nor

m. E

nerg

y

3228242016128

Tail Reduction (%)

Combined GC Boost GC Boost+Tuning QBoost

Etherpad Lite

Page 98: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

Evaluation

▸ Our system: normal operating frequency at 2.6 GHz, boosts to max 4.0 GHz during GC boost and Queue boost

▸ Different Variants:

▹ GC Boost

▹ GC Boost with GC Parameter Tuning

▹ Queue Boost

▹ GC Tuning + GC Boost + Queue Boost▸ Baseline▸ Static Frequency: 3.3GHz and 4.0GHz

▸ Adrenaline [HPCA 2015]

▸ Rubik [MICRO 2015]

�32

2.4

2.1

1.8

1.5

1.2

0.9

Nor

m. E

nerg

y

3228242016128

Tail Reduction (%)

Combined GC Boost GC Boost+Tuning QBoost

Etherpad Lite

Page 99: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

2.4

2.1

1.8

1.5

1.2

0.9

Nor

m. E

nerg

y

3228242016128

Tail Reduction (%)

Combined GC Boost GC Boost+Tuning QBoost

2.8

2.3

1.8

1.3

0.8

Nor

m. E

nerg

y

1086420Tail Reduction (%)

Adrenaline Rubik 3.3 GHz 4.0 GHz

3.0

2.3

1.6

0.9

Nor

m. E

nerg

y

4032241680

Tail Reduction (%)2.8

2.4

2.0

1.6

1.2

0.8

Nor

m. E

nerg

y

262116116

Tail Reduction (%)

3.2

2.6

2.0

1.4

0.8N

orm

. Ene

rgy

3227221712

Tail Reduction (%)

Todo Lighter

Client ManagerLet’s Chat

Page 100: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

2.4

2.1

1.8

1.5

1.2

0.9

Nor

m. E

nerg

y

3228242016128

Tail Reduction (%)

Combined GC Boost GC Boost+Tuning QBoost

2.8

2.3

1.8

1.3

0.8

Nor

m. E

nerg

y

1086420Tail Reduction (%)

Adrenaline Rubik 3.3 GHz 4.0 GHz

3.0

2.3

1.6

0.9

Nor

m. E

nerg

y

4032241680

Tail Reduction (%)2.8

2.4

2.0

1.6

1.2

0.8

Nor

m. E

nerg

y

262116116

Tail Reduction (%)

3.2

2.6

2.0

1.4

0.8N

orm

. Ene

rgy

3227221712

Tail Reduction (%)

Todo Lighter

Client ManagerLet’s Chat

Page 101: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

2.4

2.1

1.8

1.5

1.2

0.9

Nor

m. E

nerg

y

3228242016128

Tail Reduction (%)

Combined GC Boost GC Boost+Tuning QBoost

2.8

2.3

1.8

1.3

0.8

Nor

m. E

nerg

y

1086420Tail Reduction (%)

Adrenaline Rubik 3.3 GHz 4.0 GHz

3.0

2.3

1.6

0.9

Nor

m. E

nerg

y

4032241680

Tail Reduction (%)2.8

2.4

2.0

1.6

1.2

0.8

Nor

m. E

nerg

y

262116116

Tail Reduction (%)

3.2

2.6

2.0

1.4

0.8N

orm

. Ene

rgy

3227221712

Tail Reduction (%)

Todo Lighter

Client ManagerLet’s Chat

Pareto-dominate existing solutions; 14-21% tail reduction with only 3-14% energy overhead over baseline.

Page 102: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

Conclusions

Node.js uniquely combines event-driven programming model and managed language runtime, presenting new landscape and challenges to tail latency optimizations.

�34

Page 103: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

Conclusions

Node.js uniquely combines event-driven programming model and managed language runtime, presenting new landscape and challenges to tail latency optimizations.

�34

e1

e5

e3e4

e2

EventCritical Path

Event-DependencyGraph (EDG)

Event-dependency graph (EDG) and event-critical path (ECP) critical to deconstruct tail latency in Node.js.

Page 104: Tail Latency in Node.js · Instrument the Node.js runtime so that at runtime we could easily obtain: EDG & event latency info. Identify root-causes of long tails at runtime. Step

Conclusions

Node.js uniquely combines event-driven programming model and managed language runtime, presenting new landscape and challenges to tail latency optimizations.

�34

e1

e5

e3e4

e2

EventCritical Path

Event-DependencyGraph (EDG)

Event-dependency graph (EDG) and event-critical path (ECP) critical to deconstruct tail latency in Node.js.

Tail LatencyOptimization

Queue Boosting

VM Boosting

VM Optimization VM Tuning

Event Queue

Tail LatencyOptimization

Queue Boosting

VM Boosting

VM Optimization VM Tuning

Event Queue

Intelligently leverage existing hardware features, turbo boosting in particular, to reduce latency with little to none energy overhead.