SlideShare une entreprise Scribd logo
1  sur  70
Télécharger pour lire hors ligne
Vanilla java or handling
10k req/sec per core
Dmitriy Dumanskiy
Blynk
Co-Founder / Java / Android
Java blog : http://habrahabr.ru/users/doom369/topics
DOU : http://dou.ua/users/DOOM/articles/
Experience
mGage - 3k req/sec
mobclix - 6k req/sec
xxxx - 11k req/sec
Visa
Load : ~2000 req/sec
Twitter : new tweets
Load : ~6000 req/sec
Facebook messenger
Load : 300k req/sec
IoT Market
● 4.4 billion devices right now (70$ b)
● 25 billion devices per 2020 (270$ b)
Makers problem
+ = ?
Problem
● Thousands of connections
● Keep-alive
● Security
● Pulling / polling
● Simplicity
IoT Protocols
HTTP, MQTT, XMPP, AMQP, CoAP
Minimum packet size
● HTTP - 26 bytes (~70 bytes)
● MQTT - 2 bytes
● Blynk - 3 bytes
Blocking IO
connection new Socket()
new
Thread()
read / writeServer Socket
Blocking IO
● 256kb stack
● 1k threads == 250 MB of RAM
● Сontext switching
Non-Blocking
new Socket()
read / write
Selector
Thread
new Socket()
read / write
new Socket()
read / write
Non-Blocking
● Few threads. Usually - n cores x 2.
● No context switching
● No memory consumption
Non-blocking frameworks
● Apache MINA
● Grizzly
● Xnio
● Vert.x
● Akka
● Netty
Non-blocking frameworks
● Apache MINA
● Grizzly
● Xnio
● Vert.x
● Akka
● Netty
Non-blocking frameworks
● Apache MINA
● Grizzly
● Xnio
● Vert.x
● Akka
● Netty
Non-blocking frameworks
● Apache MINA
● Grizzly
● Xnio
● Vert.x
● Akka
● Netty
Non-blocking frameworks
● Apache MINA
● Grizzly
● Xnio
● Vert.x
● Akka
● Netty
Netty
Netty cons
Netty is hard. 2-3 weeks onboarding
Netty cons
Bad documentation
Netty cons
Too many abstractions
Netty cons
Easy shot in the foot
Netty cons
ByteBuf
in.readBytes(length) - memory leak
in.readSlice(length) - ok
Netty cons
Still has bugs, 300 issues
Netty pros
Full control
TCP_FASTOPEN, TCP_MD5SIG, TCP_CORK,
TCP_KEEPCNT, TCP_KEEPIDLE, TCP_KEEPINTVL,
SPLICE
Netty pros
Supports everything
TCP, UDP, UDT, SCTP, HTTP, HTTPS, HTTP/2, SPDY,
Memcached, MQTT, etc
Netty pros
A lot of default Handlers
Netty pros
Fast
Netty pros
Super quick community help
Blynk architecture
https://github.com/blynkkk/blynk-server
Open source
https://github.com/blynkkk/blynk-library
Blynk stats
● ~2000 of hardware always online
● ~300 users always online
● ~1000 local Blynk Server installations
● ~3 Mbps in traffic
● ~7 billions requests per month
Blynk load
● 6% CPU with 2500 req/sec on 4 cores
● 10k req/sec per core
● 90% of requests - 3 handlers
● Only 3% requests are HTTP
Why so fast?
No blocking IO
Request
BE
Blocking IO Workers
Response
Batches
Request
BE
Response
Collector
1 min
batch
File System
What is your DB?
try (Writer writer = Files.newBufferedWriter(file)) {
writer.write(user.toString());
}
No synchronization
Client 1
connect
Selector Thread 1
assign
Client 2
connect
Selector Thread 2
assign
Client 2
login
Logic Thread 1
reregister
No GC pressure
ctx.write(new Response(mId));
vs
ByteBuf buf = ctx.alloc().directBuffer(1);
buf.writeByte(mId);
ctx.write(buf);
In memory
Set<User> users = JsonParser.parseUsers(dir);
+ 1 min batches
Native transports
● Native epoll
● Native OpenSSL
Version 1
Blynk monolith
80$
Version 1. Tech stack
● Vanilla Java 8
● Netty (HTTP, WebSockets, TCP/IP)
Version 1. Pros
Simple single jar deployment
java -jar server.jar
100ms start
Version 1. Pros
Simple backup script
Version 1. Pros
Single JVM, no cross-JVM shared state
Version 1. Pros
Entry level
Version 1. Cons
Single point of failure, single datacenter
Version 1. Cons
Latency is bad for distant locations
Version 1. Cons
Need to drop connections on redeploy
Version 2
Client
Get DNS record EUROPE
USA
ASIA
Geo DNS
50$
Version 2
● Improved latency
● No common storage anymore
Version 2
USA
Clients
DC 1
EU
Clients
DC 2
ASIA
Clients
DC 3
Version 3
USA
Clients
DC 1
EU
Clients
DB
ASIA
Clients
DC 3
Version 3. DB Cassandra
Node 1
Node 3
Node 2
Node 3
Node 2
Node 1
Node 3
Node 2
DC 1 DC 2
Node 1
15$
Version 3. DB Cassandra
● No typical batches
● Minimum requirement 1GB of RAM
● Performs poorly on low-end VMs
● Much slower than Postgres
Version 3. Final
USA
Clients
DC 1
EU
Clients
Postgres
ASIA
Clients
DC 3
65$
Version 3. Final
● 60k req/sec for 65$ (25x for current load)
● + 10x growth to 20 CPU
● Samsung cloud - 1 req/sec per 6$
Q & A

