SlideShare a Scribd company logo
1 of 47
Download to read offline
Crushing Latency
with Vert.x
Paulo Lopes
Principal Software Engineer
@pml0pes
https://www.linkedin.com/in/pmlopes/
pmlopes
latency noun
    la·ten·cy |  ˈlā-tᵊn(t)-sē 
Network latency is the term used to indicate any kind of delay
that happens in data communication over a network.
(techopedia.com)
Latency by the numbers
Amazon: every 100ms of latency costs 1% in
sales
Google: an extra 0.5 seconds in search page
generation time dropped tra c by 20%
A broker: could lose $4 million in revenues per
millisecond if their electronic trading platform is
5 milliseconds behind the competition
http://home.blarg.net/~glinden/StanfordDataMining.2006-11-29.ppt
http://glinden.blogspot.com/2006/11/marissa-mayer-at-web-20.html
http://www.tabbgroup.com/PublicationDetail.aspx?PublicationID=346
Latency is not the problem
it's the symptom!
2007:
Dan Pritchett
Loosely Couple Components
Use Asynchronous Interfaces
Horizontally Scale from the Start
Create an Active/Active Architecture
Use a BASE instead of ACID Shared Storage
Mode
www.infoq.com/articles/pritchett-latency
2011 (Tim Fox):
Vert.x
Loosely Couple Components (event bus)
Use Asynchronous Interfaces(non blocking I/O)
Horizontally Scale from the Start (clustered)
Eclipse Vert.x is a tool-kit for building reactive
applications on the JVM. https://vertx.io/
Why Non-Blocking
I/O?
5ms / req time
...
# In optimal circumstances
1 Thread => 200 req/sec
8 Cores => 1600 req/sec
req time grows as threads
fight for execution time
...
# PROCESS STATE CODES
# D Uninterruptible sleep (usually IO)
ps aux | awk '$8 ~ /D/ { print $0 }'
root 9324 0.0 0.0 8316 436 ? D< Oct15 0:00 /usr/bin/java...
when load is higher than max
threads queuing builds up
...
# git@github.com:tsuna/contextswitch.git
./cpubench.sh
model name : Intel(R) Core(TM) i7-8650U CPU @ 1.90GHz
1 physical CPUs, 4 cores/CPU, 2 hardware threads/core
2000000 thread context switches in 2231974869ns
(1116.0ns/ctxsw)
grep 'CONFIG_HZ=' /boot/config-$(uname -r)
# CONFIG_HZ=1000
Practical example:
Tomcat 9.0
Default maxThreads: 200
Avg req time: 5ms
Hypothetical High load: 1000 req
Wasted wait/queue time: (1000 / 200 - 1) * 5 =
0~20ms
https://tomcat.apache.org/tomcat-9.0-doc/con g/executor.html
at max utilization
CPU is mostly waiting
Non-Blocking I/O
Events
Vert.x
Request handler
AUTH handler
DB handler
JSON handler
1 CPU core fully used!
Vert.x
Intel(R) Core(TM) i7-8650U CPU @ 1.90GHz
100% CPU cores used!
Benchmarking is hard
Meaningful benchmarks are even harder
Techempower Framework Benchmarks
Contributors: 528
Pull Requests: 4022
Commits: 11095
https://github.com/TechEmpower/FrameworkBenchmarks
Baseline: JAX-RS
Blocking API
Thread Based
Java
jax-rs vert.x
@GET
@Path("/queries")
World[]
queries(@QueryParam("queries") String queries)
{
World[] worlds = new World[queries];
Session session = emf.createEntityManager();
for (int i = 0; i < queries; i++) {
worlds[i] = session
.byId(World.class)
.load(randomWorld());
}
return worlds;
}
void
queriesHandler(final RoutingContext ctx) {
World[] worlds = new World[getQueries(ctx)];
AtomicInteger cnt = new AtomicInteger();
for (int i = 0; i < getQueries(ctx); i++) {
db.preparedQuery(FIND_WORLD, ..., res -> {
final Row row = res.result()
.iterator()
.next();
worlds[cnt.incrementAndGet()] =
new World(row);
if (cnt.get() == queries) {
ctx.response()
.end(Json.encodeToBuffer(worlds));
}
});
}
}
Simple results
Vert.x: 37,157 req/s
Jax-RS: 14,493 req/s
Polyglot
English - 简体中文 - Português
What happens when you say
Hello?
function handler (context) {
// the exchange context
context
// get the response object
.response()
// send the message and end
// the response
.end('你好');
}
Getting the response object
that.cachedresponse = utils.convReturnVertxGen(
HttpServerResponse,
j_routingContext["response()"]());
this.response = function() {1
var __args = arguments;2
if (__args.length === 0) {3
if (that.cachedresponse == null) {4
5
6
7
}8
return that.cachedresponse;9
} else if (typeof __super_response != 'undefined') {10
return __super_response.apply(this, __args);11
}12
else throw new TypeError('invalid arguments');13
};14
In a nutshell
Lots of conversions (GC)
Constant switch from JS engine to Java code
(somehow similar to context switching)
Not suited for performance
JIT optimization will stop at language cross
Node.js
JIT can't optimize it all
Where's Node?
🤔
Can we make polyglot
fast?
https://graalvm.org
https://graalvm.org
GraalVM: In a nutshell
Lots of conversions (GC)
Constant switch from JS engine to Java code
(somehow similar to context switching)
Not suited for performance
JIT optimization will stop at language cross
ES4X
GraalVM based
Vert.x for I/O
commonjs and ESM loader
debug/pro le chrome-devtools
https://reactiverse.io/es4x
ES4X design principles
GraalJS (for fast JS runtime)
Vert.x (for fast I/O + event loops)
GraalVM (for full JIT)
.d.ts (for IDE support)
github.com/AlDanial/cloc v 1.72 T=0.09 s (401.5 files/s, 51963.8 lines/s)
-------------------------------------------------------------------------------
Language files blank comment code
-------------------------------------------------------------------------------
Java 26 389 683 1778
JavaScript 9 201 253 1226
-------------------------------------------------------------------------------
SUM: 35 590 936 3004
-------------------------------------------------------------------------------
Node.js vs
ES4X
const cluster = require('cluster'),
numCPUs = require('os').cpus().length,
express = require('express');
if (cluster.isMaster) {
for (let i = 0; i < numCPUs; i++)
cluster.fork();
} else {
const app = module.exports = express();
app.get('/plaintext', (req, res) =>
res
.header('Content-Type', 'text/plain')
.send('Hello, World!'));
}
import { Router } from '@vertx/web';
const app = Router.router(vertx);
app.get("/plaintext").handler(ctx => {
ctx.response()
.putHeader("Content-Type", "text/plain")
.end('Hello, World!');
});
Polyglot GraalVM is
fast.
what about latency?
Conclusion
latency is not a problem, it's a symptom
use non-blocking to fully use the CPU
use vert.x ;-)
polyglot is ne
use graalvm for polyglot JIT optimizations
node can be slow for server applications
use ES4X ;-)
Let's connect!
@pml0pes
pmlopes
https://www.linkedin.com/in/pmlopes/
https://reactiverse.io/es4x
https://vertx.io
https://graalvm.org
Crushing Latency with Vert.x

