SlideShare ist ein Scribd-Unternehmen logo
1 von 57
Downloaden Sie, um offline zu lesen
A world of Rest APIs…
from Restify to a faster Fastify
ALESSANDRO POLIDORI
Senior Software Engineer
ale_polidori
Node.js Global Summit 2020
2009
2020
Debug in PRODUCTION ?
Photo by Matteo Cappè
Debug in PRODUCTION ?
NethCTI Backend REST API
M I G R A T I O N
Internet (PSTN)
server
REST / WS
REST / WS
REST / WS
REST / WS
PBX
1
2
3
Internet (PSTN)
server
REST / WS
REST / WS
REST / WS
REST / WS
PBX
1
2
Event: BridgeEnter
Privilege: call,all
BridgeUniqueid: c2c967b6-9044
BridgeType: basic
BridgeTechnology: simple_bridge
BridgeCreator: <unknown>
BridgeName: <unknown>
BridgeNumChannels: 1
BridgeVideoSourceMode: none
Channel: PJSIP/Nethesis-00000123
ChannelState: 6
ChannelStateDesc: Up
CallerIDNum: 3401234567
CallerIDName: 3401234567
ConnectedLineNum: 072112345
ConnectedLineName: <unknown>
Language: it
AccountCode: 223
Context: from-pstn
Exten:
Priority: 1
Uniqueid: 1590499030.97474
Linkedid: 1590499029.97472
{
"connected": true,
"counterpartName": "3401234567",
"counterpartNum": "3401234567",
"direction": "out",
"duration": 19,
"id": "PJSIP/91223-00000",
"inConference": false,
"linkedId": "1590499772.97717",
"owner": "91223",
"recording": "false",
"startTime": 1590499772000,
"throughQueue": false
}
3
Internet (PSTN)
REST / WS
REST / WS
REST / WS
REST / WS
PBX
1 3
Asterisk-Proxy
Database
Config
Phonebook
CustomerCard
Exec-Script
User
Call History
REST Phonebook
REST CustCard
REST History
RESTAstProxy
WebSocket
Internet (PSTN)
REST / WS
REST / WS
REST / WS
REST / WS
PBX
1 3
Internet (PSTN)
REST / WS
REST / WS
REST / WS
REST / WS
PBX
1 3
Unresponsive Client
100% CPU
Debug in PRODUCTION ?
How To Reproduce
Internet (PSTN)
S
I
P
e s s i o n
n i t i a t i o n
r o t o c o l
#sipp -sf register_invite_client.xml
-inf register_invite_client.csv
192.168.5.80 -m 100 -d 10000 -r 10
FlameGraph
FlameGraph
1. capture the stacks

2. fold the stack

3. create svg image
0x
1. installation: npm install -g 0x 

2. exec: 0x my-server.js

