SlideShare a Scribd company logo
1 of 27
C10K and beyond
Uri Shamay
$>whoami
● BIO :: http://cmpxchg16.me
● Twitter :: https://twitter.com/cmpxchg16
● Github :: https://github.com/cmpxchg16
● Email :: shamayuri@gmail.com
$>Java.IL community co-founder
http://www.meetup.com/JavaIL/
C10K and beyond, how much
beyond…….
WhatsApp 2011:
$>netstat -an | grep -c EST
$>1016313
WhatsApp 2012:
$>sysctl kern.ipc.numopensockets
$>kern.ipc.numopensockets: 2277845
What I will not cover
● Specific OS implementation
● OS system configuration
● Networking hard-core
● Hardware
What I will cover
● The history of C10K problem
● concurrency models abstract
o Processes/Threads
o Event-driven/Actors
o lightweight threads :: Coroutines/Fibers
● Java related solution
C10K problem - Processes
The old beast - @process per connection
C10K problem - Processes
Pseudo:
fork () -> {
try {
io_func_1 ()
io_func_2 ()
io_func_3 ()
} catch (timeout) {
io_handle_timeout ()
return
} catch (error) {
io_handle_error ()
return
}
handle_success ()
}
C10K problem - Processes
Usage:
● CGI with scripts and ENV passing
● Apache HTTP Server old model
● PostgreSQL model - even today!
But processes cannot scale as connections...
C10K problem - Threads
@native OS thread per connection
C10K problem - Threads
Pseudo:
thread () -> {
try {
io_func_1 ()
io_func_2 ()
io_func_3 ()
} catch (timeout) {
io_handle_timeout ()
return
} catch (error) {
io_handle_error ()
return
}
handle_success ()
}
C10K problem - Threads
Usage:
● The old model of Apache
● Any servlet container like :: Tomcat / Jetty / Resin /
Jboss / Glassfish
● Any HttpClient
But threads cannot scale as connections...
C10K problem - Event-driven
@one native OS thread rule them all!
C10K problem - Event-driven
“Hi Mate, we heard you like callbacks, so we
put callbacks in your callback so you can
callback when you callback.”
Pseudo:
main_loop () -> {
async -> (io_func_1 (state)) -> {
onSuccess (state) {
async -> (io_func_2 (state)) -> {
onSuccess (state) {
async -> (io_func_3 (state)) -> {
onSuccess (state) {
handle_success (state)
}
onError (state) { io_handle_error () }
onTimeout (state) { io_handle_timeout () }
}
}
onError (state) { io_handle_error () }
onTimeout (state) { io_handle_timeout () }
}
}
onError (state) { io_handle_error () }
onTimeout (state) { io_handle_timeout () }
}
}
C10K problem - Event-driven
The CALLBACK HELL!
io_handle_error (state) {
async -> (...) -> {
onSuccess (state) {}
onError (state) {}
onTimeout (state) {}
}
}
io_handle_timeout (state) {
async -> (...) -> {
onSuccess (state) {}
onError (state) {}
onTimeout (state) {}
}
}
C10K problem - Event-driven
support multi-core system - open
NUM_OF_PROCESSORS evented native thread’s
Usage:
● servers: Nginx/Httpd/Squid
● Node.js
● Java world frameworks for client/server that scale
:: Netty / Grizzly / Mina
C10K problem - Event-driven with
promises
Promises is just a syntactic sugar for event-driven.
● Node.js
● Java 8: CompletableFuture
main_loop () -> {
async -> (io_func_1 (state))
-> then (io_func_2 (state))
-> then (io_func_3 (state))
-> success (handle_success())
-> error (io_handle_error ())
-> timeout (io_handle_timeout ())
}
But what if our I/O is endless like WebSocket?!
C10K problem - Actor
Don't communicate by sharing memory, share
memory by communicating
C10K problem - Actor
@one Actor per connection
C10K problem - Actor
● There are a lot of frameworks out there
● Java :: Akka (concrete implementation for Actor
model in Scala)
But Actor model is asynchronous by design and our flow
is synchronous…
C10K problem - Coroutines/Fibers
Let’s face it - I/O is asynchronous, our state is
synchronous, so let’s be cooperative by hybrid mode
C10K problem - Coroutines example
Pseudo:
coroutine_1 () -> {
i := -1
while (true) {
i++
if i % 2 == 0 {
println “even is the dominant ($i)!”
if i < 10 {
yield ()
}
}
}
}
coroutine_2 () -> {
i := 0
while (true) {
i++
if i % 2 == 1 {
println “odd is the dominant ($i)!”
yield ()
}
}
}
// only one native thread
main {
coroutine_1.start ()
coroutine_2.start ()
}
Output:
even is the dominant (0)!
odd is the dominant (1)!
even is the dominant (2)!
odd is the dominant (3)!
even is the dominant (4)!
odd is the dominant (5)!
even is the dominant (6)!
odd is the dominant (7)!
even is the dominant (8)!
odd is the dominant (9)!
even is the dominant (10)!
even is the dominant (12)!
even is the dominant (14)!
even is the dominant (16)!
even is the dominant (18)!
even is the dominant (20)!
.
.
.
C10K problem - Coroutines/Fibers
@one coroutine/fiber per connection
C10K problem - Coroutines/Fibers
Pseudo:
fiber () -> {
try {
io_func_1 () // implicit yield() when blocking
io_func_2 () // implicit yield() when blocking
io_func_3 () // implicit yield() when blocking
} catch (timeout) {
io_handle_timeout () // implicit yield() when blocking
return
} catch (error) {
io_handle_error () // implicit yield() when blocking
return
}
handle_success() // implicit yield() when blocking
}
C10K problem - Coroutines/Fibers
● New programming languages includes that model:
GO (golang) / D (dlang) / Rust (via library)
● Java
o Kilim (Actor semantics)
 compile time bytecode weaving
