SlideShare a Scribd company logo
1 of 31
Event Driven with LibUV and
ZeroMQ
Phase I Summary
Luke.jf.luo@gmail.com
Outline
● Algo Trading Business Flow Review
● Order Module Design: Current Flaw
● Distributed System: Theory Review
● Event Driven System: Review
● Event Driven Design In Algo Trading
● Project Plan
Algo Trading Flow
I1 I2 I3 …... In
任务
( 下达 /
取消 /
停止 )
Instrument (Buy/Sell)
下单
撤单
下单
撤单
步长步长
.
.
.
...
...
….........
...
...
….........
...
...
….........
End
…............
Current Design Flaw
● Bad Assumptions
– Serial Execution Among Instructments
– Batch Job ( 1 Sec Interval)
– I/O Cost/ Latency: Neglectable
– Computation Cost/Latency: Neglectable
– No Uncertainty
Reality
● Parallel execution of Instruments
● Market change in Ms, 1 Sec (or More) fixed reponse interval
is 1000X
● I/O is SLOW comaring to CPU speed (10^9 order)
● Communication Channel will Break
● Only God have ALL TIMELY information for decision making.
We people live in UNCERTAINTY
● Tradeoff: Best Effort Decision versus Perfect Decision
Distributed System: Our Reality
● Parallel: Everything is Moving
● Error Prone (Fault): No 99.9999999....%
Gurantee
● Uncertainty: Who/What/Where/When/Why
● Concensus/Consistency with HIGH COST
● Speed limit: Light Travels at (300,000km/Sec)
CAP: No Perfect World
Case:Two Generals' Problem
Case:Two Generals' Problem
● 1975 . E. A. Akkoyunlu, K. Ekanadham, and R.
V. Huber "Some Constraints and Trade-offs in
the Design of Network Communications"
● “A pragmatic approach to dealing with the Two
Generals' Problem is to use schemes that
accept the uncertainty of the communications
channel and not attempt to eliminate it, but
rather mitigate it to an acceptable degree.”
TCP: Connection Establishment
TCP: Sliding Window
Event Driven: History
● 1960s: Mainframe. Batch Job Oriented
● 1970s: Unix. Interactive,Timesharing Terminal
● GUI programming:
– Xerox : mouse
– Apple: Apple II
– Microsoft: Windows
– MIT: X windows
– …...
Event Driven: Now
● Libuv: Chrome browser, node.js...
● Libev/libevent
● Boost ASIO
● ACE/ICE
● Qt event loop
● Glib/Gevent
Event Driven: Now
● Nginx,apache,Twisted,Comet
● Node.js
● Python Asyncio
● Go channel
● Scala Actor
● C++ 11 Promise/Future,Coroutine,Closure
● …........
I/O Modelling
●  blocking I/O
●  nonblocking I/O
●  I/O multiplexing (select and poll)
●  signal driven I/O (SIGIO)
●  asynchronous I/O (the POSIX aio_functions)
Quoted from “UNIX Network Programming Volume
1”
Async/Event Driven Design:
Reactor
Proactor
So we are event-driven ready.
But...
● Components are mostly event driven
● Interface Among components are BLOCKING
INTERFACE! (block/wait/timeout....)
● One blocking will ruin the whole infrastructure!
● “Public Land Tragic”
class StringQue : public MsgQueBase
StringQueue is everywhere
[luke@rmbp service_multichannel]$ find . -name StringQue.h
./orderservice/OMSInfterfaceDemo/StringQue.h
./optionhedgeservice/optionhedgeservice/StringQue.h
./queryservice/queryservice/StringQue.h
./queryservice/queryservice_auto_qt_profitchart/StringQue.h
./queryservice/queryservice_auto_qt/StringQue.h
./strategyservice_new/hedgefutureservice/StringQue.h
./strategyservice_new/algoorderservice/StringQue.h
./strategyservice_new/algoorderserviceFuture/StringQue.h
./strategyservice/hedgefutureservice/StringQue.h
./strategyservice/optionhedgeservice/optionhedgeservice/StringQue.h
./strategyservice/algoorderservice/StringQue.h
./strategyservice/algoorderserviceFuture/StringQue.h
./quoteservice/quoteservicelevel2/StringQue.h
./quoteservice/quoteservicelevel2datafeed/StringQue.h
./quoteservice/quoteservicelevel2_new/StringQue.h
./quoteservice/quoteservicelevel2datafeed_clb/StringQue.h
How we use StringQueue?
Vision
● A fault tolerant, responsive trading platorm
– Respond to every marktet tick/heartbeat
● Maintain “fresh” market snapshot
● React as every tick comes
– Async, Parallel order fullfillment
● Handle > 1000 orders one server instance without
pressure
● Milisec level processing delay per order action
Vision: Unified Event Loop
Libuv
event Loop
ZeroMq
socket
Normal socket
timer
Other Async events
eventfd
fd
timer_t handle
async_t handle
Parallel Tasks req_t
Thread Pool
Async Tasks
Order Fullfill
Market Snapshot
update
Other
Event Loop
Other business
modules
Async Programming
● Callback
● Task(threading)
● Future/Promise
● Async I/O
● Coroutine
●
Trading Version 2
I1 I2 I3 …... In
下单
撤单
下单
撤单
timeouttimeout
.
.
.
...
...
...
...
….........
...
...
….........
End
…............
tick
….........
EndEndEnd
tick
tick
tick
Project Plan
● Goal: A testable new framwork
– Algotrading as typical business test case
– High throughput, low latency
– Fault Tolerant with sensible tradeoff strategy
Side by Side comparison with current order system
Task:
● Project Managment (Wei Song)
● Event Loop, ZeroMQ (Tie Gang/Luke)
● Market snapshot update (Wei Song/Ze Yu)
● Order business module rewrite(Ze Yu/Wei Song)
● Testing environment (Wei Song/Tie Gang)
– Simulation data/replay
– OMS simulator
● Testing
– All
– + Calvin + other business staff
Schedule?
● What can we accomplish before Spring
Festival?