3. image creation: SIGINT
npm i autocannon -g
HTTP Pipelining
https://en.wikipedia.org/wiki/HTTP_pipelining
REST Phonebook
REST CustCard
REST History
RESTAstProxy
WebSocket
Node http-proxy{ REST-API }
M I G R A T I O N
var restify = require('restify');
var plugins = require('jsplugs')().require('./plugins/com_astproxy_rest/plugins_rest');
for (p in plugins) {
get = plugins[p].api.get;
root = plugins[p].api.root;
 post = plugins[p].api.post;
  del = plugins[p].api.del;
  // add routing functions
  for (k in get) {
    server.get('/' + root + '/' + get[k], execute);
  }
  // post...
}
server.listen(port, address, function() {
  logger.log.info(IDLOG, server.name + ' listening at ' + server.url);
});
T h e O l d C o d e
var restify = require('restify');
var plugins = require('jsplugs')().require('./plugins/com_astproxy_rest/plugins_rest');
for (p in plugins) {
get = plugins[p].api.get;
root = plugins[p].api.root;
 post = plugins[p].api.post;
  del = plugins[p].api.del;
  // add routing functions
  for (k in get) {
    server.get('/' + root + '/' + get[k], execute);
  }
  // post
}
server.listen(port, address, function() {
  logger.log.info(IDLOG, server.name + ' listening at ' + server.url);
});
T h e O l d C o d e
var fastify = require('fastify')({ logger: false });
var plugins = require(‘jsplugs')().require('./plugins/com_astproxy_rest/plugins_rest');
for (p in plugins) {
get = plugins[p].api.get;
  // add routing functions
  for (k in get) {
    fastify.get('/' + root + '/' + get[k], plugins[p][get[k] + '_schema'], execute);
  }
}
fastify.listen(port, address, function (err, address) {
  if (err) {
    fastify.log.error(err)
    process.exit(1)
  }
  fastify.log.info(`fastify server listening on ${address}`)
});
T h e N e w C o d e
var fastify = require('fastify')({ logger: false });
var plugins = require(‘jsplugs')().require('./plugins/com_astproxy_rest/plugins_rest');
for (p in plugins) {
get = plugins[p].api.get;
  // add routing functions
  for (k in get) {
    fastify.get('/' + root + '/' + get[k], plugins[p][get[k] + '_schema'], execute);
  }
}
fastify.listen(port, address, function (err, address) {
  if (err) {
    fastify.log.error(err)
    process.exit(1)
  }
  fastify.log.info(`fastify server listening on ${address}`)
});
T h e N e w C o d e
var fastify = require('fastify')({ logger: false });
var plugins = require(‘jsplugs')().require('./plugins/com_astproxy_rest/plugins_rest');
for (p in plugins) {
get = plugins[p].api.get;
  // add routing functions
  for (k in get) {
    fastify.get('/' + root + '/' + get[k], plugins[p][get[k] + '_schema'], execute);
  }
}
fastify.listen(port, address, function (err, address) {
  if (err) {
    fastify.log.error(err)
    process.exit(1)
  }
  fastify.log.info(`fastify server listening on ${address}`)
});
T h e N e w C o d e
M I G R A T I O N
HTTP GET astproxy/extensions
Test Scenario 1
Virtual Machine on MBP 2,7 GHz Intel Core i5
• 1 CPU

• 1 GB RAM

• 10 Phone Extensions
$ autocannon
-c 100
-d 10
-l
https://$IP/astproxy/extensions
# concurrent connections
10 secs: test duration
print latency
Running 10s test @ https://192.168.11.22/webrest/astproxy/extensions
100 connections
┌─────────┬────────┬────────┬─────────┬─────────┬───────────┬───────────┬────────────┐
│ Stat │ 2.5% │ 50% │ 97.5% │ 99% │ Avg │ Stdev │ Max │
├─────────┼────────┼────────┼─────────┼─────────┼───────────┼───────────┼────────────┤
│ Latency │ 158 ms │ 226 ms │ 1490 ms │ 1671 ms │ 270.33 ms │ 233.65 ms │ 1748.84 ms │
└─────────┴────────┴────────┴─────────┴─────────┴───────────┴───────────┴────────────┘
┌───────────┬─────┬──────┬─────────┬─────────┬─────────┬────────┬────────┐
│ Stat │ 1% │ 2.5% │ 50% │ 97.5% │ Avg │ Stdev │ Min │
├───────────┼─────┼──────┼─────────┼─────────┼─────────┼────────┼────────┤
│ Req/Sec │ 0 │ 0 │ 414 │ 511 │ 366.5 │ 145.5 │ 204 │
├───────────┼─────┼──────┼─────────┼─────────┼─────────┼────────┼────────┤
Restify performance
Running 10s test @ https://192.168.11.22/webrest/astproxy/extensions
100 connections
┌─────────┬────────┬────────┬────────┬─────────┬───────────┬───────────┬────────────┐
│ Stat │ 2.5% │ 50% │ 97.5% │ 99% │ Avg │ Stdev │ Max │
├─────────┼────────┼────────┼────────┼─────────┼───────────┼───────────┼────────────┤
│ Latency │ 128 ms │ 169 ms │ 540 ms │ 1544 ms │ 212.24 ms │ 197.89 ms │ 1778.33 ms │
└─────────┴────────┴────────┴────────┴─────────┴───────────┴───────────┴────────────┘
┌───────────┬─────┬──────┬─────────┬─────────┬─────────┬────────┬────────┐
│ Stat │ 1% │ 2.5% │ 50% │ 97.5% │ Avg │ Stdev │ Min │
├───────────┼─────┼──────┼─────────┼─────────┼─────────┼────────┼────────┤
│ Req/Sec │ 0 │ 0 │ 524 │ 658 │ 468.4 │ 204.98 │ 153 │
├───────────┼─────┼──────┼─────────┼─────────┼─────────┼────────┼────────┤
Fastify performance
I m p r o v e A G A I N ?
Is it possible ?
fastify-http-proxy
github.com/fastify/fastify-http-proxy
REST Phonebook
REST CustCard
REST History
RESTAstProxy
WebSocket
{ REST-API } Node http-proxy
Running 10s test @ https://192.168.11.22/webrest/astproxy/extensions
100 connections
┌─────────┬───────┬────────┬────────┬─────────┬───────────┬───────────┬────────────┐
│ Stat │ 2.5% │ 50% │ 97.5% │ 99% │ Avg │ Stdev │ Max │
├─────────┼───────┼────────┼────────┼─────────┼───────────┼───────────┼────────────┤
│ Latency │ 82 ms │ 121 ms │ 218 ms │ 1363 ms │ 143.46 ms │ 153.47 ms │ 1530.87 ms │
└─────────┴───────┴────────┴────────┴─────────┴───────────┴───────────┴────────────┘
┌───────────┬─────┬──────┬─────────┬─────────┬────────┬────────┬─────────┐
│ Stat │ 1% │ 2.5% │ 50% │ 97.5% │ Avg │ Stdev │ Min │
├───────────┼─────┼──────┼─────────┼─────────┼────────┼────────┼─────────┤
│ Req/Sec │ 0 │ 0 │ 776 │ 906 │ 692.2 │ 259.05 │ 468 │
├───────────┼─────┼──────┼─────────┼─────────┼────────┼────────┼─────────┤
Fastify with HTTP-PROXY
const Fastify = require('fastify');
const serverF = Fastify({ logger: false });
const proxyF = require(‘fastify-http-proxy');
serverF.register(proxyF, {
upstream: http://myserver,
  prefix: ‘/astproxy’,
  preHandler: function (req, res, done) {
  if (!req.headers.authorization) {
// do ahutentication
}
}
}
serverF.listen(port, address, (err, address) => { ... });
f a s t i f y - h t t p - p r o x y
0
175
350
525
700
Restify Fastify Rest Fastify Proxy + Rest
+48%
+22%
Req/sec
Autocannon results
I want a
R E A L S C E N A R I O ! ! !
Test Scenario 2
Test Scenario 2
┌───────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┐
│ Stat │ 1% │ 2.5% │ 50% │ 97.5% │ Avg │ Stdev │ Min │
├───────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────┤
│ Req/Sec │ 51 │ 51 │ 180 │ 239 │ 164.65 │ 57.3 │ 51 │
├───────────┼────────┼────────┼────────┼────────┼────────┼────────┼────────┤
│ Bytes/Sec │ 165 kB │ 165 kB │ 582 kB │ 773 kB │ 532 kB │ 185 kB │ 165 kB │
└───────────┴────────┴────────┴────────┴────────┴────────┴────────┴────────┘
┌───────────┬─────┬──────┬────────┬────────┬────────┬────────┬────────┐
│ Stat │ 1% │ 2.5% │ 50% │ 97.5% │ Avg │ Stdev │ Min │
├───────────┼─────┼──────┼────────┼────────┼────────┼────────┼────────┤
│ Req/Sec │ 0 │ 0 │ 236 │ 285 │ 213.6 │ 70.19 │ 45 │
├───────────┼─────┼──────┼────────┼────────┼────────┼────────┼────────┤
│ Bytes/Sec │ 0 B │ 0 B │ 772 kB │ 932 kB │ 698 kB │ 229 kB │ 147 kB │
└───────────┴─────┴──────┴────────┴────────┴────────┴────────┴────────┘
+33%
restify
Fastify
Something about
Fastify
Fastify story
Fastify story
Rest API
Plugin
Features Plugins
• https://github.com/fastify/help

• https://gitter.im/fastify

• Stack Overflow
Help
www.fastify.io
ALESSANDRO POLIDORI
Senior Software Engineer
ale_polidori
alessandropolidori
alepolidori

Weitere ähnliche Inhalte

Empfohlen

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Empfohlen (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Presentation @ Node.js Global Summit 2020 - Online