More Related Content

What's hot

IPv4/IPv6 移行・共存技術の動向
IPv4/IPv6 移行・共存技術の動向IPv4/IPv6 移行・共存技術の動向
IPv4/IPv6 移行・共存技術の動向Yuya Rin
 
ゲームボーイ向けOSの作り方
ゲームボーイ向けOSの作り方ゲームボーイ向けOSの作り方
ゲームボーイ向けOSの作り方Yuma Ohgami
 
3D描画基礎知識
3D描画基礎知識3D描画基礎知識
3D描画基礎知識AimingStudy
 
GDG Dev Fest Tokyo 2019
GDG Dev Fest Tokyo 2019GDG Dev Fest Tokyo 2019
GDG Dev Fest Tokyo 2019yoshikishibata
 
Cours Système Embarqué et Système d'exploitation mobile.pdf
Cours Système Embarqué et Système d'exploitation mobile.pdfCours Système Embarqué et Système d'exploitation mobile.pdf
Cours Système Embarqué et Système d'exploitation mobile.pdfWahideArabe
 
Protocole RIP1, RIP2, RIPng
Protocole RIP1, RIP2, RIPngProtocole RIP1, RIP2, RIPng
Protocole RIP1, RIP2, RIPngMax Benana
 
C++のライブラリを簡単に眺めてみよう
C++のライブラリを簡単に眺めてみようC++のライブラリを簡単に眺めてみよう
C++のライブラリを簡単に眺めてみようHiro H.
 