Contenu connexe

Tendances

Tendances (20)

MongoDB - Sharded Cluster Tutorial
MongoDB - Sharded Cluster TutorialMongoDB - Sharded Cluster Tutorial
MongoDB - Sharded Cluster Tutorial
 
MongoDB: Comparing WiredTiger In-Memory Engine to Redis
MongoDB: Comparing WiredTiger In-Memory Engine to RedisMongoDB: Comparing WiredTiger In-Memory Engine to Redis
MongoDB: Comparing WiredTiger In-Memory Engine to Redis
 
Back to Basics Webinar 6: Production Deployment
Back to Basics Webinar 6: Production DeploymentBack to Basics Webinar 6: Production Deployment
Back to Basics Webinar 6: Production Deployment
 
MongoDB Chunks - Distribution, Splitting, and Merging
MongoDB Chunks - Distribution, Splitting, and MergingMongoDB Chunks - Distribution, Splitting, and Merging
MongoDB Chunks - Distribution, Splitting, and Merging
 
opentsdb in a real enviroment
opentsdb in a real enviromentopentsdb in a real enviroment
opentsdb in a real enviroment
 
MongoDB - Ekino PHP
MongoDB - Ekino PHPMongoDB - Ekino PHP
MongoDB - Ekino PHP
 
Bucket Your Partitions Wisely (Markus Höfer, codecentric AG) | Cassandra Summ...
Bucket Your Partitions Wisely (Markus Höfer, codecentric AG) | Cassandra Summ...Bucket Your Partitions Wisely (Markus Höfer, codecentric AG) | Cassandra Summ...
Bucket Your Partitions Wisely (Markus Höfer, codecentric AG) | Cassandra Summ...
 
Triggers In MongoDB
Triggers In MongoDBTriggers In MongoDB
Triggers In MongoDB
 
Bucket your partitions wisely - Cassandra summit 2016
Bucket your partitions wisely - Cassandra summit 2016Bucket your partitions wisely - Cassandra summit 2016
Bucket your partitions wisely - Cassandra summit 2016
 
Managing Data and Operation Distribution In MongoDB
Managing Data and Operation Distribution In MongoDBManaging Data and Operation Distribution In MongoDB
Managing Data and Operation Distribution In MongoDB
 
Back to Basics, webinar 2: La tua prima applicazione MongoDB
Back to Basics, webinar 2: La tua prima applicazione MongoDBBack to Basics, webinar 2: La tua prima applicazione MongoDB
Back to Basics, webinar 2: La tua prima applicazione MongoDB
 
Back to Basics Webinar 3: Introduction to Replica Sets
Back to Basics Webinar 3: Introduction to Replica SetsBack to Basics Webinar 3: Introduction to Replica Sets
Back to Basics Webinar 3: Introduction to Replica Sets
 