More Related Content

What's hot

Interrupt Affinityについて
Interrupt AffinityについてInterrupt Affinityについて
Interrupt Affinityについて
Takuya ASADA
 

What's hot (20)

Build Low-Latency Applications in Rust on ScyllaDB
Build Low-Latency Applications in Rust on ScyllaDBBuild Low-Latency Applications in Rust on ScyllaDB
Build Low-Latency Applications in Rust on ScyllaDB
 
Your 1st Ceph cluster
Your 1st Ceph clusterYour 1st Ceph cluster
Your 1st Ceph cluster
 
[오픈소스컨설팅] Linux Network Troubleshooting
[오픈소스컨설팅] Linux Network Troubleshooting[오픈소스컨설팅] Linux Network Troubleshooting
[오픈소스컨설팅] Linux Network Troubleshooting
 
暗認本読書会7
暗認本読書会7暗認本読書会7
暗認本読書会7
 
Apache Kafka vs. Cloud-native iPaaS Integration Platform Middleware
Apache Kafka vs. Cloud-native iPaaS Integration Platform MiddlewareApache Kafka vs. Cloud-native iPaaS Integration Platform Middleware
Apache Kafka vs. Cloud-native iPaaS Integration Platform Middleware
 
Disk health prediction for Ceph
Disk health prediction for CephDisk health prediction for Ceph
Disk health prediction for Ceph
 
Redis Streams for Event-Driven Microservices
Redis Streams for Event-Driven MicroservicesRedis Streams for Event-Driven Microservices
Redis Streams for Event-Driven Microservices
 
Interrupt Affinityについて
Interrupt AffinityについてInterrupt Affinityについて
Interrupt Affinityについて
 
STLの型の使い分け(ダイジェスト版) @ Sapporo.cpp 第7回勉強会 (2014.10.18)
STLの型の使い分け(ダイジェスト版) @ Sapporo.cpp 第7回勉強会 (2014.10.18)STLの型の使い分け(ダイジェスト版) @ Sapporo.cpp 第7回勉強会 (2014.10.18)
STLの型の使い分け(ダイジェスト版) @ Sapporo.cpp 第7回勉強会 (2014.10.18)
 