Scala警察のすすめ
Scala警察のすすめScala警察のすすめ
Scala警察のすすめtakezoe
 
C#や.NET Frameworkがやっていること
C#や.NET FrameworkがやっていることC#や.NET Frameworkがやっていること
C#や.NET Frameworkがやっていること信之 岩永
 
どうして昔の人は八進数でしゃべるのか?
どうして昔の人は八進数でしゃべるのか?どうして昔の人は八進数でしゃべるのか?
どうして昔の人は八進数でしゃべるのか?たけおか しょうぞう
 
High Availability Storage (susecon2016)
High Availability Storage (susecon2016)High Availability Storage (susecon2016)
High Availability Storage (susecon2016)Roger Zhou 周志强
 
Point de vente ( Odoo )
Point de vente ( Odoo ) Point de vente ( Odoo )
Point de vente ( Odoo ) KARIZMA CONSEIL
 
alphorm.com - Formation Cisco ICND1-CCENT (100-101)
alphorm.com - Formation Cisco ICND1-CCENT (100-101)alphorm.com - Formation Cisco ICND1-CCENT (100-101)
alphorm.com - Formation Cisco ICND1-CCENT (100-101)Alphorm
 
2015年度先端GPGPUシミュレーション工学特論 第2回 GPUによる並列計算の概念と メモリアクセス
2015年度先端GPGPUシミュレーション工学特論 第2回 GPUによる並列計算の概念とメモリアクセス2015年度先端GPGPUシミュレーション工学特論 第2回 GPUによる並列計算の概念とメモリアクセス
2015年度先端GPGPUシミュレーション工学特論 第2回 GPUによる並列計算の概念と メモリアクセス智啓 出川
 
Technologies d'accès à Internet
Technologies d'accès à InternetTechnologies d'accès à Internet
Technologies d'accès à InternetRetis be
 
Résumé projet Smart Traffic Managment System Real Time (STMSRT)
Résumé projet Smart Traffic Managment System Real Time (STMSRT)Résumé projet Smart Traffic Managment System Real Time (STMSRT)
Résumé projet Smart Traffic Managment System Real Time (STMSRT)Ayoub Rouzi
 

What's hot (20)

IPv4/IPv6 移行・共存技術の動向
IPv4/IPv6 移行・共存技術の動向IPv4/IPv6 移行・共存技術の動向
IPv4/IPv6 移行・共存技術の動向
 
ゲームボーイ向けOSの作り方
ゲームボーイ向けOSの作り方ゲームボーイ向けOSの作り方
ゲームボーイ向けOSの作り方
 
データセンターネットワークでのPrometheus活用事例
データセンターネットワークでのPrometheus活用事例データセンターネットワークでのPrometheus活用事例
データセンターネットワークでのPrometheus活用事例
 
3D描画基礎知識
3D描画基礎知識3D描画基礎知識
3D描画基礎知識
 
GDG Dev Fest Tokyo 2019
GDG Dev Fest Tokyo 2019GDG Dev Fest Tokyo 2019
GDG Dev Fest Tokyo 2019
 
Cours Système Embarqué et Système d'exploitation mobile.pdf
Cours Système Embarqué et Système d'exploitation mobile.pdfCours Système Embarqué et Système d'exploitation mobile.pdf
Cours Système Embarqué et Système d'exploitation mobile.pdf
 
RISC-V User level ISA
RISC-V User level ISARISC-V User level ISA
RISC-V User level ISA
 
Protocole RIP1, RIP2, RIPng
Protocole RIP1, RIP2, RIPngProtocole RIP1, RIP2, RIPng
Protocole RIP1, RIP2, RIPng
 