Mongo Web Apps: OSCON 2011
Mongo Web Apps: OSCON 2011Mongo Web Apps: OSCON 2011
Mongo Web Apps: OSCON 2011
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
Using Aggregation for Analytics
Using Aggregation for Analytics Using Aggregation for Analytics
Using Aggregation for Analytics
 
Mux loves Clickhouse. By Adam Brown, Mux founder
Mux loves Clickhouse. By Adam Brown, Mux founderMux loves Clickhouse. By Adam Brown, Mux founder
Mux loves Clickhouse. By Adam Brown, Mux founder
 
Performance Tuning and Optimization
Performance Tuning and OptimizationPerformance Tuning and Optimization
Performance Tuning and Optimization
 
Using MongoDB with Kafka - Use Cases and Best Practices
Using MongoDB with Kafka -  Use Cases and Best PracticesUsing MongoDB with Kafka -  Use Cases and Best Practices
Using MongoDB with Kafka - Use Cases and Best Practices
 
Triggers in MongoDB
Triggers in MongoDBTriggers in MongoDB
Triggers in MongoDB
 
NoSQL Infrastructure - Late 2013
NoSQL Infrastructure - Late 2013NoSQL Infrastructure - Late 2013
NoSQL Infrastructure - Late 2013
 

En vedette

Tricks and Tips With NIO Using the Grizzly Framework
Tricks and Tips With NIO Using the Grizzly FrameworkTricks and Tips With NIO Using the Grizzly Framework
Tricks and Tips With NIO Using the Grizzly Framework
elliando dias
 

En vedette (10)

Hibernate performance tuning
Hibernate performance tuningHibernate performance tuning
Hibernate performance tuning
 
Hibernate, how the magic is really done
Hibernate, how the magic is really doneHibernate, how the magic is really done
Hibernate, how the magic is really done
 
Performance testing for web-scale
Performance testing for web-scalePerformance testing for web-scale
Performance testing for web-scale
 
Survey_Paper
Survey_PaperSurvey_Paper
Survey_Paper
 
Tricks and Tips With NIO Using the Grizzly Framework
Tricks and Tips With NIO Using the Grizzly FrameworkTricks and Tips With NIO Using the Grizzly Framework
Tricks and Tips With NIO Using the Grizzly Framework
 
A step-by-step approach toward high quality OutOfMemoryError analysis
A step-by-step approach toward high quality OutOfMemoryError analysisA step-by-step approach toward high quality OutOfMemoryError analysis
A step-by-step approach toward high quality OutOfMemoryError analysis
 
Search and analyze your data with elasticsearch
Search and analyze your data with elasticsearchSearch and analyze your data with elasticsearch
Search and analyze your data with elasticsearch
 
Angular2 Development for Java developers
Angular2 Development for Java developersAngular2 Development for Java developers
Angular2 Development for Java developers
 
Reactive Thinking in Java
Reactive Thinking in JavaReactive Thinking in Java
Reactive Thinking in Java
 
Java EE 8: What Servlet 4.0 and HTTP/2 mean to you
Java EE 8: What Servlet 4.0 and HTTP/2 mean to youJava EE 8: What Servlet 4.0 and HTTP/2 mean to you
Java EE 8: What Servlet 4.0 and HTTP/2 mean to you
 

Similaire à JEEConf. Vanilla java

Eduardo Silva - monkey http-server everywhere
Eduardo Silva - monkey http-server everywhereEduardo Silva - monkey http-server everywhere
Eduardo Silva - monkey http-server everywhere
StarTech Conference
 

Similaire à JEEConf. Vanilla java (20)

Datafying Bitcoins
Datafying BitcoinsDatafying Bitcoins
Datafying Bitcoins
 
Open Source SQL databases enter millions queries per second era
Open Source SQL databases enter millions queries per second eraOpen Source SQL databases enter millions queries per second era
Open Source SQL databases enter millions queries per second era
 
Windows Azure Storage – Architecture View
Windows Azure Storage – Architecture ViewWindows Azure Storage – Architecture View
Windows Azure Storage – Architecture View
 