Webinar: 99 Ways to Enrich Streaming Data with Apache Flink - Konstantin Knauf
Webinar: 99 Ways to Enrich Streaming Data with Apache Flink - Konstantin KnaufWebinar: 99 Ways to Enrich Streaming Data with Apache Flink - Konstantin Knauf
Webinar: 99 Ways to Enrich Streaming Data with Apache Flink - Konstantin Knauf
 
원격회의 분야의 실감형 콘텐츠 표준활용 동향_WebRTC 융합_손성영
원격회의 분야의 실감형 콘텐츠 표준활용 동향_WebRTC 융합_손성영원격회의 분야의 실감형 콘텐츠 표준활용 동향_WebRTC 융합_손성영
원격회의 분야의 실감형 콘텐츠 표준활용 동향_WebRTC 융합_손성영
 
LLVM最適化のこつ
LLVM最適化のこつLLVM最適化のこつ
LLVM最適化のこつ
 
GC free coding in @Java presented @Geecon
GC free coding in @Java presented @GeeconGC free coding in @Java presented @Geecon
GC free coding in @Java presented @Geecon
 
NextGen Server/Client Architecture - gRPC + Unity + C#
NextGen Server/Client Architecture - gRPC + Unity + C#NextGen Server/Client Architecture - gRPC + Unity + C#
NextGen Server/Client Architecture - gRPC + Unity + C#
 
Under The Hood Of A Shard-Per-Core Database Architecture
Under The Hood Of A Shard-Per-Core Database ArchitectureUnder The Hood Of A Shard-Per-Core Database Architecture
Under The Hood Of A Shard-Per-Core Database Architecture
 
MagicOnion~C#でゲームサーバを開発しよう~
MagicOnion~C#でゲームサーバを開発しよう~MagicOnion~C#でゲームサーバを開発しよう~
MagicOnion~C#でゲームサーバを開発しよう~
 
Introducing envoy-based service mesh at Booking.com
Introducing envoy-based service mesh at Booking.comIntroducing envoy-based service mesh at Booking.com
Introducing envoy-based service mesh at Booking.com
 
[CEDEC2017] LINEゲームのセキュリティ診断手法
[CEDEC2017] LINEゲームのセキュリティ診断手法[CEDEC2017] LINEゲームのセキュリティ診断手法
[CEDEC2017] LINEゲームのセキュリティ診断手法
 
OrientDB
OrientDBOrientDB
OrientDB
 
Apache Kafka and Blockchain - Comparison and a Kafka-native Implementation
Apache Kafka and Blockchain - Comparison and a Kafka-native ImplementationApache Kafka and Blockchain - Comparison and a Kafka-native Implementation
Apache Kafka and Blockchain - Comparison and a Kafka-native Implementation
 

Viewers also liked

ZeroMQ: Super Sockets - by J2 Labs
ZeroMQ: Super Sockets - by J2 LabsZeroMQ: Super Sockets - by J2 Labs
ZeroMQ: Super Sockets - by J2 Labs
James Dennis
 

Viewers also liked (9)

Archlinux dev environment
Archlinux dev environmentArchlinux dev environment
Archlinux dev environment
 
Who Is a Software Architect?
Who Is a Software Architect?Who Is a Software Architect?
Who Is a Software Architect?
 
'Quality Engineering: Build It Right The First Time' by Allan Woodcock, Shoba...
'Quality Engineering: Build It Right The First Time' by Allan Woodcock, Shoba...'Quality Engineering: Build It Right The First Time' by Allan Woodcock, Shoba...
'Quality Engineering: Build It Right The First Time' by Allan Woodcock, Shoba...
 
Protocol Buffer.ppt
Protocol Buffer.pptProtocol Buffer.ppt
Protocol Buffer.ppt
 
FOSDEM 2011 - 0MQ
FOSDEM 2011 - 0MQFOSDEM 2011 - 0MQ
FOSDEM 2011 - 0MQ
 
ZeroMQ: Super Sockets - by J2 Labs
ZeroMQ: Super Sockets - by J2 LabsZeroMQ: Super Sockets - by J2 Labs
ZeroMQ: Super Sockets - by J2 Labs
 