C++のライブラリを簡単に眺めてみよう
C++のライブラリを簡単に眺めてみようC++のライブラリを簡単に眺めてみよう
C++のライブラリを簡単に眺めてみよう
 
Scala警察のすすめ
Scala警察のすすめScala警察のすすめ
Scala警察のすすめ
 
C#や.NET Frameworkがやっていること
C#や.NET FrameworkがやっていることC#や.NET Frameworkがやっていること
C#や.NET Frameworkがやっていること
 
どうして昔の人は八進数でしゃべるのか?
どうして昔の人は八進数でしゃべるのか?どうして昔の人は八進数でしゃべるのか?
どうして昔の人は八進数でしゃべるのか?
 
High Availability Storage (susecon2016)
High Availability Storage (susecon2016)High Availability Storage (susecon2016)
High Availability Storage (susecon2016)
 
Wireguard 実践入門
Wireguard 実践入門Wireguard 実践入門
Wireguard 実践入門
 
Point de vente ( Odoo )
Point de vente ( Odoo ) Point de vente ( Odoo )
Point de vente ( Odoo )
 
alphorm.com - Formation Cisco ICND1-CCENT (100-101)
alphorm.com - Formation Cisco ICND1-CCENT (100-101)alphorm.com - Formation Cisco ICND1-CCENT (100-101)
alphorm.com - Formation Cisco ICND1-CCENT (100-101)
 
2015年度先端GPGPUシミュレーション工学特論 第2回 GPUによる並列計算の概念と メモリアクセス
2015年度先端GPGPUシミュレーション工学特論 第2回 GPUによる並列計算の概念とメモリアクセス2015年度先端GPGPUシミュレーション工学特論 第2回 GPUによる並列計算の概念とメモリアクセス
2015年度先端GPGPUシミュレーション工学特論 第2回 GPUによる並列計算の概念と メモリアクセス
 
Timers
TimersTimers
Timers
 
Technologies d'accès à Internet
Technologies d'accès à InternetTechnologies d'accès à Internet
Technologies d'accès à Internet
 
Résumé projet Smart Traffic Managment System Real Time (STMSRT)
Résumé projet Smart Traffic Managment System Real Time (STMSRT)Résumé projet Smart Traffic Managment System Real Time (STMSRT)
Résumé projet Smart Traffic Managment System Real Time (STMSRT)
 

Similar to Crushing Latency with Vert.x

Introduction to Real Time Java
Introduction to Real Time JavaIntroduction to Real Time Java
Introduction to Real Time JavaDeniz Oguz
 
Clug 2011 March web server optimisation
Clug 2011 March  web server optimisationClug 2011 March  web server optimisation
Clug 2011 March web server optimisationgrooverdan
 
Overview Of Parallel Development - Ericnel
Overview Of Parallel Development -  EricnelOverview Of Parallel Development -  Ericnel
Overview Of Parallel Development - Ericnelukdpe
 
Scalable Apache for Beginners
Scalable Apache for BeginnersScalable Apache for Beginners
Scalable Apache for Beginnerswebhostingguy
 
Non-blocking I/O, Event loops and node.js
Non-blocking I/O, Event loops and node.jsNon-blocking I/O, Event loops and node.js
Non-blocking I/O, Event loops and node.jsMarcus Frödin
 
Profiling PHP with Xdebug / Webgrind
Profiling PHP with Xdebug / WebgrindProfiling PHP with Xdebug / Webgrind
Profiling PHP with Xdebug / WebgrindSam Keen
 
The Value of Reactive
The Value of ReactiveThe Value of Reactive
The Value of ReactiveVMware Tanzu
 
Five cool ways the JVM can run Apache Spark faster
Five cool ways the JVM can run Apache Spark fasterFive cool ways the JVM can run Apache Spark faster
Five cool ways the JVM can run Apache Spark fasterTim Ellison
 
Mirage: ML kernels in the cloud (ML Workshop 2010)
Mirage: ML kernels in the cloud (ML Workshop 2010)Mirage: ML kernels in the cloud (ML Workshop 2010)
Mirage: ML kernels in the cloud (ML Workshop 2010)Anil Madhavapeddy
 
