SlideShare una empresa de Scribd logo
1 de 19
Linux multiplexing
Mark Veltzer
mailto: mark@veltzer.net
What is multiplexing?
● Multiplexing is doing multiple IO operations in
just one thread.
● It is also used in the more general meaning of
waiting for more than one thing to happen.
● In our case it means waiting for more than one
thing to happen at the OS level (usually IO to
complete).
● This could be IO, signal, event from another
thread, timer and more.
Multiplexing and multi-threading
● Some see multiplexing as an alternative to multi
threading.
● If one thread can do IO on many file descriptors and
if IO is slow then one thread may handle all the IO
needs of the application.
● This view has a lot of truth to it and practice has
shown that you can implement a very efficient web
server using a single thread.
● Note that this has nothing to do with content
generation or business logic. They may need threads
because they are CPU consuming.
Multiplexing and multi-threading
(cont)
● Multiplexing can also be used in concert with multi-
threading.
● Either one thread will do multiplexing and will use
a thread pool to do business logic.
● Or you could have more than one multiplexer (with
it's own thread pool, or not...)
● Because of the rising speed of network devices
you may need more than one multiplexer.
● Obviously then you need to divide connections/file
descriptors between your multiplexing threads.
What about signal handling?
● Signal handling could be seen as a sort of multiplexing.
● It enables you to do more than one thing in one thread:
both wait for a signal and do synchronous IO at the
same time.
● But signal handling is asynchronous which causes
problems for many programmers.
● While multiplexing is synchronous (albeit not easy to
implement correctly).
● And signal handling was never scalable to a large
number of concurrent tasks.
What about asynchronous IO?
● Asynchronous IO does allow you to do
something like multiplexing: do IO and not wait
for it to complete.
● But how would you know that the IO has
completed?
● You either get a signal with signal handling
problems.
● Or wait. But that is exactly what multiplexing
does.
The reactor pattern
● The reactor pattern in ACE and other frameworks is a pattern
built on top of the OS specific multiplexing API.
● You write multiple objects with methods to handle various types
of events.
● The framework then uses a single thread to wait for any of these
events using the OS API.
● When the event happens the thread wakes up and calls the
appropriate method on the appropriate object.
● And you get a nice C++ OO API so that you can easily write the
event handlers independent of each other.
File descriptors in UNIX
● File descriptors in UNIX were flexible to begin with.
● They could stand for:
● Regular file / folders
● Device driver
● Network socket
● Listening socket
● Anonymous or named pipes
● UNIX domain socket
● Virtual files, like /proc, which look like regular files
● So multiplexing on many file descriptors is already
powerful.
File descriptors in Linux
● In order to make multiplexing more flexible and
effective the concept of file descriptor was
enhanced in Linux to include things that were
never in the UNIX definition.
● In Linux a file descriptor can also be:
● Timer (timerfd)
● Signal file descriptor for synchronous signal
delivery. (signalfd)
● Event from another thread or process (eventfd)
timerfd
● API: timerfd_create(2), timerfd_settime(2),
timerfd_gettime(2)
● You create (open?!?) a timerfd by calling
timerfd_create.
● You can say what type of clock (hardware, software,
etc) your timer will be based on.
● You get a file descriptor.
● Now you can read(2) it and you block until the timer
expires.
● Or you can multiplex on it.
signalfd
● API: signalfd(2)
● You call signalfd(2) and create (open?!?) a file
descriptor.
● You can specify what signals you want this file
descriptor to catch and various flags.
● You can now read(2) this file descriptor and go
to sleep and wait for any of the prescribed
signals.
● Or you can multiplex on it.
eventfd
● API: eventfd(2), eventfd_read(2), eventfd_write(2)
● Create (open?) an eventfd using eventfd(2)
● Now write or read from it.
● Writes and reads only work in 64 bit chunks.
● You can now read(2) this file descriptor and go to
sleep to wait for this event. You will wake up once
another thread does a write(2) to this file descriptor.
● Or you can multiplex on it.
eventfd (cont)
● More efficient than a pipe (no circular buffer,
messages are constant size).
● Simpler than a pipe (one fd and not two, no
signals involved).
● Kernel uses this to signal user space (async io).
● You can use it for inter-thread or inter-process
communication.
● For instance using fork.
Linux multiplexing API
● Is comprised of three system calls (or system
call groups): select, poll and epoll.
● They all work on file descriptors.
● Since file descriptor in Linux can stand for all
the previously mentioned types multiplexing is
very flexible.
● You pack file descriptors into a group and then
you wait on the group.
Why 3 different APIs?
● Because they evolved through time.
● First was select, then poll and then epoll.
● Differences are: size of group of fds, efficient
handling of large groups of fds, timer support,
signal masking and more.
● Epoll is the most advanced API so we will
concentrate on that.
epoll
● API: epoll(2), epoll_create(2), epoll_create1(2),
epoll_ctl(2), epoll_pwait(2), epoll_wait(2)
● You create (open?) an epoll file descriptor using
epoll_create(2).
● Now you can add/remove file descriptors
to/from it using epoll_ctl.
● When adding a file descriptor you can say what
you are waiting on this file descriptor for (read,
write, error, etc).
epoll (cont)
● Now you can epoll_wait(2) until something
happens.
● When you wake up your array of epll_event
structs is filled with details about what
happened.
● You handle the events and go back to
epoll_wait(2).
epoll (cont)
● In epoll the list of file descriptors is held in
kernel space.
● This is seen as one of epolls main strengths
since passing a large file descriptor collection on
each call to select(2) or poll(2) was problematic.
● This is what makes epoll(2) scale to large
numbers of file descriptors (some report
hundreds of thousands).
● Some see this as the pinnacle of Linux APIs.
Multiplexing - conclusions
● Multiplexing in Linux is very powerful.
● You can do many many things in parallel in a single
thread/process.
● It scales well to large numbers of file descriptors.
● The API is not easy but that is the kernel design.
● The idea is that it will be wrapped by user level libraries,
maybe even OO.
● ACE needs to be compiled in a special way to support
epoll.

Más contenido relacionado

La actualidad más candente

How Functions Work
How Functions WorkHow Functions Work
How Functions WorkSaumil Shah
 
IPv4aaS tutorial and hands-on
IPv4aaS tutorial and hands-onIPv4aaS tutorial and hands-on
IPv4aaS tutorial and hands-onAPNIC
 
Dynamic Instrumentation- OpenEBS Golang Meetup July 2017
Dynamic Instrumentation- OpenEBS Golang Meetup July 2017Dynamic Instrumentation- OpenEBS Golang Meetup July 2017
Dynamic Instrumentation- OpenEBS Golang Meetup July 2017OpenEBS
 
Bypassing ASLR Exploiting CVE 2015-7545
Bypassing ASLR Exploiting CVE 2015-7545Bypassing ASLR Exploiting CVE 2015-7545
Bypassing ASLR Exploiting CVE 2015-7545Kernel TLV
 
Distributed app development with nodejs and zeromq
Distributed app development with nodejs and zeromqDistributed app development with nodejs and zeromq
Distributed app development with nodejs and zeromqRuben Tan
 
Asynchronous programming intro
Asynchronous programming introAsynchronous programming intro
Asynchronous programming introcc liu
 
Course lecture - An introduction to the Return Oriented Programming
Course lecture - An introduction to the Return Oriented ProgrammingCourse lecture - An introduction to the Return Oriented Programming
Course lecture - An introduction to the Return Oriented ProgrammingJonathan Salwan
 
Introduction to netlink in linux kernel (english)
Introduction to netlink in linux kernel (english)Introduction to netlink in linux kernel (english)
Introduction to netlink in linux kernel (english)Sneeker Yeh
 
0.5mln packets per second with Erlang
0.5mln packets per second with Erlang0.5mln packets per second with Erlang
0.5mln packets per second with ErlangMaxim Kharchenko
 
Dive into ROP - a quick introduction to Return Oriented Programming
Dive into ROP - a quick introduction to Return Oriented ProgrammingDive into ROP - a quick introduction to Return Oriented Programming
Dive into ROP - a quick introduction to Return Oriented ProgrammingSaumil Shah
 
Stackless Python In Eve
Stackless Python In EveStackless Python In Eve
Stackless Python In Eveguest91855c
 
Systemtap
SystemtapSystemtap
SystemtapFeng Yu
 
Python twisted
Python twistedPython twisted
Python twistedMahendra M
 
Introduction to Erlang/(Elixir) at a Webilea Hands-On Session
Introduction to Erlang/(Elixir) at a Webilea Hands-On SessionIntroduction to Erlang/(Elixir) at a Webilea Hands-On Session
Introduction to Erlang/(Elixir) at a Webilea Hands-On SessionAndré Graf
 
Startup guide for kvm on cent os 6
Startup guide for kvm on cent os 6Startup guide for kvm on cent os 6
Startup guide for kvm on cent os 6Carlos Eduardo
 
RAFT Consensus Algorithm
RAFT Consensus AlgorithmRAFT Consensus Algorithm
RAFT Consensus Algorithmsangyun han
 

La actualidad más candente (20)

Distributed Elixir
Distributed ElixirDistributed Elixir
Distributed Elixir
 
How Functions Work
How Functions WorkHow Functions Work
How Functions Work
 
IPv4aaS tutorial and hands-on
IPv4aaS tutorial and hands-onIPv4aaS tutorial and hands-on
IPv4aaS tutorial and hands-on
 
Return Oriented Programming (ROP) Based Exploits - Part I
Return Oriented Programming  (ROP) Based Exploits  - Part IReturn Oriented Programming  (ROP) Based Exploits  - Part I
Return Oriented Programming (ROP) Based Exploits - Part I
 
LuaJIT
LuaJITLuaJIT
LuaJIT
 
Dynamic Instrumentation- OpenEBS Golang Meetup July 2017
Dynamic Instrumentation- OpenEBS Golang Meetup July 2017Dynamic Instrumentation- OpenEBS Golang Meetup July 2017
Dynamic Instrumentation- OpenEBS Golang Meetup July 2017
 
Bypassing ASLR Exploiting CVE 2015-7545
Bypassing ASLR Exploiting CVE 2015-7545Bypassing ASLR Exploiting CVE 2015-7545
Bypassing ASLR Exploiting CVE 2015-7545
 
Distributed app development with nodejs and zeromq
Distributed app development with nodejs and zeromqDistributed app development with nodejs and zeromq
Distributed app development with nodejs and zeromq
 
Asynchronous programming intro
Asynchronous programming introAsynchronous programming intro
Asynchronous programming intro
 
Course lecture - An introduction to the Return Oriented Programming
Course lecture - An introduction to the Return Oriented ProgrammingCourse lecture - An introduction to the Return Oriented Programming
Course lecture - An introduction to the Return Oriented Programming
 
Introduction to netlink in linux kernel (english)
Introduction to netlink in linux kernel (english)Introduction to netlink in linux kernel (english)
Introduction to netlink in linux kernel (english)
 
0.5mln packets per second with Erlang
0.5mln packets per second with Erlang0.5mln packets per second with Erlang
0.5mln packets per second with Erlang
 
Dive into ROP - a quick introduction to Return Oriented Programming
Dive into ROP - a quick introduction to Return Oriented ProgrammingDive into ROP - a quick introduction to Return Oriented Programming
Dive into ROP - a quick introduction to Return Oriented Programming
 
Stackless Python In Eve
Stackless Python In EveStackless Python In Eve
Stackless Python In Eve
 
Advance ROP Attacks
Advance ROP AttacksAdvance ROP Attacks
Advance ROP Attacks
 
Systemtap
SystemtapSystemtap
Systemtap
 
Python twisted
Python twistedPython twisted
Python twisted
 
Introduction to Erlang/(Elixir) at a Webilea Hands-On Session
Introduction to Erlang/(Elixir) at a Webilea Hands-On SessionIntroduction to Erlang/(Elixir) at a Webilea Hands-On Session
Introduction to Erlang/(Elixir) at a Webilea Hands-On Session
 
Startup guide for kvm on cent os 6
Startup guide for kvm on cent os 6Startup guide for kvm on cent os 6
Startup guide for kvm on cent os 6
 
RAFT Consensus Algorithm
RAFT Consensus AlgorithmRAFT Consensus Algorithm
RAFT Consensus Algorithm
 

Destacado

Mba ii rm unit-3.3 sampling methods a
Mba ii rm unit-3.3 sampling methods aMba ii rm unit-3.3 sampling methods a
Mba ii rm unit-3.3 sampling methods aRai University
 
Sampling Design and Sampling Distribution
Sampling Design and Sampling DistributionSampling Design and Sampling Distribution
Sampling Design and Sampling DistributionVikas Sonwane
 
Toxic Release And Dispersion Models
Toxic Release And Dispersion ModelsToxic Release And Dispersion Models
Toxic Release And Dispersion Modelsleksonobangun
 
The Physical Layer
The Physical LayerThe Physical Layer
The Physical Layeradil raja
 
Best Practices for Salesforce Data Access
Best Practices for Salesforce Data AccessBest Practices for Salesforce Data Access
Best Practices for Salesforce Data AccessSalesforce Developers
 
Intorduction to cellular communication
Intorduction to cellular communicationIntorduction to cellular communication
Intorduction to cellular communicationZaahir Salam
 
Comparison between ipv4 and ipv6
Comparison between ipv4 and ipv6Comparison between ipv4 and ipv6
Comparison between ipv4 and ipv6Dharmesh Patel
 
GSM, Cell Planning & Frequency Reuse
GSM, Cell Planning & Frequency ReuseGSM, Cell Planning & Frequency Reuse
GSM, Cell Planning & Frequency Reusesanjida2222
 
IPv4 to IPv6
IPv4 to IPv6IPv4 to IPv6
IPv4 to IPv6mithilak
 
Wireless communication and cellular concept
Wireless communication and cellular conceptWireless communication and cellular concept
Wireless communication and cellular conceptsaam123
 

Destacado (15)

08 multiplexing
08 multiplexing08 multiplexing
08 multiplexing
 
Sampling (Research)
Sampling (Research)Sampling (Research)
Sampling (Research)
 
Mba ii rm unit-3.3 sampling methods a
Mba ii rm unit-3.3 sampling methods aMba ii rm unit-3.3 sampling methods a
Mba ii rm unit-3.3 sampling methods a
 
Sampling Design and Sampling Distribution
Sampling Design and Sampling DistributionSampling Design and Sampling Distribution
Sampling Design and Sampling Distribution
 
Toxic Release And Dispersion Models
Toxic Release And Dispersion ModelsToxic Release And Dispersion Models
Toxic Release And Dispersion Models
 
Sample
SampleSample
Sample
 
The Physical Layer
The Physical LayerThe Physical Layer
The Physical Layer
 
Physical Layer
Physical LayerPhysical Layer
Physical Layer
 
Best Practices for Salesforce Data Access
Best Practices for Salesforce Data AccessBest Practices for Salesforce Data Access
Best Practices for Salesforce Data Access
 
Intorduction to cellular communication
Intorduction to cellular communicationIntorduction to cellular communication
Intorduction to cellular communication
 
Comparison between ipv4 and ipv6
Comparison between ipv4 and ipv6Comparison between ipv4 and ipv6
Comparison between ipv4 and ipv6
 
Sdh total final
Sdh total finalSdh total final
Sdh total final
 
GSM, Cell Planning & Frequency Reuse
GSM, Cell Planning & Frequency ReuseGSM, Cell Planning & Frequency Reuse
GSM, Cell Planning & Frequency Reuse
 
IPv4 to IPv6
IPv4 to IPv6IPv4 to IPv6
IPv4 to IPv6
 
Wireless communication and cellular concept
Wireless communication and cellular conceptWireless communication and cellular concept
Wireless communication and cellular concept
 

Similar a Linux multiplexing

An introduction to erlang
An introduction to erlangAn introduction to erlang
An introduction to erlangMirko Bonadei
 
Let's Talk Locks!
Let's Talk Locks!Let's Talk Locks!
Let's Talk Locks!C4Media
 
Building scalable and language independent java services using apache thrift
Building scalable and language independent java services using apache thriftBuilding scalable and language independent java services using apache thrift
Building scalable and language independent java services using apache thriftTalentica Software
 
Linux Server Deep Dives (DrupalCon Amsterdam)
Linux Server Deep Dives (DrupalCon Amsterdam)Linux Server Deep Dives (DrupalCon Amsterdam)
Linux Server Deep Dives (DrupalCon Amsterdam)Amin Astaneh
 
Linux 开源操作系统发展新趋势
Linux 开源操作系统发展新趋势Linux 开源操作系统发展新趋势
Linux 开源操作系统发展新趋势Anthony Wong
 
Building scalable and language-independent Java services using Apache Thrift ...
Building scalable and language-independent Java services using Apache Thrift ...Building scalable and language-independent Java services using Apache Thrift ...
Building scalable and language-independent Java services using Apache Thrift ...IndicThreads
 
M|18 Architectural Overview: MariaDB MaxScale
M|18 Architectural Overview: MariaDB MaxScaleM|18 Architectural Overview: MariaDB MaxScale
M|18 Architectural Overview: MariaDB MaxScaleMariaDB plc
 
Monitoring.pptx
Monitoring.pptxMonitoring.pptx
Monitoring.pptxShadi Akil
 
[CB16] COFI break – Breaking exploits with Processor trace and Practical cont...
[CB16] COFI break – Breaking exploits with Processor trace and Practical cont...[CB16] COFI break – Breaking exploits with Processor trace and Practical cont...
[CB16] COFI break – Breaking exploits with Processor trace and Practical cont...CODE BLUE
 
Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.jsSu Zin Kyaw
 
BUD17-104: Scripting Languages in IoT: Challenges and Approaches
BUD17-104: Scripting Languages in IoT: Challenges and ApproachesBUD17-104: Scripting Languages in IoT: Challenges and Approaches
BUD17-104: Scripting Languages in IoT: Challenges and ApproachesLinaro
 
A Dive Into ELF Binaries
A Dive Into ELF BinariesA Dive Into ELF Binaries
A Dive Into ELF BinariesBhashit Pandya
 
Centralized logging system using mongoDB
Centralized logging system using mongoDBCentralized logging system using mongoDB
Centralized logging system using mongoDBVivek Parihar
 
Analysis Result Manager (ARM)
Analysis Result Manager (ARM)Analysis Result Manager (ARM)
Analysis Result Manager (ARM)magland
 
TFLite NNAPI and GPU Delegates
TFLite NNAPI and GPU DelegatesTFLite NNAPI and GPU Delegates
TFLite NNAPI and GPU DelegatesKoan-Sin Tan
 

Similar a Linux multiplexing (20)

Multicore
MulticoreMulticore
Multicore
 
An introduction to erlang
An introduction to erlangAn introduction to erlang
An introduction to erlang
 
Let's Talk Locks!
Let's Talk Locks!Let's Talk Locks!
Let's Talk Locks!
 
Building scalable and language independent java services using apache thrift
Building scalable and language independent java services using apache thriftBuilding scalable and language independent java services using apache thrift
Building scalable and language independent java services using apache thrift
 
Linux Server Deep Dives (DrupalCon Amsterdam)
Linux Server Deep Dives (DrupalCon Amsterdam)Linux Server Deep Dives (DrupalCon Amsterdam)
Linux Server Deep Dives (DrupalCon Amsterdam)
 
Linux 开源操作系统发展新趋势
Linux 开源操作系统发展新趋势Linux 开源操作系统发展新趋势
Linux 开源操作系统发展新趋势
 
Building scalable and language-independent Java services using Apache Thrift ...
Building scalable and language-independent Java services using Apache Thrift ...Building scalable and language-independent Java services using Apache Thrift ...
Building scalable and language-independent Java services using Apache Thrift ...
 
M|18 Architectural Overview: MariaDB MaxScale
M|18 Architectural Overview: MariaDB MaxScaleM|18 Architectural Overview: MariaDB MaxScale
M|18 Architectural Overview: MariaDB MaxScale
 
Monitoring.pptx
Monitoring.pptxMonitoring.pptx
Monitoring.pptx
 
[CB16] COFI break – Breaking exploits with Processor trace and Practical cont...
[CB16] COFI break – Breaking exploits with Processor trace and Practical cont...[CB16] COFI break – Breaking exploits with Processor trace and Practical cont...
[CB16] COFI break – Breaking exploits with Processor trace and Practical cont...
 
Multithreading by rj
Multithreading by rjMultithreading by rj
Multithreading by rj
 
Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.js
 
Linux-Internals-and-Networking
Linux-Internals-and-NetworkingLinux-Internals-and-Networking
Linux-Internals-and-Networking
 
BUD17-104: Scripting Languages in IoT: Challenges and Approaches
BUD17-104: Scripting Languages in IoT: Challenges and ApproachesBUD17-104: Scripting Languages in IoT: Challenges and Approaches
BUD17-104: Scripting Languages in IoT: Challenges and Approaches
 
Monkey Server
Monkey ServerMonkey Server
Monkey Server
 
A Dive Into ELF Binaries
A Dive Into ELF BinariesA Dive Into ELF Binaries
A Dive Into ELF Binaries
 
Centralized logging system using mongoDB
Centralized logging system using mongoDBCentralized logging system using mongoDB
Centralized logging system using mongoDB
 
Analysis Result Manager (ARM)
Analysis Result Manager (ARM)Analysis Result Manager (ARM)
Analysis Result Manager (ARM)
 
TFLite NNAPI and GPU Delegates
TFLite NNAPI and GPU DelegatesTFLite NNAPI and GPU Delegates
TFLite NNAPI and GPU Delegates
 
Realtime
RealtimeRealtime
Realtime
 

Más de Mark Veltzer (11)

Gcc
GccGcc
Gcc
 
Gcc opt
Gcc optGcc opt
Gcc opt
 
Linux io
Linux ioLinux io
Linux io
 
Linux logging
Linux loggingLinux logging
Linux logging
 
Linux monitoring
Linux monitoringLinux monitoring
Linux monitoring
 
Linux tmpfs
Linux tmpfsLinux tmpfs
Linux tmpfs
 
Multicore
MulticoreMulticore
Multicore
 
Pthreads linux
Pthreads linuxPthreads linux
Pthreads linux
 
Streams
StreamsStreams
Streams
 
Volatile
VolatileVolatile
Volatile
 
Effective cplusplus
Effective cplusplusEffective cplusplus
Effective cplusplus
 

Último

DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 

Último (20)

DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 

Linux multiplexing

  • 2. What is multiplexing? ● Multiplexing is doing multiple IO operations in just one thread. ● It is also used in the more general meaning of waiting for more than one thing to happen. ● In our case it means waiting for more than one thing to happen at the OS level (usually IO to complete). ● This could be IO, signal, event from another thread, timer and more.
  • 3. Multiplexing and multi-threading ● Some see multiplexing as an alternative to multi threading. ● If one thread can do IO on many file descriptors and if IO is slow then one thread may handle all the IO needs of the application. ● This view has a lot of truth to it and practice has shown that you can implement a very efficient web server using a single thread. ● Note that this has nothing to do with content generation or business logic. They may need threads because they are CPU consuming.
  • 4. Multiplexing and multi-threading (cont) ● Multiplexing can also be used in concert with multi- threading. ● Either one thread will do multiplexing and will use a thread pool to do business logic. ● Or you could have more than one multiplexer (with it's own thread pool, or not...) ● Because of the rising speed of network devices you may need more than one multiplexer. ● Obviously then you need to divide connections/file descriptors between your multiplexing threads.
  • 5. What about signal handling? ● Signal handling could be seen as a sort of multiplexing. ● It enables you to do more than one thing in one thread: both wait for a signal and do synchronous IO at the same time. ● But signal handling is asynchronous which causes problems for many programmers. ● While multiplexing is synchronous (albeit not easy to implement correctly). ● And signal handling was never scalable to a large number of concurrent tasks.
  • 6. What about asynchronous IO? ● Asynchronous IO does allow you to do something like multiplexing: do IO and not wait for it to complete. ● But how would you know that the IO has completed? ● You either get a signal with signal handling problems. ● Or wait. But that is exactly what multiplexing does.
  • 7. The reactor pattern ● The reactor pattern in ACE and other frameworks is a pattern built on top of the OS specific multiplexing API. ● You write multiple objects with methods to handle various types of events. ● The framework then uses a single thread to wait for any of these events using the OS API. ● When the event happens the thread wakes up and calls the appropriate method on the appropriate object. ● And you get a nice C++ OO API so that you can easily write the event handlers independent of each other.
  • 8. File descriptors in UNIX ● File descriptors in UNIX were flexible to begin with. ● They could stand for: ● Regular file / folders ● Device driver ● Network socket ● Listening socket ● Anonymous or named pipes ● UNIX domain socket ● Virtual files, like /proc, which look like regular files ● So multiplexing on many file descriptors is already powerful.
  • 9. File descriptors in Linux ● In order to make multiplexing more flexible and effective the concept of file descriptor was enhanced in Linux to include things that were never in the UNIX definition. ● In Linux a file descriptor can also be: ● Timer (timerfd) ● Signal file descriptor for synchronous signal delivery. (signalfd) ● Event from another thread or process (eventfd)
  • 10. timerfd ● API: timerfd_create(2), timerfd_settime(2), timerfd_gettime(2) ● You create (open?!?) a timerfd by calling timerfd_create. ● You can say what type of clock (hardware, software, etc) your timer will be based on. ● You get a file descriptor. ● Now you can read(2) it and you block until the timer expires. ● Or you can multiplex on it.
  • 11. signalfd ● API: signalfd(2) ● You call signalfd(2) and create (open?!?) a file descriptor. ● You can specify what signals you want this file descriptor to catch and various flags. ● You can now read(2) this file descriptor and go to sleep and wait for any of the prescribed signals. ● Or you can multiplex on it.
  • 12. eventfd ● API: eventfd(2), eventfd_read(2), eventfd_write(2) ● Create (open?) an eventfd using eventfd(2) ● Now write or read from it. ● Writes and reads only work in 64 bit chunks. ● You can now read(2) this file descriptor and go to sleep to wait for this event. You will wake up once another thread does a write(2) to this file descriptor. ● Or you can multiplex on it.
  • 13. eventfd (cont) ● More efficient than a pipe (no circular buffer, messages are constant size). ● Simpler than a pipe (one fd and not two, no signals involved). ● Kernel uses this to signal user space (async io). ● You can use it for inter-thread or inter-process communication. ● For instance using fork.
  • 14. Linux multiplexing API ● Is comprised of three system calls (or system call groups): select, poll and epoll. ● They all work on file descriptors. ● Since file descriptor in Linux can stand for all the previously mentioned types multiplexing is very flexible. ● You pack file descriptors into a group and then you wait on the group.
  • 15. Why 3 different APIs? ● Because they evolved through time. ● First was select, then poll and then epoll. ● Differences are: size of group of fds, efficient handling of large groups of fds, timer support, signal masking and more. ● Epoll is the most advanced API so we will concentrate on that.
  • 16. epoll ● API: epoll(2), epoll_create(2), epoll_create1(2), epoll_ctl(2), epoll_pwait(2), epoll_wait(2) ● You create (open?) an epoll file descriptor using epoll_create(2). ● Now you can add/remove file descriptors to/from it using epoll_ctl. ● When adding a file descriptor you can say what you are waiting on this file descriptor for (read, write, error, etc).
  • 17. epoll (cont) ● Now you can epoll_wait(2) until something happens. ● When you wake up your array of epll_event structs is filled with details about what happened. ● You handle the events and go back to epoll_wait(2).
  • 18. epoll (cont) ● In epoll the list of file descriptors is held in kernel space. ● This is seen as one of epolls main strengths since passing a large file descriptor collection on each call to select(2) or poll(2) was problematic. ● This is what makes epoll(2) scale to large numbers of file descriptors (some report hundreds of thousands). ● Some see this as the pinnacle of Linux APIs.
  • 19. Multiplexing - conclusions ● Multiplexing in Linux is very powerful. ● You can do many many things in parallel in a single thread/process. ● It scales well to large numbers of file descriptors. ● The API is not easy but that is the kernel design. ● The idea is that it will be wrapped by user level libraries, maybe even OO. ● ACE needs to be compiled in a special way to support epoll.