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

DNS移転失敗体験談
DNS移転失敗体験談DNS移転失敗体験談
DNS移転失敗体験談oheso tori
 
Stream Processing 과 Confluent Cloud 시작하기
Stream Processing 과 Confluent Cloud 시작하기Stream Processing 과 Confluent Cloud 시작하기
Stream Processing 과 Confluent Cloud 시작하기confluent
 
k8s初心者が gRPC × envoyを導入したら色々苦労した話 #yjbonfire
k8s初心者が gRPC × envoyを導入したら色々苦労した話 #yjbonfirek8s初心者が gRPC × envoyを導入したら色々苦労した話 #yjbonfire
k8s初心者が gRPC × envoyを導入したら色々苦労した話 #yjbonfireYahoo!デベロッパーネットワーク
 
Quic을 이용한 네트워크 성능 개선
 Quic을 이용한 네트워크 성능 개선 Quic을 이용한 네트워크 성능 개선
Quic을 이용한 네트워크 성능 개선NAVER D2
 
Zipf分布に従う乱数の生成方法
Zipf分布に従う乱数の生成方法Zipf分布に従う乱数の生成方法
Zipf分布に従う乱数の生成方法Maruyama Tetsutaro
 
処理概要図&構築手順書1124
処理概要図&構築手順書1124処理概要図&構築手順書1124
処理概要図&構築手順書1124Kazuki Miura
 
JVM @ Taobao - QCon Hangzhou 2011
JVM @ Taobao - QCon Hangzhou 2011JVM @ Taobao - QCon Hangzhou 2011
JVM @ Taobao - QCon Hangzhou 2011Kris Mok
 
Wireshark入門 (2014版)
Wireshark入門 (2014版)Wireshark入門 (2014版)
Wireshark入門 (2014版)彰 村地
 
DB 모니터링 신규 & 개선 기능 (박명규)
DB 모니터링 신규 & 개선 기능 (박명규)DB 모니터링 신규 & 개선 기능 (박명규)
DB 모니터링 신규 & 개선 기능 (박명규)WhaTap Labs
 
WebRTCがよく分からないから調べて試してみた
WebRTCがよく分からないから調べて試してみたWebRTCがよく分からないから調べて試してみた
WebRTCがよく分からないから調べて試してみたtoru tom
 
IBM JVM 소개 - Oracle JVM 과 비교
IBM JVM 소개 - Oracle JVM 과 비교IBM JVM 소개 - Oracle JVM 과 비교
IBM JVM 소개 - Oracle JVM 과 비교JungWoon Lee
 
gloops流データアナリストの部署間連携術
gloops流データアナリストの部署間連携術gloops流データアナリストの部署間連携術
gloops流データアナリストの部署間連携術gloops, Inc.
 
Temporal-Joins in Kafka Streams and ksqlDB | Matthias Sax, Confluent
Temporal-Joins in Kafka Streams and ksqlDB | Matthias Sax, ConfluentTemporal-Joins in Kafka Streams and ksqlDB | Matthias Sax, Confluent
Temporal-Joins in Kafka Streams and ksqlDB | Matthias Sax, ConfluentHostedbyConfluent
 
SDN입문 (Overlay and Underlay)
SDN입문 (Overlay and Underlay)SDN입문 (Overlay and Underlay)
SDN입문 (Overlay and Underlay)NAIM Networks, Inc.
 
[2019] 200만 동접 게임을 위한 MySQL 샤딩
[2019] 200만 동접 게임을 위한 MySQL 샤딩[2019] 200만 동접 게임을 위한 MySQL 샤딩
[2019] 200만 동접 게임을 위한 MySQL 샤딩NHN FORWARD
 
パケットキャプチャの勘どころ Ssmjp 201501
パケットキャプチャの勘どころ Ssmjp 201501パケットキャプチャの勘どころ Ssmjp 201501
パケットキャプチャの勘どころ Ssmjp 201501稔 小林
 
WebRTC mediasoup on raspberrypi3
WebRTC mediasoup on raspberrypi3WebRTC mediasoup on raspberrypi3
WebRTC mediasoup on raspberrypi3mganeko
 
Non-Fluff Software Defined Networking, Network Function Virtualization and IoT
Non-Fluff Software Defined Networking, Network Function Virtualization and IoTNon-Fluff Software Defined Networking, Network Function Virtualization and IoT
Non-Fluff Software Defined Networking, Network Function Virtualization and IoTMark Ryan Castellani
 

What's hot (20)