Linux Kernel vs DPDK: HTTP Performance Showdown
Linux Kernel vs DPDK: HTTP Performance ShowdownLinux Kernel vs DPDK: HTTP Performance Showdown
Linux Kernel vs DPDK: HTTP Performance ShowdownScyllaDB
 
Extreme HTTP Performance Tuning: 1.2M API req/s on a 4 vCPU EC2 Instance
Extreme HTTP Performance Tuning: 1.2M API req/s on a 4 vCPU EC2 InstanceExtreme HTTP Performance Tuning: 1.2M API req/s on a 4 vCPU EC2 Instance
Extreme HTTP Performance Tuning: 1.2M API req/s on a 4 vCPU EC2 InstanceScyllaDB
 
Технологии работы с дисковыми хранилищами и файловыми системами Windows Serve...
Технологии работы с дисковыми хранилищами и файловыми системами Windows Serve...Технологии работы с дисковыми хранилищами и файловыми системами Windows Serve...
Технологии работы с дисковыми хранилищами и файловыми системами Windows Serve...Виталий Стародубцев
 
How to deploy & optimize eZ Publish (2014)
How to deploy & optimize eZ Publish (2014)How to deploy & optimize eZ Publish (2014)
How to deploy & optimize eZ Publish (2014)Kaliop-slide
 
Hands on with CoAP and Californium
Hands on with CoAP and CaliforniumHands on with CoAP and Californium
Hands on with CoAP and CaliforniumJulien Vermillard
 
Nagios Conference 2014 - Gerald Combs - A Trillion Truths
Nagios Conference 2014 - Gerald Combs - A Trillion TruthsNagios Conference 2014 - Gerald Combs - A Trillion Truths
Nagios Conference 2014 - Gerald Combs - A Trillion TruthsNagios
 
Being HAPI! Reverse Proxying on Purpose
Being HAPI! Reverse Proxying on PurposeBeing HAPI! Reverse Proxying on Purpose
Being HAPI! Reverse Proxying on PurposeAman Kohli
 

Similar to Crushing Latency with Vert.x (20)

Introduction to Real Time Java
Introduction to Real Time JavaIntroduction to Real Time Java
Introduction to Real Time Java
 
Clug 2011 March web server optimisation
Clug 2011 March  web server optimisationClug 2011 March  web server optimisation
Clug 2011 March web server optimisation
 
Overview Of Parallel Development - Ericnel
Overview Of Parallel Development -  EricnelOverview Of Parallel Development -  Ericnel
Overview Of Parallel Development - Ericnel
 
Scalable Apache for Beginners
Scalable Apache for BeginnersScalable Apache for Beginners
Scalable Apache for Beginners
 
Non-blocking I/O, Event loops and node.js
Non-blocking I/O, Event loops and node.jsNon-blocking I/O, Event loops and node.js
Non-blocking I/O, Event loops and node.js
 
Velocity 2010 - ATS
Velocity 2010 - ATSVelocity 2010 - ATS
Velocity 2010 - ATS
 
netty_qcon_v4
netty_qcon_v4netty_qcon_v4
netty_qcon_v4
 
Profiling PHP with Xdebug / Webgrind
Profiling PHP with Xdebug / WebgrindProfiling PHP with Xdebug / Webgrind
Profiling PHP with Xdebug / Webgrind
 
The value of reactive
The value of reactiveThe value of reactive
The value of reactive
 
The Value of Reactive
The Value of ReactiveThe Value of Reactive
The Value of Reactive
 
Five cool ways the JVM can run Apache Spark faster
Five cool ways the JVM can run Apache Spark fasterFive cool ways the JVM can run Apache Spark faster
Five cool ways the JVM can run Apache Spark faster
 
Rit 2011 ats
Rit 2011 atsRit 2011 ats
Rit 2011 ats
 
Mirage: ML kernels in the cloud (ML Workshop 2010)
Mirage: ML kernels in the cloud (ML Workshop 2010)Mirage: ML kernels in the cloud (ML Workshop 2010)
Mirage: ML kernels in the cloud (ML Workshop 2010)
 
Linux Kernel vs DPDK: HTTP Performance Showdown
Linux Kernel vs DPDK: HTTP Performance ShowdownLinux Kernel vs DPDK: HTTP Performance Showdown
Linux Kernel vs DPDK: HTTP Performance Showdown
 