A deep dive into libuv
A deep dive into libuvA deep dive into libuv
A deep dive into libuv
 
libuv: cross platform asynchronous i/o
libuv: cross platform asynchronous i/olibuv: cross platform asynchronous i/o
libuv: cross platform asynchronous i/o
 
Overview of ZeroMQ
Overview of ZeroMQOverview of ZeroMQ
Overview of ZeroMQ
 

Similar to Event Driven with LibUV and ZeroMQ

ekbpy'2012 - Антон Патрушев - ZeroMQ
ekbpy'2012 - Антон Патрушев - ZeroMQekbpy'2012 - Антон Патрушев - ZeroMQ
ekbpy'2012 - Антон Патрушев - ZeroMQ
it-people
 
Demo the reactive jargons
Demo the reactive jargonsDemo the reactive jargons
Demo the reactive jargons
Thoughtworks
 
Tornado Web Server Internals
Tornado Web Server InternalsTornado Web Server Internals
Tornado Web Server Internals
Praveen Gollakota
 
smalltalk numbercrunching
smalltalk numbercrunchingsmalltalk numbercrunching
smalltalk numbercrunching
Daniel Poon
 

Similar to Event Driven with LibUV and ZeroMQ (20)

Asynchronous programming intro
Asynchronous programming introAsynchronous programming intro
Asynchronous programming intro
 
Common mistakes in android development
Common mistakes in android developmentCommon mistakes in android development
Common mistakes in android development
 
Reactive mistakes - ScalaDays Chicago 2017
Reactive mistakes -  ScalaDays Chicago 2017Reactive mistakes -  ScalaDays Chicago 2017
Reactive mistakes - ScalaDays Chicago 2017
 
ekbpy'2012 - Антон Патрушев - ZeroMQ
ekbpy'2012 - Антон Патрушев - ZeroMQekbpy'2012 - Антон Патрушев - ZeroMQ
ekbpy'2012 - Антон Патрушев - ZeroMQ
 
Async Web Frameworks in Python
Async Web Frameworks in PythonAsync Web Frameworks in Python
Async Web Frameworks in Python
 
IoT with Ruby/mruby - RubyWorld Conference 2015
IoT with Ruby/mruby - RubyWorld Conference 2015IoT with Ruby/mruby - RubyWorld Conference 2015
IoT with Ruby/mruby - RubyWorld Conference 2015
 
Demo the reactive jargons by Mushtaq Ahmed, ThoughtWorks presented at Pune Sc...
Demo the reactive jargons by Mushtaq Ahmed, ThoughtWorks presented at Pune Sc...Demo the reactive jargons by Mushtaq Ahmed, ThoughtWorks presented at Pune Sc...
Demo the reactive jargons by Mushtaq Ahmed, ThoughtWorks presented at Pune Sc...
 
Demo the reactive jargons
Demo the reactive jargonsDemo the reactive jargons
Demo the reactive jargons
 
Kernel Recipes 2018 - Live (Kernel) Patching: status quo and status futurus -...
Kernel Recipes 2018 - Live (Kernel) Patching: status quo and status futurus -...Kernel Recipes 2018 - Live (Kernel) Patching: status quo and status futurus -...
Kernel Recipes 2018 - Live (Kernel) Patching: status quo and status futurus -...
 
An Abusive Relationship with AngularJS
An Abusive Relationship with AngularJSAn Abusive Relationship with AngularJS
An Abusive Relationship with AngularJS
 
Shall we play a game?
Shall we play a game?Shall we play a game?
Shall we play a game?
 
Ipc feb4
Ipc feb4Ipc feb4
Ipc feb4
 
Tornado Web Server Internals
Tornado Web Server InternalsTornado Web Server Internals
Tornado Web Server Internals
 
The art of concurrent programming
The art of concurrent programmingThe art of concurrent programming
The art of concurrent programming
 
smalltalk numbercrunching
smalltalk numbercrunchingsmalltalk numbercrunching
smalltalk numbercrunching
 
Barcamp presentation
Barcamp presentationBarcamp presentation
Barcamp presentation
 