o Quasar (Fibers as a lightweight threads)
 runtime bytecode weaving with javaagent
C10K problem - Coroutines/Fibers
Caveats
● As any transparent concurrency model, also that
model suffers from blocking calls - be careful when
using third libraries
● OS Scheduling is very optimized to CPU & I/O
o If we have a CPU intensive task our I/O
corporative model is “unfair” (e.g SSL/TLS,
compression/decompression)
C10K and beyond
Uri Shamay
Questions?

More Related Content

What's hot

What's hot (20)

Kubernetes Networking 101
Kubernetes Networking 101Kubernetes Networking 101
Kubernetes Networking 101
 
Docker and kubernetes
Docker and kubernetesDocker and kubernetes
Docker and kubernetes
 
GCP CloudRun Overview
GCP CloudRun OverviewGCP CloudRun Overview
GCP CloudRun Overview
 
Cql – cassandra query language
Cql – cassandra query languageCql – cassandra query language
Cql – cassandra query language
 
Quic을 이용한 네트워크 성능 개선
 Quic을 이용한 네트워크 성능 개선 Quic을 이용한 네트워크 성능 개선
Quic을 이용한 네트워크 성능 개선
 
gRPC Overview
gRPC OverviewgRPC Overview
gRPC Overview
 
Confluent Workshop Series: ksqlDB로 스트리밍 앱 빌드
Confluent Workshop Series: ksqlDB로 스트리밍 앱 빌드Confluent Workshop Series: ksqlDB로 스트리밍 앱 빌드
Confluent Workshop Series: ksqlDB로 스트리밍 앱 빌드
 
Non blocking io with netty
Non blocking io with nettyNon blocking io with netty
Non blocking io with netty
 
Docker Kubernetes Istio
Docker Kubernetes IstioDocker Kubernetes Istio
Docker Kubernetes Istio
 
Deep dive into Kubernetes Networking
Deep dive into Kubernetes NetworkingDeep dive into Kubernetes Networking
Deep dive into Kubernetes Networking
 
Getting Started with Kubernetes
Getting Started with Kubernetes Getting Started with Kubernetes
Getting Started with Kubernetes
 
Intégration de SonarQube dans GitLab ci
Intégration de SonarQube dans GitLab ciIntégration de SonarQube dans GitLab ci
Intégration de SonarQube dans GitLab ci
 
우아한 모노리스
우아한 모노리스우아한 모노리스
우아한 모노리스
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
Next.js with drupal, the good parts
Next.js with drupal, the good partsNext.js with drupal, the good parts
Next.js with drupal, the good parts
 
Kubernetes 101
Kubernetes 101Kubernetes 101
Kubernetes 101
 