Extreme HTTP Performance Tuning: 1.2M API req/s on a 4 vCPU EC2 Instance
Extreme HTTP Performance Tuning: 1.2M API req/s on a 4 vCPU EC2 InstanceExtreme HTTP Performance Tuning: 1.2M API req/s on a 4 vCPU EC2 Instance
Extreme HTTP Performance Tuning: 1.2M API req/s on a 4 vCPU EC2 Instance
 
Технологии работы с дисковыми хранилищами и файловыми системами Windows Serve...
Технологии работы с дисковыми хранилищами и файловыми системами Windows Serve...Технологии работы с дисковыми хранилищами и файловыми системами Windows Serve...
Технологии работы с дисковыми хранилищами и файловыми системами Windows Serve...
 
How to deploy & optimize eZ Publish (2014)
How to deploy & optimize eZ Publish (2014)How to deploy & optimize eZ Publish (2014)
How to deploy & optimize eZ Publish (2014)
 
Hands on with CoAP and Californium
Hands on with CoAP and CaliforniumHands on with CoAP and Californium
Hands on with CoAP and Californium
 
Nagios Conference 2014 - Gerald Combs - A Trillion Truths
Nagios Conference 2014 - Gerald Combs - A Trillion TruthsNagios Conference 2014 - Gerald Combs - A Trillion Truths
Nagios Conference 2014 - Gerald Combs - A Trillion Truths
 
Being HAPI! Reverse Proxying on Purpose
Being HAPI! Reverse Proxying on PurposeBeing HAPI! Reverse Proxying on Purpose
Being HAPI! Reverse Proxying on Purpose
 

Recently uploaded

Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)jennyeacort
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfPower Karaoke
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 

Recently uploaded (20)

Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdf
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 

