SlideShare a Scribd company logo
1 of 19
Download to read offline
ZeroMQ
Anatomy & JeroMQ
ZeroMQ
MQ 가 아니무니다..
TCP on Steroids
ZMQ Socket
ROUTER DEALER XPUB XSUB PUSH
PULLREP REQ PUB SUB
ZeroMQ Anatomy
R w
io_thread_t
ZMQ Socket
Mailbox
Signaler
ypipe_t
<cmd_t>
Session
Socket
Session
Socket
poller
r
fd
fd
ypipe_t <msg_t> inpipe
ypipe_t <msg_t> outpipe
ZMQ
Socket
ZMQ
Socket
ZMQ
Socket
ZMQ
Socket
SessionSessionSession
Context
Mailbox
r
Msg
union {
...
struct {
unsigned char data [29];
unsigned char size;
unsigned char type;
unsigned char flags;
} vsm;
struct {
content_t *content;
unsigned char unused
[29 + 1 - sizeof (content_t*)];
unsigned char type;
unsigned char flags;
} lmsg;
DATA S T F
T F
S DATA
vsm
lmsg
writer thread
reader thread
YQueue
yqueue_t <msg_t, 256>
yqueue_t <command_t, 16>
struct chunk_t
{
T values [N];
chunk_t *prev;
chunk_t *next;
};
atomic_ptr_t <chunk_t>
spare_chunk
...
begin
back
• Only single thread can read from begin_chunk
• Only single thread can write to yqueue_t <msg_t> to back chunk
• Only single thread can write to yqueue_t <command_t> at a time
YPipe
atomic_ptr_t <T> c
Reader
Writer
T* r
T* w
T* f
bool flush () {
if ( c.cas ( w, f ) != w ) {
c.set ( f ) ;
w = f ;
return false ; // reader is sleeping
}
w = f ;
return true ;
}
bool check_read () {
if ( queue.front () != r ) return true ;
r = c.cas ( queue.front () , NULL ) ;
if ( queue.front () == r )
return false ; // nothing to read
return true;
}
read() =>
queue<T>.pop
write() =>
queue<T>.push
r w f
Signaler
socketpair ( AF_UNIX, SOCK_STREAM, 0, sv[2] )
int w = sv[0]; // writer fd
int r = sv[1]; // reader fd, Used at IOThread.poll
Reader
recv () {
:: recv ( r , dummy[1] );
}
wait ( timeout ) {
poll ( r , timeout );
}
Writer
send () {
:: send ( w, dummy[1] );
}
Mailbox
ypipe_t <command_t, 16> cpipe
signaler_t signaler
Reader
Writer
recv (timeout) {
signaler.wait (timeout)
return cpipe.read ()
}
send (cmd) {
lock ()
cpipe.write (cmd)
cpipe.flush ()
unlock ()
signaler.send ()
}
ZMQ Socket
ZMQ Socket
mailbox_t
signaler_
typipe_t
<cmd_t>
Session
Socket
Session
Socket
r
fd
fd
ypipe_t <msg_t> inpipe
ypipe_t <msg_t> outpipe
• Session is create when connect / accept
•Worker thread owns ZMQ socket
• IOThread owns Sessions
• recv msg from socket and en-queue inpipe
• recv msg from outpipe and send to socket
• zsocket.send en-queue to outpipe
• zsocket.recv de-queue from inpipe if any
main/worker
IOThread
io_thread
ZMQ Socket
mailbox
Session
Socket
poller
ZMQ
Socket
ZMQ
Socket
ZMQ
Socket
ZMQ
Socket
Session
mailbox
zsocket.write(msg)
outpipe.write(msg)
activate_read
session.read_activated
engine.activate_out
engine.out_event
SessionSessionSession
Stream Engine
engine.in_event
outpipe.write(msg)
activate_read
zsocket.read_activated
msg = inpipe.read
in_event () { // read from socket
size = 8192 // ***
buffer = decoder . get_buffer (size)
::recv (buffer, size)
decoder . process_buffer(buffer)
session . flush()
}
out_event () { // write to socket
size = 8192 // ***
buffer = encoder . get_data (size)
::send (buffer, size)
}
msg = parse (buffer)
session.write (msg)
Stream Engine
msg = session.read ()
buffer.fill (msg)
Summary
inline
lock-free
well-defined threading model
less system calls
• malloc / free
• bulk socket recv / send
• balance copy overhead
JeroMQ - jeromq.org
Hand-made
Compatible with ZeroMQ-3
tcp:// inproc://
ipc:// pgm://
same dev experience
95%~ performance
JeroMQ - diff
Java NIO
SelectableChannel
(Direct) ByteBuffer
Signaler
Pipe.SourceChannel / Pipe.SinkChannel
Mixed with counter
YQueue - circular linked list
Plain Socket Proxy
Persistence - Kafka alike
MappedByteBuffer
ZeroCopy
Future
Zero Persistence Queue
http://github.com/miniway/zper
Faster than Kafka
50% Less code
Configurable topology
Java 7 - AsynchronousChannel
Conclusion
Why reinvent the wheel
“The only limitation is your imagination and
sobriety”
Q/A

More Related Content

What's hot

Docker Hub: Past, Present and Future by Ken Cochrane & BC Wong
Docker Hub: Past, Present and Future by Ken Cochrane & BC WongDocker Hub: Past, Present and Future by Ken Cochrane & BC Wong
Docker Hub: Past, Present and Future by Ken Cochrane & BC Wong
Docker, Inc.
 
DevNetCreate - ACI and Kubernetes Integration
DevNetCreate - ACI and Kubernetes IntegrationDevNetCreate - ACI and Kubernetes Integration
DevNetCreate - ACI and Kubernetes Integration
Hank Preston
 

What's hot (20)

Multitenancy on EKS
Multitenancy on EKSMultitenancy on EKS
Multitenancy on EKS
 
Kernel Recipes 2015: Anatomy of an atomic KMS driver
Kernel Recipes 2015: Anatomy of an atomic KMS driverKernel Recipes 2015: Anatomy of an atomic KMS driver
Kernel Recipes 2015: Anatomy of an atomic KMS driver
 
OVS v OVS-DPDK
OVS v OVS-DPDKOVS v OVS-DPDK
OVS v OVS-DPDK
 
Xen in Safety-Critical Systems - Critical Summit 2022
Xen in Safety-Critical Systems - Critical Summit 2022Xen in Safety-Critical Systems - Critical Summit 2022
Xen in Safety-Critical Systems - Critical Summit 2022
 
Deep Dive into Docker Swarm Mode
Deep Dive into Docker Swarm ModeDeep Dive into Docker Swarm Mode
Deep Dive into Docker Swarm Mode
 
Containers and workload security an overview
Containers and workload security an overview Containers and workload security an overview
Containers and workload security an overview
 
Docker Hub: Past, Present and Future by Ken Cochrane & BC Wong
Docker Hub: Past, Present and Future by Ken Cochrane & BC WongDocker Hub: Past, Present and Future by Ken Cochrane & BC Wong
Docker Hub: Past, Present and Future by Ken Cochrane & BC Wong
 
Architecting for the Cloud using NetflixOSS - Codemash Workshop
Architecting for the Cloud using NetflixOSS - Codemash WorkshopArchitecting for the Cloud using NetflixOSS - Codemash Workshop
Architecting for the Cloud using NetflixOSS - Codemash Workshop
 
Introduction à docker.io
Introduction à docker.ioIntroduction à docker.io
Introduction à docker.io
 
ZFS in 30 minutes
ZFS in 30 minutesZFS in 30 minutes
ZFS in 30 minutes
 
NAT64 Overview
NAT64 OverviewNAT64 Overview
NAT64 Overview
 
BlueHat v17 || Out of the Truman Show: VM Escape in VMware Gracefully
BlueHat v17 || Out of the Truman Show: VM Escape in VMware Gracefully BlueHat v17 || Out of the Truman Show: VM Escape in VMware Gracefully
BlueHat v17 || Out of the Truman Show: VM Escape in VMware Gracefully
 
Java - Primeiros passos
Java - Primeiros passosJava - Primeiros passos
Java - Primeiros passos
 
DevNetCreate - ACI and Kubernetes Integration
DevNetCreate - ACI and Kubernetes IntegrationDevNetCreate - ACI and Kubernetes Integration
DevNetCreate - ACI and Kubernetes Integration
 
Alphorm.com Formation Docker (1/2) : Installation et Administration
Alphorm.com Formation Docker (1/2) : Installation et AdministrationAlphorm.com Formation Docker (1/2) : Installation et Administration
Alphorm.com Formation Docker (1/2) : Installation et Administration
 
Implementation &amp; Comparison Of Rdma Over Ethernet
Implementation &amp; Comparison Of Rdma Over EthernetImplementation &amp; Comparison Of Rdma Over Ethernet
Implementation &amp; Comparison Of Rdma Over Ethernet
 
Docker
DockerDocker
Docker
 
Persistência com JPA usando o NetBeans 7
Persistência com JPA usando o NetBeans 7Persistência com JPA usando o NetBeans 7
Persistência com JPA usando o NetBeans 7
 
Docker internals
Docker internalsDocker internals
Docker internals
 
The Linux Kernel Implementation of Pipes and FIFOs
The Linux Kernel Implementation of Pipes and FIFOsThe Linux Kernel Implementation of Pipes and FIFOs
The Linux Kernel Implementation of Pipes and FIFOs
 

Similar to Zeromq anatomy & jeromq

Степан Кольцов — Rust — лучше, чем C++
Степан Кольцов — Rust — лучше, чем C++Степан Кольцов — Rust — лучше, чем C++
Степан Кольцов — Rust — лучше, чем C++
Yandex
 
Shell to be modified#include stdlib.h #include unistd.h .pdf
Shell to be modified#include stdlib.h #include unistd.h .pdfShell to be modified#include stdlib.h #include unistd.h .pdf
Shell to be modified#include stdlib.h #include unistd.h .pdf
clarityvision
 

Similar to Zeromq anatomy & jeromq (20)

Distributed Computing Patterns in R
Distributed Computing Patterns in RDistributed Computing Patterns in R
Distributed Computing Patterns in R
 
Zmq in context of openstack
Zmq in context of openstackZmq in context of openstack
Zmq in context of openstack
 
20120705 - LUA_MODULE
20120705 - LUA_MODULE20120705 - LUA_MODULE
20120705 - LUA_MODULE
 
RAZORPOINT TCP/UDP PORTS LIST
RAZORPOINT TCP/UDP PORTS LISTRAZORPOINT TCP/UDP PORTS LIST
RAZORPOINT TCP/UDP PORTS LIST
 
Debugging Ruby Systems
Debugging Ruby SystemsDebugging Ruby Systems
Debugging Ruby Systems
 
OpenSMTPD: we deliver !!
OpenSMTPD: we deliver !!OpenSMTPD: we deliver !!
OpenSMTPD: we deliver !!
 
The New Systems Performance
The New Systems PerformanceThe New Systems Performance
The New Systems Performance
 
Npc08
Npc08Npc08
Npc08
 
Степан Кольцов — Rust — лучше, чем C++
Степан Кольцов — Rust — лучше, чем C++Степан Кольцов — Rust — лучше, чем C++
Степан Кольцов — Rust — лучше, чем C++
 
Pf: the OpenBSD packet filter
Pf: the OpenBSD packet filterPf: the OpenBSD packet filter
Pf: the OpenBSD packet filter
 
Services
ServicesServices
Services
 
Tc pdump mod
Tc pdump modTc pdump mod
Tc pdump mod
 
Shell to be modified#include stdlib.h #include unistd.h .pdf
Shell to be modified#include stdlib.h #include unistd.h .pdfShell to be modified#include stdlib.h #include unistd.h .pdf
Shell to be modified#include stdlib.h #include unistd.h .pdf
 
20120521 - zeroMQ
20120521 - zeroMQ20120521 - zeroMQ
20120521 - zeroMQ
 
WMQ Toolbox: 20 Scripts, One-liners, & Utilities for UNIX & Windows
WMQ Toolbox: 20 Scripts, One-liners, & Utilities for UNIX & Windows WMQ Toolbox: 20 Scripts, One-liners, & Utilities for UNIX & Windows
WMQ Toolbox: 20 Scripts, One-liners, & Utilities for UNIX & Windows
 
اسلاید دوم جلسه یازدهم کلاس پایتون برای هکر های قانونی
اسلاید دوم جلسه یازدهم کلاس پایتون برای هکر های قانونیاسلاید دوم جلسه یازدهم کلاس پایتون برای هکر های قانونی
اسلاید دوم جلسه یازدهم کلاس پایتون برای هکر های قانونی
 
A22 Introduction to DTrace by Kyle Hailey
A22 Introduction to DTrace by Kyle HaileyA22 Introduction to DTrace by Kyle Hailey
A22 Introduction to DTrace by Kyle Hailey
 
[CB20]-U25 Automated Hunting for Cross-Server Xrefs in Microsoft RPC and COM ...
[CB20]-U25 Automated Hunting for Cross-Server Xrefs in Microsoft RPC and COM ...[CB20]-U25 Automated Hunting for Cross-Server Xrefs in Microsoft RPC and COM ...
[CB20]-U25 Automated Hunting for Cross-Server Xrefs in Microsoft RPC and COM ...
 
Debugging Ruby
Debugging RubyDebugging Ruby
Debugging Ruby
 
Pycon - Python for ethical hackers
Pycon - Python for ethical hackers Pycon - Python for ethical hackers
Pycon - Python for ethical hackers
 

Recently uploaded

%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
masabamasaba
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
masabamasaba
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
masabamasaba
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
masabamasaba
 

Recently uploaded (20)

WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
 

Zeromq anatomy & jeromq