REST-API introduction for developers
REST-API introduction for developersREST-API introduction for developers
REST-API introduction for developers
 
ksqlDB - Stream Processing simplified!
ksqlDB - Stream Processing simplified!ksqlDB - Stream Processing simplified!
ksqlDB - Stream Processing simplified!
 
Building a fully managed stream processing platform on Flink at scale for Lin...
Building a fully managed stream processing platform on Flink at scale for Lin...Building a fully managed stream processing platform on Flink at scale for Lin...
Building a fully managed stream processing platform on Flink at scale for Lin...
 
Jenkins tutorial
Jenkins tutorialJenkins tutorial
Jenkins tutorial
 

Viewers also liked

WITHOUT PR 150209 PPP Peja - Motor division - Omec presentation
WITHOUT PR 150209 PPP Peja - Motor division - Omec presentationWITHOUT PR 150209 PPP Peja - Motor division - Omec presentation
WITHOUT PR 150209 PPP Peja - Motor division - Omec presentation
Samira Qadiri Trias
 
New pdf portfolio
New pdf portfolioNew pdf portfolio
New pdf portfolio
aqeeln
 
Дворец из мороженого
Дворец из мороженогоДворец из мороженого
Дворец из мороженого
gexarvest
 
UCR New Grid Project
UCR New Grid ProjectUCR New Grid Project
UCR New Grid Project
Jonathan Wong
 
2014_09_21_ABOUT-SKY-SERVICES_V3
2014_09_21_ABOUT-SKY-SERVICES_V32014_09_21_ABOUT-SKY-SERVICES_V3
2014_09_21_ABOUT-SKY-SERVICES_V3
Vladimer Svanadze
 

Viewers also liked (18)

Electrolube, Selector de productos electrolube. Antala Industria.
Electrolube, Selector de productos electrolube. Antala Industria.Electrolube, Selector de productos electrolube. Antala Industria.
Electrolube, Selector de productos electrolube. Antala Industria.
 
WITHOUT PR 150209 PPP Peja - Motor division - Omec presentation
WITHOUT PR 150209 PPP Peja - Motor division - Omec presentationWITHOUT PR 150209 PPP Peja - Motor division - Omec presentation
WITHOUT PR 150209 PPP Peja - Motor division - Omec presentation
 
Mоя семья
Mоя семьяMоя семья
Mоя семья
 
ApplicationSupport
ApplicationSupportApplicationSupport
ApplicationSupport
 
Unique buildings
Unique buildingsUnique buildings
Unique buildings
 
Cpd ppt PAYAL PARMAR
Cpd ppt PAYAL PARMARCpd ppt PAYAL PARMAR
Cpd ppt PAYAL PARMAR
 
New pdf portfolio
New pdf portfolioNew pdf portfolio
New pdf portfolio
 
Polis Hammam
Polis HammamPolis Hammam
Polis Hammam
 
Дворец из мороженого
Дворец из мороженогоДворец из мороженого
Дворец из мороженого
 
UCR New Grid Project
UCR New Grid ProjectUCR New Grid Project
UCR New Grid Project
 
Skillda Careers - Kick-start your career!
Skillda Careers - Kick-start your career!Skillda Careers - Kick-start your career!
Skillda Careers - Kick-start your career!
 
2014_09_21_ABOUT-SKY-SERVICES_V3
2014_09_21_ABOUT-SKY-SERVICES_V32014_09_21_ABOUT-SKY-SERVICES_V3
2014_09_21_ABOUT-SKY-SERVICES_V3
 
Talk at Six
Talk at SixTalk at Six
Talk at Six
 
Priyanka sharma
Priyanka sharmaPriyanka sharma
Priyanka sharma
 
A Banyan Residence Assisted Living Resort Venice florida
A Banyan Residence Assisted Living Resort Venice floridaA Banyan Residence Assisted Living Resort Venice florida
A Banyan Residence Assisted Living Resort Venice florida
 
Kalpesh
KalpeshKalpesh
Kalpesh
 
Cucina cinese
Cucina cineseCucina cinese
Cucina cinese
 
AFH Minideck: Villa Rosa Planning, Port-au-Prince, Haiti
AFH Minideck: Villa Rosa Planning, Port-au-Prince, HaitiAFH Minideck: Villa Rosa Planning, Port-au-Prince, Haiti
AFH Minideck: Villa Rosa Planning, Port-au-Prince, Haiti
 