Crushing Latency with Vert.x

  • 1. Crushing Latency with Vert.x Paulo Lopes Principal Software Engineer @pml0pes https://www.linkedin.com/in/pmlopes/ pmlopes
  • 2.
  • 3. latency noun     la·ten·cy | ˈlā-tᵊn(t)-sē Network latency is the term used to indicate any kind of delay that happens in data communication over a network. (techopedia.com)
  • 4. Latency by the numbers Amazon: every 100ms of latency costs 1% in sales Google: an extra 0.5 seconds in search page generation time dropped tra c by 20% A broker: could lose $4 million in revenues per millisecond if their electronic trading platform is 5 milliseconds behind the competition http://home.blarg.net/~glinden/StanfordDataMining.2006-11-29.ppt http://glinden.blogspot.com/2006/11/marissa-mayer-at-web-20.html http://www.tabbgroup.com/PublicationDetail.aspx?PublicationID=346
  • 5. Latency is not the problem it's the symptom!
  • 6. 2007: Dan Pritchett Loosely Couple Components Use Asynchronous Interfaces Horizontally Scale from the Start Create an Active/Active Architecture Use a BASE instead of ACID Shared Storage Mode www.infoq.com/articles/pritchett-latency
  • 7. 2011 (Tim Fox): Vert.x Loosely Couple Components (event bus) Use Asynchronous Interfaces(non blocking I/O) Horizontally Scale from the Start (clustered) Eclipse Vert.x is a tool-kit for building reactive applications on the JVM. https://vertx.io/
  • 9. 5ms / req time ... # In optimal circumstances 1 Thread => 200 req/sec 8 Cores => 1600 req/sec
  • 10. req time grows as threads fight for execution time ... # PROCESS STATE CODES # D Uninterruptible sleep (usually IO) ps aux | awk '$8 ~ /D/ { print $0 }' root 9324 0.0 0.0 8316 436 ? D< Oct15 0:00 /usr/bin/java...
  • 11. when load is higher than max threads queuing builds up ... # git@github.com:tsuna/contextswitch.git ./cpubench.sh model name : Intel(R) Core(TM) i7-8650U CPU @ 1.90GHz 1 physical CPUs, 4 cores/CPU, 2 hardware threads/core 2000000 thread context switches in 2231974869ns (1116.0ns/ctxsw)
  • 13. Practical example: Tomcat 9.0 Default maxThreads: 200 Avg req time: 5ms Hypothetical High load: 1000 req Wasted wait/queue time: (1000 / 200 - 1) * 5 = 0~20ms https://tomcat.apache.org/tomcat-9.0-doc/con g/executor.html
  • 14. at max utilization CPU is mostly waiting
  • 17. 1 CPU core fully used!
  • 19. 100% CPU cores used!
  • 20. Benchmarking is hard Meaningful benchmarks are even harder Techempower Framework Benchmarks Contributors: 528 Pull Requests: 4022 Commits: 11095 https://github.com/TechEmpower/FrameworkBenchmarks
  • 22. jax-rs vert.x @GET @Path("/queries") World[] queries(@QueryParam("queries") String queries) { World[] worlds = new World[queries]; Session session = emf.createEntityManager(); for (int i = 0; i < queries; i++) { worlds[i] = session .byId(World.class) .load(randomWorld()); } return worlds; } void queriesHandler(final RoutingContext ctx) { World[] worlds = new World[getQueries(ctx)]; AtomicInteger cnt = new AtomicInteger(); for (int i = 0; i < getQueries(ctx); i++) { db.preparedQuery(FIND_WORLD, ..., res -> { final Row row = res.result() .iterator() .next(); worlds[cnt.incrementAndGet()] = new World(row); if (cnt.get() == queries) { ctx.response() .end(Json.encodeToBuffer(worlds)); } }); } }
  • 23.
  • 24. Simple results Vert.x: 37,157 req/s Jax-RS: 14,493 req/s
  • 25.
  • 27. What happens when you say Hello? function handler (context) { // the exchange context context // get the response object .response() // send the message and end // the response .end('你好'); }
  • 28. Getting the response object that.cachedresponse = utils.convReturnVertxGen( HttpServerResponse, j_routingContext["response()"]()); this.response = function() {1 var __args = arguments;2 if (__args.length === 0) {3 if (that.cachedresponse == null) {4 5 6 7 }8 return that.cachedresponse;9 } else if (typeof __super_response != 'undefined') {10 return __super_response.apply(this, __args);11 }12 else throw new TypeError('invalid arguments');13 };14
  • 29. In a nutshell Lots of conversions (GC) Constant switch from JS engine to Java code (somehow similar to context switching) Not suited for performance JIT optimization will stop at language cross
  • 33.
  • 34. 🤔 Can we make polyglot fast?
  • 37. GraalVM: In a nutshell Lots of conversions (GC) Constant switch from JS engine to Java code (somehow similar to context switching) Not suited for performance JIT optimization will stop at language cross
  • 38. ES4X GraalVM based Vert.x for I/O commonjs and ESM loader debug/pro le chrome-devtools https://reactiverse.io/es4x
  • 39. ES4X design principles GraalJS (for fast JS runtime) Vert.x (for fast I/O + event loops) GraalVM (for full JIT) .d.ts (for IDE support) github.com/AlDanial/cloc v 1.72 T=0.09 s (401.5 files/s, 51963.8 lines/s) ------------------------------------------------------------------------------- Language files blank comment code ------------------------------------------------------------------------------- Java 26 389 683 1778 JavaScript 9 201 253 1226 ------------------------------------------------------------------------------- SUM: 35 590 936 3004 -------------------------------------------------------------------------------
  • 40. Node.js vs ES4X const cluster = require('cluster'), numCPUs = require('os').cpus().length, express = require('express'); if (cluster.isMaster) { for (let i = 0; i < numCPUs; i++) cluster.fork(); } else { const app = module.exports = express(); app.get('/plaintext', (req, res) => res .header('Content-Type', 'text/plain') .send('Hello, World!')); } import { Router } from '@vertx/web'; const app = Router.router(vertx); app.get("/plaintext").handler(ctx => { ctx.response() .putHeader("Content-Type", "text/plain") .end('Hello, World!'); });
  • 41.
  • 42.
  • 44.
  • 45. Conclusion latency is not a problem, it's a symptom use non-blocking to fully use the CPU use vert.x ;-) polyglot is ne use graalvm for polyglot JIT optimizations node can be slow for server applications use ES4X ;-)