DNS移転失敗体験談
DNS移転失敗体験談DNS移転失敗体験談
DNS移転失敗体験談
 
Stream Processing 과 Confluent Cloud 시작하기
Stream Processing 과 Confluent Cloud 시작하기Stream Processing 과 Confluent Cloud 시작하기
Stream Processing 과 Confluent Cloud 시작하기
 
k8s初心者が gRPC × envoyを導入したら色々苦労した話 #yjbonfire
k8s初心者が gRPC × envoyを導入したら色々苦労した話 #yjbonfirek8s初心者が gRPC × envoyを導入したら色々苦労した話 #yjbonfire
k8s初心者が gRPC × envoyを導入したら色々苦労した話 #yjbonfire
 
Quic을 이용한 네트워크 성능 개선
 Quic을 이용한 네트워크 성능 개선 Quic을 이용한 네트워크 성능 개선
Quic을 이용한 네트워크 성능 개선
 
Zipf分布に従う乱数の生成方法
Zipf分布に従う乱数の生成方法Zipf分布に従う乱数の生成方法
Zipf分布に従う乱数の生成方法
 
処理概要図&構築手順書1124
処理概要図&構築手順書1124処理概要図&構築手順書1124
処理概要図&構築手順書1124
 
JVM @ Taobao - QCon Hangzhou 2011
JVM @ Taobao - QCon Hangzhou 2011JVM @ Taobao - QCon Hangzhou 2011
JVM @ Taobao - QCon Hangzhou 2011
 
Wireshark入門 (2014版)
Wireshark入門 (2014版)Wireshark入門 (2014版)
Wireshark入門 (2014版)
 
DB 모니터링 신규 & 개선 기능 (박명규)
DB 모니터링 신규 & 개선 기능 (박명규)DB 모니터링 신규 & 개선 기능 (박명규)
DB 모니터링 신규 & 개선 기능 (박명규)
 
WebRTCがよく分からないから調べて試してみた
WebRTCがよく分からないから調べて試してみたWebRTCがよく分からないから調べて試してみた
WebRTCがよく分からないから調べて試してみた
 
IBM JVM 소개 - Oracle JVM 과 비교
IBM JVM 소개 - Oracle JVM 과 비교IBM JVM 소개 - Oracle JVM 과 비교
IBM JVM 소개 - Oracle JVM 과 비교
 
DNSのRFCの歩き方
DNSのRFCの歩き方DNSのRFCの歩き方
DNSのRFCの歩き方
 
gloops流データアナリストの部署間連携術
gloops流データアナリストの部署間連携術gloops流データアナリストの部署間連携術
gloops流データアナリストの部署間連携術
 
Temporal-Joins in Kafka Streams and ksqlDB | Matthias Sax, Confluent
Temporal-Joins in Kafka Streams and ksqlDB | Matthias Sax, ConfluentTemporal-Joins in Kafka Streams and ksqlDB | Matthias Sax, Confluent
Temporal-Joins in Kafka Streams and ksqlDB | Matthias Sax, Confluent
 
SDN입문 (Overlay and Underlay)
SDN입문 (Overlay and Underlay)SDN입문 (Overlay and Underlay)
SDN입문 (Overlay and Underlay)
 
Sipwise rtpengine
Sipwise rtpengineSipwise rtpengine
Sipwise rtpengine
 
[2019] 200만 동접 게임을 위한 MySQL 샤딩
[2019] 200만 동접 게임을 위한 MySQL 샤딩[2019] 200만 동접 게임을 위한 MySQL 샤딩
[2019] 200만 동접 게임을 위한 MySQL 샤딩
 
パケットキャプチャの勘どころ Ssmjp 201501
パケットキャプチャの勘どころ Ssmjp 201501パケットキャプチャの勘どころ Ssmjp 201501
パケットキャプチャの勘どころ Ssmjp 201501
 
WebRTC mediasoup on raspberrypi3
WebRTC mediasoup on raspberrypi3WebRTC mediasoup on raspberrypi3
WebRTC mediasoup on raspberrypi3
 
Non-Fluff Software Defined Networking, Network Function Virtualization and IoT
Non-Fluff Software Defined Networking, Network Function Virtualization and IoTNon-Fluff Software Defined Networking, Network Function Virtualization and IoT
Non-Fluff Software Defined Networking, Network Function Virtualization and IoT
 

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

Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
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
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number SystemsJheuzeDellosa
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationkaushalgiri8080
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...aditisharan08
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
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
 
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 

Recently uploaded (20)

Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
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
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number Systems
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanation
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
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)
 
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 

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 ;-)