Similar to C10k and beyond - Uri Shamay, Akamai

Csw2016 gawlik bypassing_differentdefenseschemes
Csw2016 gawlik bypassing_differentdefenseschemesCsw2016 gawlik bypassing_differentdefenseschemes
Csw2016 gawlik bypassing_differentdefenseschemes
CanSecWest
 
Tornado Web Server Internals
Tornado Web Server InternalsTornado Web Server Internals
Tornado Web Server Internals
Praveen Gollakota
 
JavaOne 2012 - JVM JIT for Dummies
JavaOne 2012 - JVM JIT for DummiesJavaOne 2012 - JVM JIT for Dummies
JavaOne 2012 - JVM JIT for Dummies
Charles Nutter
 
Codestrong 2012 breakout session hacking titanium
Codestrong 2012 breakout session   hacking titaniumCodestrong 2012 breakout session   hacking titanium
Codestrong 2012 breakout session hacking titanium
Axway Appcelerator
 

Similar to C10k and beyond - Uri Shamay, Akamai (20)

Actor Concurrency
Actor ConcurrencyActor Concurrency
Actor Concurrency
 
Online test program generator for RISC-V processors
Online test program generator for RISC-V processorsOnline test program generator for RISC-V processors
Online test program generator for RISC-V processors
 
Kotlin: forse è la volta buona (Trento)
Kotlin: forse è la volta buona (Trento)Kotlin: forse è la volta buona (Trento)
Kotlin: forse è la volta buona (Trento)
 
Kotlin Coroutines and Rx
Kotlin Coroutines and RxKotlin Coroutines and Rx
Kotlin Coroutines and Rx
 
apidays LIVE Australia 2020 - Strangling the monolith with a reactive GraphQL...
apidays LIVE Australia 2020 - Strangling the monolith with a reactive GraphQL...apidays LIVE Australia 2020 - Strangling the monolith with a reactive GraphQL...
apidays LIVE Australia 2020 - Strangling the monolith with a reactive GraphQL...
 
Non Blocking I/O for Everyone with RxJava
Non Blocking I/O for Everyone with RxJavaNon Blocking I/O for Everyone with RxJava
Non Blocking I/O for Everyone with RxJava
 
Доклад Антона Поварова "Go in Badoo" с Golang Meetup
Доклад Антона Поварова "Go in Badoo" с Golang MeetupДоклад Антона Поварова "Go in Badoo" с Golang Meetup
Доклад Антона Поварова "Go in Badoo" с Golang Meetup
 
Scala to assembly
Scala to assemblyScala to assembly
Scala to assembly
 
What Lies Beneath
What Lies BeneathWhat Lies Beneath
What Lies Beneath
 
Csw2016 gawlik bypassing_differentdefenseschemes
Csw2016 gawlik bypassing_differentdefenseschemesCsw2016 gawlik bypassing_differentdefenseschemes
Csw2016 gawlik bypassing_differentdefenseschemes
 
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
 
Tornado Web Server Internals
Tornado Web Server InternalsTornado Web Server Internals
Tornado Web Server Internals
 
Performance tests - it's a trap
Performance tests - it's a trapPerformance tests - it's a trap
Performance tests - it's a trap
 
Coroutines in Kotlin. In-depth review
Coroutines in Kotlin. In-depth reviewCoroutines in Kotlin. In-depth review
Coroutines in Kotlin. In-depth review
 
Coroutines in Kotlin. UA Mobile 2017.
Coroutines in Kotlin. UA Mobile 2017.Coroutines in Kotlin. UA Mobile 2017.
Coroutines in Kotlin. UA Mobile 2017.
 
Kotlin coroutine - the next step for RxJava developer?
Kotlin coroutine - the next step for RxJava developer?Kotlin coroutine - the next step for RxJava developer?
Kotlin coroutine - the next step for RxJava developer?
 
Eco-Friendly Hardware Hacking with Android
Eco-Friendly Hardware Hacking with AndroidEco-Friendly Hardware Hacking with Android
Eco-Friendly Hardware Hacking with Android
 
JavaOne 2012 - JVM JIT for Dummies
JavaOne 2012 - JVM JIT for DummiesJavaOne 2012 - JVM JIT for Dummies
JavaOne 2012 - JVM JIT for Dummies
 