IoTivity Tutorial: Prototyping IoT Devices on GNU/Linux
IoTivity Tutorial: Prototyping IoT Devices on GNU/LinuxIoTivity Tutorial: Prototyping IoT Devices on GNU/Linux
IoTivity Tutorial: Prototyping IoT Devices on GNU/Linux
 
Free the Functions with Fn project!
Free the Functions with Fn project!Free the Functions with Fn project!
Free the Functions with Fn project!
 
jSession #4 - Maciej Próchniak - Java 9, OSGi - czy w epoce mikroserwisów pot...
jSession #4 - Maciej Próchniak - Java 9, OSGi - czy w epoce mikroserwisów pot...jSession #4 - Maciej Próchniak - Java 9, OSGi - czy w epoce mikroserwisów pot...
jSession #4 - Maciej Próchniak - Java 9, OSGi - czy w epoce mikroserwisów pot...
 
Voxxed Days Villnius 2015 - Burning Marshmallows
Voxxed Days Villnius 2015 - Burning MarshmallowsVoxxed Days Villnius 2015 - Burning Marshmallows
Voxxed Days Villnius 2015 - Burning Marshmallows
 

Recently uploaded

+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...
+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...
+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...
Health
 
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
HenryBriggs2
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
Epec Engineered Technologies
 
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
jaanualu31
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Kandungan 087776558899
 

Recently uploaded (20)

Air Compressor reciprocating single stage
Air Compressor reciprocating single stageAir Compressor reciprocating single stage
Air Compressor reciprocating single stage
 
Rums floating Omkareshwar FSPV IM_16112021.pdf
Rums floating Omkareshwar FSPV IM_16112021.pdfRums floating Omkareshwar FSPV IM_16112021.pdf
Rums floating Omkareshwar FSPV IM_16112021.pdf
 
+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...
+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...
+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
 
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
 
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
 
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
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS Lambda
 
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARHAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
 
Computer Lecture 01.pptxIntroduction to Computers
Computer Lecture 01.pptxIntroduction to ComputersComputer Lecture 01.pptxIntroduction to Computers
Computer Lecture 01.pptxIntroduction to Computers
 
AIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech studentsAIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech students
 
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equation
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torque
 
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best ServiceTamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptx
 