Flink Forward Berlin 2017: Robert Metzger - Keep it going - How to reliably a...
Flink Forward Berlin 2017: Robert Metzger - Keep it going - How to reliably a...Flink Forward Berlin 2017: Robert Metzger - Keep it going - How to reliably a...
Flink Forward Berlin 2017: Robert Metzger - Keep it going - How to reliably a...
 
Open Source SQL databases enters millions queries per second era
Open Source SQL databases enters millions queries per second eraOpen Source SQL databases enters millions queries per second era
Open Source SQL databases enters millions queries per second era
 
Kraken mesoscon 2018
Kraken mesoscon 2018Kraken mesoscon 2018
Kraken mesoscon 2018
 
Microservices with Micronaut
Microservices with MicronautMicroservices with Micronaut
Microservices with Micronaut
 
Microservices with Micronaut
Microservices with MicronautMicroservices with Micronaut
Microservices with Micronaut
 
Tempesta FW - Framework и Firewall для WAF и DDoS mitigation, Александр Крижа...
Tempesta FW - Framework и Firewall для WAF и DDoS mitigation, Александр Крижа...Tempesta FW - Framework и Firewall для WAF и DDoS mitigation, Александр Крижа...
Tempesta FW - Framework и Firewall для WAF и DDoS mitigation, Александр Крижа...
 
Scale and Throughput @ Clicktale with Akka
Scale and Throughput @ Clicktale with AkkaScale and Throughput @ Clicktale with Akka
Scale and Throughput @ Clicktale with Akka
 
PyConUK 2018 - Journey from HTTP to gRPC
PyConUK 2018 - Journey from HTTP to gRPCPyConUK 2018 - Journey from HTTP to gRPC
PyConUK 2018 - Journey from HTTP to gRPC
 
Logs @ OVHcloud
Logs @ OVHcloudLogs @ OVHcloud
Logs @ OVHcloud
 
Introduction to performance tuning perl web applications
Introduction to performance tuning perl web applicationsIntroduction to performance tuning perl web applications
Introduction to performance tuning perl web applications
 
Microservices with Micronaut
Microservices with MicronautMicroservices with Micronaut
Microservices with Micronaut
 
Netflix Keystone - How Netflix Handles Data Streams up to 11M Events/Sec
Netflix Keystone - How Netflix Handles Data Streams up to 11M Events/SecNetflix Keystone - How Netflix Handles Data Streams up to 11M Events/Sec
Netflix Keystone - How Netflix Handles Data Streams up to 11M Events/Sec
 
[db tech showcase Tokyo 2017] A11: SQLite - The most used yet least appreciat...
[db tech showcase Tokyo 2017] A11: SQLite - The most used yet least appreciat...[db tech showcase Tokyo 2017] A11: SQLite - The most used yet least appreciat...
[db tech showcase Tokyo 2017] A11: SQLite - The most used yet least appreciat...
 
Haproxy - zastosowania
Haproxy - zastosowaniaHaproxy - zastosowania
Haproxy - zastosowania
 
Eduardo Silva - monkey http-server everywhere
Eduardo Silva - monkey http-server everywhereEduardo Silva - monkey http-server everywhere
Eduardo Silva - monkey http-server everywhere
 
Introduction to apache kafka
Introduction to apache kafkaIntroduction to apache kafka
Introduction to apache kafka
 
Stephan Ewen - Experiences running Flink at Very Large Scale
Stephan Ewen -  Experiences running Flink at Very Large ScaleStephan Ewen -  Experiences running Flink at Very Large Scale
Stephan Ewen - Experiences running Flink at Very Large Scale
 

Dernier

VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
dharasingh5698
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college project
Tonystark477637
 

Dernier (20)

Glass Ceramics: Processing and Properties
Glass Ceramics: Processing and PropertiesGlass Ceramics: Processing and Properties
Glass Ceramics: Processing and Properties
 
UNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICS
UNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICSUNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICS
UNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICS
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSIS
 
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineering
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
 
Vivazz, Mieres Social Housing Design Spain
Vivazz, Mieres Social Housing Design SpainVivazz, Mieres Social Housing Design Spain
Vivazz, Mieres Social Housing Design Spain
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college project
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
 
Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduits
 
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank  Design by Working Stress - IS Method.pdfIntze Overhead Water Tank  Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 

JEEConf. Vanilla java