Idioms in swift 2016 05c
Idioms in swift 2016 05cIdioms in swift 2016 05c
Idioms in swift 2016 05c
 
Codestrong 2012 breakout session hacking titanium
Codestrong 2012 breakout session   hacking titaniumCodestrong 2012 breakout session   hacking titanium
Codestrong 2012 breakout session hacking titanium
 

More from Codemotion Tel Aviv

More from Codemotion Tel Aviv (20)

Keynote: Trends in Modern Application Development - Gilly Dekel, IBM
Keynote: Trends in Modern Application Development - Gilly Dekel, IBMKeynote: Trends in Modern Application Development - Gilly Dekel, IBM
Keynote: Trends in Modern Application Development - Gilly Dekel, IBM
 
Angular is one fire(base)! - Shmuela Jacobs
Angular is one fire(base)! - Shmuela JacobsAngular is one fire(base)! - Shmuela Jacobs
Angular is one fire(base)! - Shmuela Jacobs
 
Demystifying docker networking black magic - Lorenzo Fontana, Kiratech
Demystifying docker networking black magic - Lorenzo Fontana, KiratechDemystifying docker networking black magic - Lorenzo Fontana, Kiratech
Demystifying docker networking black magic - Lorenzo Fontana, Kiratech
 
Faster deep learning solutions from training to inference - Amitai Armon & Ni...
Faster deep learning solutions from training to inference - Amitai Armon & Ni...Faster deep learning solutions from training to inference - Amitai Armon & Ni...
Faster deep learning solutions from training to inference - Amitai Armon & Ni...
 
Facts about multithreading that'll keep you up at night - Guy Bar on, Vonage
Facts about multithreading that'll keep you up at night - Guy Bar on, VonageFacts about multithreading that'll keep you up at night - Guy Bar on, Vonage
Facts about multithreading that'll keep you up at night - Guy Bar on, Vonage
 
Master the Art of the AST (and Take Control of Your JS!) - Yonatan Mevorach, ...
Master the Art of the AST (and Take Control of Your JS!) - Yonatan Mevorach, ...Master the Art of the AST (and Take Control of Your JS!) - Yonatan Mevorach, ...
Master the Art of the AST (and Take Control of Your JS!) - Yonatan Mevorach, ...
 
Unleash the power of angular Reactive Forms - Nir Kaufman, 500Tech
Unleash the power of angular Reactive Forms - Nir Kaufman, 500TechUnleash the power of angular Reactive Forms - Nir Kaufman, 500Tech
Unleash the power of angular Reactive Forms - Nir Kaufman, 500Tech
 
Can we build an Azure IoT controlled device in less than 40 minutes that cost...
Can we build an Azure IoT controlled device in less than 40 minutes that cost...Can we build an Azure IoT controlled device in less than 40 minutes that cost...
Can we build an Azure IoT controlled device in less than 40 minutes that cost...
 
Actors and Microservices - Can two walk together? - Rotem Hermon, Gigya
Actors and Microservices - Can two walk together? - Rotem Hermon, GigyaActors and Microservices - Can two walk together? - Rotem Hermon, Gigya
Actors and Microservices - Can two walk together? - Rotem Hermon, Gigya
 
How to Leverage Machine Learning (R, Hadoop, Spark, H2O) for Real Time Proces...
How to Leverage Machine Learning (R, Hadoop, Spark, H2O) for Real Time Proces...How to Leverage Machine Learning (R, Hadoop, Spark, H2O) for Real Time Proces...
How to Leverage Machine Learning (R, Hadoop, Spark, H2O) for Real Time Proces...
 
My Minecraft Smart Home: Prototyping the internet of uncanny things - Sascha ...
My Minecraft Smart Home: Prototyping the internet of uncanny things - Sascha ...My Minecraft Smart Home: Prototyping the internet of uncanny things - Sascha ...
My Minecraft Smart Home: Prototyping the internet of uncanny things - Sascha ...
 
Distributed Systems explained (with NodeJS) - Bruno Bossola, JUG Torino
Distributed Systems explained (with NodeJS) - Bruno Bossola, JUG TorinoDistributed Systems explained (with NodeJS) - Bruno Bossola, JUG Torino
Distributed Systems explained (with NodeJS) - Bruno Bossola, JUG Torino
 