Event Driven with LibUV and ZeroMQ

  • 1. Event Driven with LibUV and ZeroMQ Phase I Summary Luke.jf.luo@gmail.com
  • 2. Outline ● Algo Trading Business Flow Review ● Order Module Design: Current Flaw ● Distributed System: Theory Review ● Event Driven System: Review ● Event Driven Design In Algo Trading ● Project Plan
  • 3. Algo Trading Flow I1 I2 I3 …... In 任务 ( 下达 / 取消 / 停止 ) Instrument (Buy/Sell) 下单 撤单 下单 撤单 步长步长 . . . ... ... …......... ... ... …......... ... ... …......... End …............
  • 4. Current Design Flaw ● Bad Assumptions – Serial Execution Among Instructments – Batch Job ( 1 Sec Interval) – I/O Cost/ Latency: Neglectable – Computation Cost/Latency: Neglectable – No Uncertainty
  • 5. Reality ● Parallel execution of Instruments ● Market change in Ms, 1 Sec (or More) fixed reponse interval is 1000X ● I/O is SLOW comaring to CPU speed (10^9 order) ● Communication Channel will Break ● Only God have ALL TIMELY information for decision making. We people live in UNCERTAINTY ● Tradeoff: Best Effort Decision versus Perfect Decision
  • 6. Distributed System: Our Reality ● Parallel: Everything is Moving ● Error Prone (Fault): No 99.9999999....% Gurantee ● Uncertainty: Who/What/Where/When/Why ● Concensus/Consistency with HIGH COST ● Speed limit: Light Travels at (300,000km/Sec)
  • 9. Case:Two Generals' Problem ● 1975 . E. A. Akkoyunlu, K. Ekanadham, and R. V. Huber "Some Constraints and Trade-offs in the Design of Network Communications" ● “A pragmatic approach to dealing with the Two Generals' Problem is to use schemes that accept the uncertainty of the communications channel and not attempt to eliminate it, but rather mitigate it to an acceptable degree.”
  • 12. Event Driven: History ● 1960s: Mainframe. Batch Job Oriented ● 1970s: Unix. Interactive,Timesharing Terminal ● GUI programming: – Xerox : mouse – Apple: Apple II – Microsoft: Windows – MIT: X windows – …...
  • 13. Event Driven: Now ● Libuv: Chrome browser, node.js... ● Libev/libevent ● Boost ASIO ● ACE/ICE ● Qt event loop ● Glib/Gevent
  • 14. Event Driven: Now ● Nginx,apache,Twisted,Comet ● Node.js ● Python Asyncio ● Go channel ● Scala Actor ● C++ 11 Promise/Future,Coroutine,Closure ● …........
  • 15. I/O Modelling ●  blocking I/O ●  nonblocking I/O ●  I/O multiplexing (select and poll) ●  signal driven I/O (SIGIO) ●  asynchronous I/O (the POSIX aio_functions) Quoted from “UNIX Network Programming Volume 1”
  • 16.
  • 18.
  • 20.
  • 21. So we are event-driven ready. But... ● Components are mostly event driven ● Interface Among components are BLOCKING INTERFACE! (block/wait/timeout....) ● One blocking will ruin the whole infrastructure! ● “Public Land Tragic”
  • 22. class StringQue : public MsgQueBase
  • 23. StringQueue is everywhere [luke@rmbp service_multichannel]$ find . -name StringQue.h ./orderservice/OMSInfterfaceDemo/StringQue.h ./optionhedgeservice/optionhedgeservice/StringQue.h ./queryservice/queryservice/StringQue.h ./queryservice/queryservice_auto_qt_profitchart/StringQue.h ./queryservice/queryservice_auto_qt/StringQue.h ./strategyservice_new/hedgefutureservice/StringQue.h ./strategyservice_new/algoorderservice/StringQue.h ./strategyservice_new/algoorderserviceFuture/StringQue.h ./strategyservice/hedgefutureservice/StringQue.h ./strategyservice/optionhedgeservice/optionhedgeservice/StringQue.h ./strategyservice/algoorderservice/StringQue.h ./strategyservice/algoorderserviceFuture/StringQue.h ./quoteservice/quoteservicelevel2/StringQue.h ./quoteservice/quoteservicelevel2datafeed/StringQue.h ./quoteservice/quoteservicelevel2_new/StringQue.h ./quoteservice/quoteservicelevel2datafeed_clb/StringQue.h
  • 24. How we use StringQueue?
  • 25. Vision ● A fault tolerant, responsive trading platorm – Respond to every marktet tick/heartbeat ● Maintain “fresh” market snapshot ● React as every tick comes – Async, Parallel order fullfillment ● Handle > 1000 orders one server instance without pressure ● Milisec level processing delay per order action
  • 26. Vision: Unified Event Loop Libuv event Loop ZeroMq socket Normal socket timer Other Async events eventfd fd timer_t handle async_t handle Parallel Tasks req_t Thread Pool Async Tasks Order Fullfill Market Snapshot update Other Event Loop Other business modules
  • 27. Async Programming ● Callback ● Task(threading) ● Future/Promise ● Async I/O ● Coroutine ●
  • 28. Trading Version 2 I1 I2 I3 …... In 下单 撤单 下单 撤单 timeouttimeout . . . ... ... ... ... …......... ... ... …......... End …............ tick …......... EndEndEnd tick tick tick
  • 29. Project Plan ● Goal: A testable new framwork – Algotrading as typical business test case – High throughput, low latency – Fault Tolerant with sensible tradeoff strategy Side by Side comparison with current order system
  • 30. Task: ● Project Managment (Wei Song) ● Event Loop, ZeroMQ (Tie Gang/Luke) ● Market snapshot update (Wei Song/Ze Yu) ● Order business module rewrite(Ze Yu/Wei Song) ● Testing environment (Wei Song/Tie Gang) – Simulation data/replay – OMS simulator ● Testing – All – + Calvin + other business staff
  • 31. Schedule? ● What can we accomplish before Spring Festival?