Containerised ASP.NET Core apps with Kubernetes
Containerised ASP.NET Core apps with KubernetesContainerised ASP.NET Core apps with Kubernetes
Containerised ASP.NET Core apps with Kubernetes
 
Fullstack DDD with ASP.NET Core and Anguar 2 - Ronald Harmsen, NForza
Fullstack DDD with ASP.NET Core and Anguar 2 - Ronald Harmsen, NForzaFullstack DDD with ASP.NET Core and Anguar 2 - Ronald Harmsen, NForza
Fullstack DDD with ASP.NET Core and Anguar 2 - Ronald Harmsen, NForza
 
The Art of Decomposing Monoliths - Kfir Bloch, Wix
The Art of Decomposing Monoliths - Kfir Bloch, WixThe Art of Decomposing Monoliths - Kfir Bloch, Wix
The Art of Decomposing Monoliths - Kfir Bloch, Wix
 
SOA Lessons Learnt (or Microservices done Better) - Sean Farmar, Particular S...
SOA Lessons Learnt (or Microservices done Better) - Sean Farmar, Particular S...SOA Lessons Learnt (or Microservices done Better) - Sean Farmar, Particular S...
SOA Lessons Learnt (or Microservices done Better) - Sean Farmar, Particular S...
 
S3, Cassandra or Outer Space? Dumping Time Series Data using Spark - Demi Ben...
S3, Cassandra or Outer Space? Dumping Time Series Data using Spark - Demi Ben...S3, Cassandra or Outer Space? Dumping Time Series Data using Spark - Demi Ben...
S3, Cassandra or Outer Space? Dumping Time Series Data using Spark - Demi Ben...
 
Getting Physical with Web Bluetooth - Uri Shaked, BlackBerry
Getting Physical with Web Bluetooth - Uri Shaked, BlackBerryGetting Physical with Web Bluetooth - Uri Shaked, BlackBerry
Getting Physical with Web Bluetooth - Uri Shaked, BlackBerry
 
Web based virtual reality - Tanay Pant, Mozilla
Web based virtual reality - Tanay Pant, MozillaWeb based virtual reality - Tanay Pant, Mozilla
Web based virtual reality - Tanay Pant, Mozilla
 
Material Design Demytified - Ran Nachmany, Google
Material Design Demytified - Ran Nachmany, GoogleMaterial Design Demytified - Ran Nachmany, Google
Material Design Demytified - Ran Nachmany, Google
 

Recently uploaded

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Recently uploaded (20)

The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 

C10k and beyond - Uri Shamay, Akamai

  • 2. $>whoami ● BIO :: http://cmpxchg16.me ● Twitter :: https://twitter.com/cmpxchg16 ● Github :: https://github.com/cmpxchg16 ● Email :: shamayuri@gmail.com
  • 4. C10K and beyond, how much beyond……. WhatsApp 2011: $>netstat -an | grep -c EST $>1016313 WhatsApp 2012: $>sysctl kern.ipc.numopensockets $>kern.ipc.numopensockets: 2277845
  • 5. What I will not cover ● Specific OS implementation ● OS system configuration ● Networking hard-core ● Hardware
  • 6. What I will cover ● The history of C10K problem ● concurrency models abstract o Processes/Threads o Event-driven/Actors o lightweight threads :: Coroutines/Fibers ● Java related solution
  • 7. C10K problem - Processes The old beast - @process per connection
  • 8. C10K problem - Processes Pseudo: fork () -> { try { io_func_1 () io_func_2 () io_func_3 () } catch (timeout) { io_handle_timeout () return } catch (error) { io_handle_error () return } handle_success () }
  • 9. C10K problem - Processes Usage: ● CGI with scripts and ENV passing ● Apache HTTP Server old model ● PostgreSQL model - even today! But processes cannot scale as connections...
  • 10. C10K problem - Threads @native OS thread per connection
  • 11. C10K problem - Threads Pseudo: thread () -> { try { io_func_1 () io_func_2 () io_func_3 () } catch (timeout) { io_handle_timeout () return } catch (error) { io_handle_error () return } handle_success () }
  • 12. C10K problem - Threads Usage: ● The old model of Apache ● Any servlet container like :: Tomcat / Jetty / Resin / Jboss / Glassfish ● Any HttpClient But threads cannot scale as connections...
  • 13. C10K problem - Event-driven @one native OS thread rule them all!
  • 14. C10K problem - Event-driven “Hi Mate, we heard you like callbacks, so we put callbacks in your callback so you can callback when you callback.”
  • 15. Pseudo: main_loop () -> { async -> (io_func_1 (state)) -> { onSuccess (state) { async -> (io_func_2 (state)) -> { onSuccess (state) { async -> (io_func_3 (state)) -> { onSuccess (state) { handle_success (state) } onError (state) { io_handle_error () } onTimeout (state) { io_handle_timeout () } } } onError (state) { io_handle_error () } onTimeout (state) { io_handle_timeout () } } } onError (state) { io_handle_error () } onTimeout (state) { io_handle_timeout () } } } C10K problem - Event-driven The CALLBACK HELL! io_handle_error (state) { async -> (...) -> { onSuccess (state) {} onError (state) {} onTimeout (state) {} } } io_handle_timeout (state) { async -> (...) -> { onSuccess (state) {} onError (state) {} onTimeout (state) {} } }
  • 16. C10K problem - Event-driven support multi-core system - open NUM_OF_PROCESSORS evented native thread’s Usage: ● servers: Nginx/Httpd/Squid ● Node.js ● Java world frameworks for client/server that scale :: Netty / Grizzly / Mina
  • 17. C10K problem - Event-driven with promises Promises is just a syntactic sugar for event-driven. ● Node.js ● Java 8: CompletableFuture main_loop () -> { async -> (io_func_1 (state)) -> then (io_func_2 (state)) -> then (io_func_3 (state)) -> success (handle_success()) -> error (io_handle_error ()) -> timeout (io_handle_timeout ()) } But what if our I/O is endless like WebSocket?!
  • 18. C10K problem - Actor Don't communicate by sharing memory, share memory by communicating
  • 19. C10K problem - Actor @one Actor per connection
  • 20. C10K problem - Actor ● There are a lot of frameworks out there ● Java :: Akka (concrete implementation for Actor model in Scala) But Actor model is asynchronous by design and our flow is synchronous…
  • 21. C10K problem - Coroutines/Fibers Let’s face it - I/O is asynchronous, our state is synchronous, so let’s be cooperative by hybrid mode
  • 22. C10K problem - Coroutines example Pseudo: coroutine_1 () -> { i := -1 while (true) { i++ if i % 2 == 0 { println “even is the dominant ($i)!” if i < 10 { yield () } } } } coroutine_2 () -> { i := 0 while (true) { i++ if i % 2 == 1 { println “odd is the dominant ($i)!” yield () } } } // only one native thread main { coroutine_1.start () coroutine_2.start () } Output: even is the dominant (0)! odd is the dominant (1)! even is the dominant (2)! odd is the dominant (3)! even is the dominant (4)! odd is the dominant (5)! even is the dominant (6)! odd is the dominant (7)! even is the dominant (8)! odd is the dominant (9)! even is the dominant (10)! even is the dominant (12)! even is the dominant (14)! even is the dominant (16)! even is the dominant (18)! even is the dominant (20)! . . .
  • 23. C10K problem - Coroutines/Fibers @one coroutine/fiber per connection
  • 24. C10K problem - Coroutines/Fibers Pseudo: fiber () -> { try { io_func_1 () // implicit yield() when blocking io_func_2 () // implicit yield() when blocking io_func_3 () // implicit yield() when blocking } catch (timeout) { io_handle_timeout () // implicit yield() when blocking return } catch (error) { io_handle_error () // implicit yield() when blocking return } handle_success() // implicit yield() when blocking }
  • 25. C10K problem - Coroutines/Fibers ● New programming languages includes that model: GO (golang) / D (dlang) / Rust (via library) ● Java o Kilim (Actor semantics)  compile time bytecode weaving o Quasar (Fibers as a lightweight threads)  runtime bytecode weaving with javaagent
  • 26. C10K problem - Coroutines/Fibers Caveats ● As any transparent concurrency model, also that model suffers from blocking calls - be careful when using third libraries ● OS Scheduling is very optimized to CPU & I/O o If we have a CPU intensive task our I/O corporative model is “unfair” (e.g SSL/TLS, compression/decompression)
  • 27. C10K and beyond Uri Shamay Questions?