SlideShare a Scribd company logo
1 of 48
Linux-RT in Financial Markets
Adrien Mahieux
Performance Engineer
Orness
gh: github.com/Saruspete
tw: @Saruspete
em: adrien.mahieux@gmail.com
BOFH - $(uname -a)
Adrien Mahieux
Orness
Performance Engineer aka Microsecond hunter
How I’m seen from:
- HW Vendor: Client with funny cases, that may want this new feature
- Kernel Dev: Client with weird requests that breaks his model
- App Dev: The one that refuses “quick deployment” in prod (“No-as-a-Service”)
- End-Users: Why is my Linux desktop not working?!
Agenda
- What’s the Finance about ?
- Why would Finance actors need RealTime ?
- Real-time Challenges
- Monitoring and benchmarking
- Linus Torvalds: Controlling a laser with Linux is crazy, but everyone in this room is crazy in his own way. So if
you want to use Linux to control an industrial welding laser, I have no problem with your using PREEMPT_RT.
- Finance: Hold my beer
What’s the Finance about ?
Financial Markets 101
- Place where to exchange goods, currencies, insurances…
- Can trade any type of product:
- Physical: commodities, currencies, goods…
- Virtual: stock, index, insurance, futures, options..
- Rule 34: As long as there’s a need & a supplier, you can trade it
- Need to have a Trading License
- The market takes a fee for every transaction executed
- For an identical price, First arrived, first served
- You can see the Order Book (qties + price), but not “who”
Why would you trade
- Commodities (Fast-Food, beverage store, industrial...)
- Need to buy every day physical goods (commodities) for your business to run
- Need a delivery date and check product quality
- Want to have a cover over steel in case of import tariff
- Investor (individual or corporate)
- Stocks kept long-time (years...)
- Plays in the tendencies of the market (people reactions)
- May want an insurance in case of product fluctuations
Stock Market: from paper to electronic
Palais Brogniart 1973
Paris Stock Exchange
Stock Market: from paper to electronic
Palais Brogniart 1997
Paris Stock Exchange
Stock Market: from paper to electronic
Palais Brogniart 2016
Paris Stock Exchange
Paris Stock Exchange is at
Basildon, UK
Stock Market: from paper to electronic
Any Stock Exchange:
- Matching Engine
- Access Gateway
- Recorders
An history of technical optimizations
- Hire the fastest runner between “trading floor” (pit) to “trading offices”
- Went out of job with Telex & Tickers operated by secretaries
- 1983: Thomas Peterffy created the first touch-screen tablet: direct market
access
- With reduced latencies, stock minimal price went from 25cts to 1cts.
- CoLocation: host your servers in the market’s DC.
- From Optical Fiber to Microwaves
Stock Market: from paper to electronic
Automation - New strategies created
Legal: taking advantage of technology
- Arbitrage : Play on different prices for the same product on different markets
- Market Making: Provide securities available elsewhere
- Front Running: Using faster infrastructure to buy first what others wants
Illegal : manipulating market / Generate fake events
- Quote Stuffing: send lots of quotes to slow down other people
- Quote Stuffing(2): Place big sell orders (not 1st limit) to fake market pressure
- Wash Trade: Cross-trade: buy your own orders to generate fake volume
- Smoking: propose an interesting price, but cancel it immediately
HFT / High Frequency Trading
What is a “High Frequency” ?
Many definitions, no official one
Catch-All term for “Automated” or “Algorithmic Trading”
Current status: 80% of all trades made by bots
The problem: Bots reacts to events (really, any event…)
⇒ Risk of “Flash Crash” (amplification loop between bots)
Front Running
Use of a technical advantage to vampirise traders wanting to make a deal
Brad Katsuyama wanted to buy 100,000 AMD shares:
- 2006: Placed its order, got its 100,000 shares.
- 2007: Placed its order, got 80,000 shares
- 2008: Placed its order, got 70,000 shares
- 2009: Placed its order, got 45,000 shares
Maybe more people want to buy AMD at the same time?
Front Running
There’s about 13 stocks
exchanges in US
Split 100K order in 4 * 25K
Brad latencies were 2ms
from first (BATS) to last
(NYSE)
Front Running
Front-Runner with
optimized infra is 0.5ms
FR cancel their Sell order
on the different markets
FR buy shares ahead of
Brad and sell them back at
a higher price (+1 cts)
Why would Finance need RealTime ?
Front Running - Protect against it
Don’t send all orders at the
same time: slow down
Delay sending based on
the time needed to reach
them
Closest locations will be
sent after farther ones.
Goal: they all touch their
target market at the same
time
Regulations for Market Members
MIFID II requires Timestamp orders accuracy of 100µs
Everyone wanting to acquire stocks must go through a “Market Member” (usually a
Broker or a Bank) which has extensive regulations and risk analysis.
Market rules requires actors “to place an order with willingness to be executed”
Need accurate statistics for strategy backtest
Exchanges need fairness
A Stock Exchange is also a regulated entity.
Should ensure “Fairness for all” actors (not yet enforced)
- Co-Location hosting
- Same length of cable / Optical Fiber: 1m = 5ns
- Distributed Gateways to handle workload
Technical Challenges
x86 - What could go wrong ?
Tend to be Throughput optimized rather than Latency optimized
Interrupts: SMI, LOC, IPI, NMI
Frequency: Turbo Boost makes real freq vary greatly
Assembly: Transcribed to µops
Out Of Order Execution: need memory barriers
Compiler Optimization: Some neat tricks depending on options
NUMA: control placement of CPU, memory and cache snoop
x86 - CPU Isolation to reduce jitter
Goal: dedicate cores for specific processing and don’t disturb them ever.
Most frequent combination:
- IRQ Isolation: Move IRQs away from processing cores
- isolcpus= Change the default affinity of all userland process
- nohz_full= Don’t fire the scheduler interruption (thanks Frederic)
- rcu_nocbs= & rcu_nocb_poll Move away kthreads for RCU mechanism
- intel_idle.max_cstate=1 disable CPU c-states
- idle=poll when really angry
- noibrs noibpb nopti nospectre_v2 nospectre_v1 l1tf=off
nospec_store_bypass_disable no_stf_barrier mds=off mitigations=off
x86 - Application optimization
Application also has its share of work:
- No memory allocation in the critical path
- Cache isolation to avoid noisy neighbor (Intel CMT-CAT)
- Keep cache hot for critical path with fake events
- Network Polling by application (spinning 100% CPU)
- Memory locking to avoid swapping (mlock* sysctls in mm/mlock.c)
- Hardware Timestamping when available
x86 - Hardware modifications
Core placement & Pinning is hard : ACPI Table, Firmware update, Model changes...
Time Synchronisation
Needed for legal records, traceability and monitoring
NTP: sub-ms, very network dependant (from client to local server)
- Relies on server clock source (Often TSC)
PTP: sub µs, close to client thanks to boundary clocks:
- Smart switchs can offset their propagated values
- SmartNICs of final servers have an embedded oscillator
WhiteRabbit: sub ns, implemented by CERN and Eurex (among others)
Heavy network pps load
Awful kind of network workload:
- Packets < 256 bytes
- Spike only lasts a few milliseconds
- No cache miss allowed
- 10 Gbps at Pkt Size 1500 ~ 800.000 pps
- 10 Gbps at Pkt Size 128 ~ 10.000.000 pps
Better to just bypass the Kernel (DPDK, Onload, VMA)
Optical Fiber is slow : Go Microwave !
Optical Fiber:
- ⅔ of speed of light (wire is not empty and beam bounces)
- not straight : has to follow ground
- Compact and secure channel
Microwave:
- Full speed of light in vacuum
- Direct line of sight (only need repeaters for earth curvature)
- But small packet size: 64 (raw sockets)
- Subject to weather, Marine Traffic and Solar flares
Optical Fiber is slow : Go Microwave !
Houtem tower in Belgium:
Auction started at 255K€
sold for 5M€
Direct line of sight from Houtem to England
Time requirements
IEX : Speed bump to protect from
Front Runners
Best tech is no tech
A very long Optical Fiber adds
350µs latency
Monitoring & Profiling
Monitoring - Netdata
github.com/netdata/netdata
- 1s granularity
- Standalone
- Integrated alerting
- Lowest overhead monitoring
- 1000’s of metrics per second
- Self-explained configuration
- No conf needed to use
Profiling & Measurements
Measurement will have an impact
many TSC Flags: rdtscp, constant_tsc, nonstop_tsc, tsc_known_freq, tsc_adjust
CPU Perf Counters readable through MSR (Intel PCM: github.com/opcm/pcm)
Traces when it goes bad
ftrace ring buffer on production + crash plugin (thanks Steven)
Had multiple issues involving NFS, RCU, RT_Mutex…
Most of the time, it was an application issue with 3 factors:
- Spinning
- Realtime (FF) Scheduling
- Bad affinity
Network - FPGA to the rescue
The best code is the one not run
FPGA are perfect for Latency optimized workloads
⇒ High end FPGA are expensive
Still needs monitoring software on the host
⇒ Relies on communication channels and drivers
Network - Wire 2 Wire
Metamako Layer 1 Switch
Fast active tap: 4ns
Profiling and Dev Tools
Opengrok - https://github.com/opengrok/opengrok
Fast code browser with indexing and ctags support
Compiler Explorer - https://godbolt.org
Show compiled ASM and matching source lines
Agner Tables - https://www.agner.org/optimize/instruction_tables.pdf
List of x86 instruction latencies per CPU (Intel, AMD, Via)
QuickBench - http://quick-bench.com
Benchmarks
Dynticks-Testing
LinuxRT Cyclictest
Solarflare Sysjitter
Bitmover lm_bench
The Best benchmark...
Is still to test in production !
Bibliography
Trading - Market Operations
Michael Lewis - Flash Boys - ISBN: 978-0393244663
Alexandre Laumonier “4” (ISBN: 978-2930601106) & “5|6” (ISBN: 978-2930601106)
The Wall Street Code - youtube.com/watch?v=kFQJNeQDDHA
Flash Crash - youtube.com/watch?v=aq1Ln1UCoEU
Les Nouveaux Loups de Wall Street - youtube.com/watch?v=0KNwcJgKMbo
Trading - Technical reads
www.algo-logic.com/sites/default/files/Algo_Logic_How_To_Build_An_Exchange.pdf
Timing White Rabbit at Eurex: https://www.eurexchange.com/exchange-en/resources/initiatives/technical-
changes/high-precision-time-white-rabbit-pilot
Meanderful - meanderful.blogspot.com/
Sniper In Mahwah - sniperinmahwah.wordpress.com/
Microwave KMZ: https://sniperinmahwah.wordpress.com/2015/04/15/hft-in-my-backyard-the-map/
NYSE vs IEX https://www.businessinsider.fr/us/iex-vs-nyse-on-speed-bump-2017-3
Eurex Connection Gateways details: https://www.eurexchange.com/exchange-
en/resources/initiatives/technical-changes/connection-gateways
Trading - Official Business Websites
IEX about NYSE FIX GW: https://iextrading.com/about/press/op-ed/
Cboe (BATS/CHIX) markets.cboe.com/europe/equities/market_share/index/cboe
Questions ?
Bonus: Finance is always trending
Trading Fashion - High Heels
First of all, you have to
stand out from the crowd.
That’s why you see all
those Technicolor jackets.
A lot of guys wore shoes
with three-inch soles so
they’d look taller. There
was a guy in the Loop who
made his living resoling
shoes for traders.
Bibliography
Trading Fashion
Business Insider
Bloomberg
Twitter - SniperInMahwah

More Related Content

What's hot

DPDK: Multi Architecture High Performance Packet Processing
DPDK: Multi Architecture High Performance Packet ProcessingDPDK: Multi Architecture High Performance Packet Processing
DPDK: Multi Architecture High Performance Packet ProcessingMichelle Holley
 
Jagan Teki - U-boot from scratch
Jagan Teki - U-boot from scratchJagan Teki - U-boot from scratch
Jagan Teki - U-boot from scratchlinuxlab_conf
 
DPDK in Containers Hands-on Lab
DPDK in Containers Hands-on LabDPDK in Containers Hands-on Lab
DPDK in Containers Hands-on LabMichelle Holley
 
malloc & vmalloc in Linux
malloc & vmalloc in Linuxmalloc & vmalloc in Linux
malloc & vmalloc in LinuxAdrian Huang
 
Kernel Recipes 2019 - XDP closer integration with network stack
Kernel Recipes 2019 -  XDP closer integration with network stackKernel Recipes 2019 -  XDP closer integration with network stack
Kernel Recipes 2019 - XDP closer integration with network stackAnne Nicolas
 
Linux BPF Superpowers
Linux BPF SuperpowersLinux BPF Superpowers
Linux BPF SuperpowersBrendan Gregg
 
from Binary to Binary: How Qemu Works
from Binary to Binary: How Qemu Worksfrom Binary to Binary: How Qemu Works
from Binary to Binary: How Qemu WorksZhen Wei
 
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 ArchitectureScyllaDB
 
The Linux Block Layer - Built for Fast Storage
The Linux Block Layer - Built for Fast StorageThe Linux Block Layer - Built for Fast Storage
The Linux Block Layer - Built for Fast StorageKernel TLV
 
Open vSwitch - Stateful Connection Tracking & Stateful NAT
Open vSwitch - Stateful Connection Tracking & Stateful NATOpen vSwitch - Stateful Connection Tracking & Stateful NAT
Open vSwitch - Stateful Connection Tracking & Stateful NATThomas Graf
 
Boost UDP Transaction Performance
Boost UDP Transaction PerformanceBoost UDP Transaction Performance
Boost UDP Transaction PerformanceLF Events
 
Understanding DPDK algorithmics
Understanding DPDK algorithmicsUnderstanding DPDK algorithmics
Understanding DPDK algorithmicsDenys Haryachyy
 
ACPI Debugging from Linux Kernel
ACPI Debugging from Linux KernelACPI Debugging from Linux Kernel
ACPI Debugging from Linux KernelSUSE Labs Taipei
 
Poll mode driver integration into dpdk
Poll mode driver integration into dpdkPoll mode driver integration into dpdk
Poll mode driver integration into dpdkVipin Varghese
 
Linux Kernel vs DPDK: HTTP Performance Showdown
Linux Kernel vs DPDK: HTTP Performance ShowdownLinux Kernel vs DPDK: HTTP Performance Showdown
Linux Kernel vs DPDK: HTTP Performance ShowdownScyllaDB
 
Introduction to eBPF
Introduction to eBPFIntroduction to eBPF
Introduction to eBPFRogerColl2
 
Linux Kernel MMC Storage driver Overview
Linux Kernel MMC Storage driver OverviewLinux Kernel MMC Storage driver Overview
Linux Kernel MMC Storage driver OverviewRajKumar Rampelli
 
U boot porting guide for SoC
U boot porting guide for SoCU boot porting guide for SoC
U boot porting guide for SoCMacpaul Lin
 

What's hot (20)

DPDK: Multi Architecture High Performance Packet Processing
DPDK: Multi Architecture High Performance Packet ProcessingDPDK: Multi Architecture High Performance Packet Processing
DPDK: Multi Architecture High Performance Packet Processing
 
Jagan Teki - U-boot from scratch
Jagan Teki - U-boot from scratchJagan Teki - U-boot from scratch
Jagan Teki - U-boot from scratch
 
Hacking QNX
Hacking QNXHacking QNX
Hacking QNX
 
DPDK in Containers Hands-on Lab
DPDK in Containers Hands-on LabDPDK in Containers Hands-on Lab
DPDK in Containers Hands-on Lab
 
malloc & vmalloc in Linux
malloc & vmalloc in Linuxmalloc & vmalloc in Linux
malloc & vmalloc in Linux
 
Kernel Recipes 2019 - XDP closer integration with network stack
Kernel Recipes 2019 -  XDP closer integration with network stackKernel Recipes 2019 -  XDP closer integration with network stack
Kernel Recipes 2019 - XDP closer integration with network stack
 
Linux BPF Superpowers
Linux BPF SuperpowersLinux BPF Superpowers
Linux BPF Superpowers
 
from Binary to Binary: How Qemu Works
from Binary to Binary: How Qemu Worksfrom Binary to Binary: How Qemu Works
from Binary to Binary: How Qemu Works
 
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
 
The Linux Block Layer - Built for Fast Storage
The Linux Block Layer - Built for Fast StorageThe Linux Block Layer - Built for Fast Storage
The Linux Block Layer - Built for Fast Storage
 
NMAP
NMAPNMAP
NMAP
 
Open vSwitch - Stateful Connection Tracking & Stateful NAT
Open vSwitch - Stateful Connection Tracking & Stateful NATOpen vSwitch - Stateful Connection Tracking & Stateful NAT
Open vSwitch - Stateful Connection Tracking & Stateful NAT
 
Boost UDP Transaction Performance
Boost UDP Transaction PerformanceBoost UDP Transaction Performance
Boost UDP Transaction Performance
 
Understanding DPDK algorithmics
Understanding DPDK algorithmicsUnderstanding DPDK algorithmics
Understanding DPDK algorithmics
 
ACPI Debugging from Linux Kernel
ACPI Debugging from Linux KernelACPI Debugging from Linux Kernel
ACPI Debugging from Linux Kernel
 
Poll mode driver integration into dpdk
Poll mode driver integration into dpdkPoll mode driver integration into dpdk
Poll mode driver integration into dpdk
 
Linux Kernel vs DPDK: HTTP Performance Showdown
Linux Kernel vs DPDK: HTTP Performance ShowdownLinux Kernel vs DPDK: HTTP Performance Showdown
Linux Kernel vs DPDK: HTTP Performance Showdown
 
Introduction to eBPF
Introduction to eBPFIntroduction to eBPF
Introduction to eBPF
 
Linux Kernel MMC Storage driver Overview
Linux Kernel MMC Storage driver OverviewLinux Kernel MMC Storage driver Overview
Linux Kernel MMC Storage driver Overview
 
U boot porting guide for SoC
U boot porting guide for SoCU boot porting guide for SoC
U boot porting guide for SoC
 

Similar to Linux rt in financial markets

Introduction to embedded System.pptx
Introduction to embedded System.pptxIntroduction to embedded System.pptx
Introduction to embedded System.pptxPratik Gohel
 
04 Mcu Day Stellaris 8 12b Editado
04   Mcu Day   Stellaris 8 12b   Editado04   Mcu Day   Stellaris 8 12b   Editado
04 Mcu Day Stellaris 8 12b EditadoTexas Instruments
 
Automating the Hunt for Non-Obvious Sources of Latency Spreads
Automating the Hunt for Non-Obvious Sources of Latency SpreadsAutomating the Hunt for Non-Obvious Sources of Latency Spreads
Automating the Hunt for Non-Obvious Sources of Latency SpreadsScyllaDB
 
Connection Machine
Connection MachineConnection Machine
Connection Machinebutest
 
Industrial Pioneers Days - Machine Learning
Industrial Pioneers Days - Machine LearningIndustrial Pioneers Days - Machine Learning
Industrial Pioneers Days - Machine LearningVEDLIoT Project
 
An Innovative NVM technology for Sub-0.25um SOC Applications
An Innovative NVM technology for Sub-0.25um SOC ApplicationsAn Innovative NVM technology for Sub-0.25um SOC Applications
An Innovative NVM technology for Sub-0.25um SOC ApplicationsAsia Pacific Cloud Apps Alliance
 
Semiconductor overview
Semiconductor overviewSemiconductor overview
Semiconductor overviewNabil Chouba
 
IS 139 Lecture 1 - 2015
IS 139 Lecture 1 - 2015IS 139 Lecture 1 - 2015
IS 139 Lecture 1 - 2015Aron Kondoro
 
Piccolo F2806x Microcontrollers
Piccolo F2806x MicrocontrollersPiccolo F2806x Microcontrollers
Piccolo F2806x MicrocontrollersPremier Farnell
 
Microsoft Hello World IoT 2017 - Embedded Systems Design - Build vs Buy
Microsoft Hello World IoT 2017 - Embedded Systems Design - Build vs BuyMicrosoft Hello World IoT 2017 - Embedded Systems Design - Build vs Buy
Microsoft Hello World IoT 2017 - Embedded Systems Design - Build vs BuyFernando Luiz Cola
 
An Entire Concept of Embedded systems
An Entire Concept of Embedded systems An Entire Concept of Embedded systems
An Entire Concept of Embedded systems Prabhakar Captain
 
An entire concept of embedded systems entire ppt
An entire concept of embedded systems entire pptAn entire concept of embedded systems entire ppt
An entire concept of embedded systems entire pptPrabhakar Captain
 
AVR_Course_Day4 introduction to microcontroller
AVR_Course_Day4 introduction to microcontrollerAVR_Course_Day4 introduction to microcontroller
AVR_Course_Day4 introduction to microcontrollerMohamed Ali
 
Embedded Systems Overview
Embedded Systems OverviewEmbedded Systems Overview
Embedded Systems OverviewSameer Rapate
 
How to Select Hardware for Internet of Things Systems?
How to Select Hardware for Internet of Things Systems?How to Select Hardware for Internet of Things Systems?
How to Select Hardware for Internet of Things Systems?Hannes Tschofenig
 
E3100 introduction to computer
E3100 introduction to computerE3100 introduction to computer
E3100 introduction to computerDhom Nawhki
 

Similar to Linux rt in financial markets (20)

Introduction to embedded System.pptx
Introduction to embedded System.pptxIntroduction to embedded System.pptx
Introduction to embedded System.pptx
 
Exascale Capabl
Exascale CapablExascale Capabl
Exascale Capabl
 
04 Mcu Day Stellaris 8 12b Editado
04   Mcu Day   Stellaris 8 12b   Editado04   Mcu Day   Stellaris 8 12b   Editado
04 Mcu Day Stellaris 8 12b Editado
 
Micro processor
Micro processorMicro processor
Micro processor
 
Automating the Hunt for Non-Obvious Sources of Latency Spreads
Automating the Hunt for Non-Obvious Sources of Latency SpreadsAutomating the Hunt for Non-Obvious Sources of Latency Spreads
Automating the Hunt for Non-Obvious Sources of Latency Spreads
 
Micro controller & Micro processor
Micro controller & Micro processorMicro controller & Micro processor
Micro controller & Micro processor
 
Connection Machine
Connection MachineConnection Machine
Connection Machine
 
Industrial Pioneers Days - Machine Learning
Industrial Pioneers Days - Machine LearningIndustrial Pioneers Days - Machine Learning
Industrial Pioneers Days - Machine Learning
 
An Innovative NVM technology for Sub-0.25um SOC Applications
An Innovative NVM technology for Sub-0.25um SOC ApplicationsAn Innovative NVM technology for Sub-0.25um SOC Applications
An Innovative NVM technology for Sub-0.25um SOC Applications
 
Semiconductor overview
Semiconductor overviewSemiconductor overview
Semiconductor overview
 
IS 139 Lecture 1 - 2015
IS 139 Lecture 1 - 2015IS 139 Lecture 1 - 2015
IS 139 Lecture 1 - 2015
 
Piccolo F2806x Microcontrollers
Piccolo F2806x MicrocontrollersPiccolo F2806x Microcontrollers
Piccolo F2806x Microcontrollers
 
Microsoft Hello World IoT 2017 - Embedded Systems Design - Build vs Buy
Microsoft Hello World IoT 2017 - Embedded Systems Design - Build vs BuyMicrosoft Hello World IoT 2017 - Embedded Systems Design - Build vs Buy
Microsoft Hello World IoT 2017 - Embedded Systems Design - Build vs Buy
 
An Entire Concept of Embedded systems
An Entire Concept of Embedded systems An Entire Concept of Embedded systems
An Entire Concept of Embedded systems
 
An entire concept of embedded systems entire ppt
An entire concept of embedded systems entire pptAn entire concept of embedded systems entire ppt
An entire concept of embedded systems entire ppt
 
AVR_Course_Day4 introduction to microcontroller
AVR_Course_Day4 introduction to microcontrollerAVR_Course_Day4 introduction to microcontroller
AVR_Course_Day4 introduction to microcontroller
 
Embedded Systems Overview
Embedded Systems OverviewEmbedded Systems Overview
Embedded Systems Overview
 
How to Select Hardware for Internet of Things Systems?
How to Select Hardware for Internet of Things Systems?How to Select Hardware for Internet of Things Systems?
How to Select Hardware for Internet of Things Systems?
 
Intro720T5.pptx
Intro720T5.pptxIntro720T5.pptx
Intro720T5.pptx
 
E3100 introduction to computer
E3100 introduction to computerE3100 introduction to computer
E3100 introduction to computer
 

Recently uploaded

Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
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 2024Rafal Los
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
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 organizationRadu Cotescu
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 

Recently uploaded (20)

Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
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
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
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
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 

Linux rt in financial markets

  • 1. Linux-RT in Financial Markets Adrien Mahieux Performance Engineer Orness gh: github.com/Saruspete tw: @Saruspete em: adrien.mahieux@gmail.com
  • 2. BOFH - $(uname -a) Adrien Mahieux Orness Performance Engineer aka Microsecond hunter How I’m seen from: - HW Vendor: Client with funny cases, that may want this new feature - Kernel Dev: Client with weird requests that breaks his model - App Dev: The one that refuses “quick deployment” in prod (“No-as-a-Service”) - End-Users: Why is my Linux desktop not working?!
  • 3. Agenda - What’s the Finance about ? - Why would Finance actors need RealTime ? - Real-time Challenges - Monitoring and benchmarking - Linus Torvalds: Controlling a laser with Linux is crazy, but everyone in this room is crazy in his own way. So if you want to use Linux to control an industrial welding laser, I have no problem with your using PREEMPT_RT. - Finance: Hold my beer
  • 5. Financial Markets 101 - Place where to exchange goods, currencies, insurances… - Can trade any type of product: - Physical: commodities, currencies, goods… - Virtual: stock, index, insurance, futures, options.. - Rule 34: As long as there’s a need & a supplier, you can trade it - Need to have a Trading License - The market takes a fee for every transaction executed - For an identical price, First arrived, first served - You can see the Order Book (qties + price), but not “who”
  • 6. Why would you trade - Commodities (Fast-Food, beverage store, industrial...) - Need to buy every day physical goods (commodities) for your business to run - Need a delivery date and check product quality - Want to have a cover over steel in case of import tariff - Investor (individual or corporate) - Stocks kept long-time (years...) - Plays in the tendencies of the market (people reactions) - May want an insurance in case of product fluctuations
  • 7. Stock Market: from paper to electronic Palais Brogniart 1973 Paris Stock Exchange
  • 8. Stock Market: from paper to electronic Palais Brogniart 1997 Paris Stock Exchange
  • 9. Stock Market: from paper to electronic Palais Brogniart 2016 Paris Stock Exchange Paris Stock Exchange is at Basildon, UK
  • 10. Stock Market: from paper to electronic Any Stock Exchange: - Matching Engine - Access Gateway - Recorders
  • 11. An history of technical optimizations - Hire the fastest runner between “trading floor” (pit) to “trading offices” - Went out of job with Telex & Tickers operated by secretaries - 1983: Thomas Peterffy created the first touch-screen tablet: direct market access - With reduced latencies, stock minimal price went from 25cts to 1cts. - CoLocation: host your servers in the market’s DC. - From Optical Fiber to Microwaves Stock Market: from paper to electronic
  • 12. Automation - New strategies created Legal: taking advantage of technology - Arbitrage : Play on different prices for the same product on different markets - Market Making: Provide securities available elsewhere - Front Running: Using faster infrastructure to buy first what others wants Illegal : manipulating market / Generate fake events - Quote Stuffing: send lots of quotes to slow down other people - Quote Stuffing(2): Place big sell orders (not 1st limit) to fake market pressure - Wash Trade: Cross-trade: buy your own orders to generate fake volume - Smoking: propose an interesting price, but cancel it immediately
  • 13. HFT / High Frequency Trading
  • 14. What is a “High Frequency” ? Many definitions, no official one Catch-All term for “Automated” or “Algorithmic Trading” Current status: 80% of all trades made by bots The problem: Bots reacts to events (really, any event…) ⇒ Risk of “Flash Crash” (amplification loop between bots)
  • 15. Front Running Use of a technical advantage to vampirise traders wanting to make a deal Brad Katsuyama wanted to buy 100,000 AMD shares: - 2006: Placed its order, got its 100,000 shares. - 2007: Placed its order, got 80,000 shares - 2008: Placed its order, got 70,000 shares - 2009: Placed its order, got 45,000 shares Maybe more people want to buy AMD at the same time?
  • 16. Front Running There’s about 13 stocks exchanges in US Split 100K order in 4 * 25K Brad latencies were 2ms from first (BATS) to last (NYSE)
  • 17. Front Running Front-Runner with optimized infra is 0.5ms FR cancel their Sell order on the different markets FR buy shares ahead of Brad and sell them back at a higher price (+1 cts)
  • 18. Why would Finance need RealTime ?
  • 19. Front Running - Protect against it Don’t send all orders at the same time: slow down Delay sending based on the time needed to reach them Closest locations will be sent after farther ones. Goal: they all touch their target market at the same time
  • 20. Regulations for Market Members MIFID II requires Timestamp orders accuracy of 100µs Everyone wanting to acquire stocks must go through a “Market Member” (usually a Broker or a Bank) which has extensive regulations and risk analysis. Market rules requires actors “to place an order with willingness to be executed” Need accurate statistics for strategy backtest
  • 21. Exchanges need fairness A Stock Exchange is also a regulated entity. Should ensure “Fairness for all” actors (not yet enforced) - Co-Location hosting - Same length of cable / Optical Fiber: 1m = 5ns - Distributed Gateways to handle workload
  • 23. x86 - What could go wrong ? Tend to be Throughput optimized rather than Latency optimized Interrupts: SMI, LOC, IPI, NMI Frequency: Turbo Boost makes real freq vary greatly Assembly: Transcribed to µops Out Of Order Execution: need memory barriers Compiler Optimization: Some neat tricks depending on options NUMA: control placement of CPU, memory and cache snoop
  • 24. x86 - CPU Isolation to reduce jitter Goal: dedicate cores for specific processing and don’t disturb them ever. Most frequent combination: - IRQ Isolation: Move IRQs away from processing cores - isolcpus= Change the default affinity of all userland process - nohz_full= Don’t fire the scheduler interruption (thanks Frederic) - rcu_nocbs= & rcu_nocb_poll Move away kthreads for RCU mechanism - intel_idle.max_cstate=1 disable CPU c-states - idle=poll when really angry - noibrs noibpb nopti nospectre_v2 nospectre_v1 l1tf=off nospec_store_bypass_disable no_stf_barrier mds=off mitigations=off
  • 25. x86 - Application optimization Application also has its share of work: - No memory allocation in the critical path - Cache isolation to avoid noisy neighbor (Intel CMT-CAT) - Keep cache hot for critical path with fake events - Network Polling by application (spinning 100% CPU) - Memory locking to avoid swapping (mlock* sysctls in mm/mlock.c) - Hardware Timestamping when available
  • 26. x86 - Hardware modifications Core placement & Pinning is hard : ACPI Table, Firmware update, Model changes...
  • 27. Time Synchronisation Needed for legal records, traceability and monitoring NTP: sub-ms, very network dependant (from client to local server) - Relies on server clock source (Often TSC) PTP: sub µs, close to client thanks to boundary clocks: - Smart switchs can offset their propagated values - SmartNICs of final servers have an embedded oscillator WhiteRabbit: sub ns, implemented by CERN and Eurex (among others)
  • 28. Heavy network pps load Awful kind of network workload: - Packets < 256 bytes - Spike only lasts a few milliseconds - No cache miss allowed - 10 Gbps at Pkt Size 1500 ~ 800.000 pps - 10 Gbps at Pkt Size 128 ~ 10.000.000 pps Better to just bypass the Kernel (DPDK, Onload, VMA)
  • 29. Optical Fiber is slow : Go Microwave ! Optical Fiber: - ⅔ of speed of light (wire is not empty and beam bounces) - not straight : has to follow ground - Compact and secure channel Microwave: - Full speed of light in vacuum - Direct line of sight (only need repeaters for earth curvature) - But small packet size: 64 (raw sockets) - Subject to weather, Marine Traffic and Solar flares
  • 30. Optical Fiber is slow : Go Microwave ! Houtem tower in Belgium: Auction started at 255K€ sold for 5M€ Direct line of sight from Houtem to England
  • 31. Time requirements IEX : Speed bump to protect from Front Runners Best tech is no tech A very long Optical Fiber adds 350µs latency
  • 33. Monitoring - Netdata github.com/netdata/netdata - 1s granularity - Standalone - Integrated alerting - Lowest overhead monitoring - 1000’s of metrics per second - Self-explained configuration - No conf needed to use
  • 34. Profiling & Measurements Measurement will have an impact many TSC Flags: rdtscp, constant_tsc, nonstop_tsc, tsc_known_freq, tsc_adjust CPU Perf Counters readable through MSR (Intel PCM: github.com/opcm/pcm)
  • 35. Traces when it goes bad ftrace ring buffer on production + crash plugin (thanks Steven) Had multiple issues involving NFS, RCU, RT_Mutex… Most of the time, it was an application issue with 3 factors: - Spinning - Realtime (FF) Scheduling - Bad affinity
  • 36. Network - FPGA to the rescue The best code is the one not run FPGA are perfect for Latency optimized workloads ⇒ High end FPGA are expensive Still needs monitoring software on the host ⇒ Relies on communication channels and drivers
  • 37. Network - Wire 2 Wire Metamako Layer 1 Switch Fast active tap: 4ns
  • 38. Profiling and Dev Tools Opengrok - https://github.com/opengrok/opengrok Fast code browser with indexing and ctags support Compiler Explorer - https://godbolt.org Show compiled ASM and matching source lines Agner Tables - https://www.agner.org/optimize/instruction_tables.pdf List of x86 instruction latencies per CPU (Intel, AMD, Via) QuickBench - http://quick-bench.com
  • 40. The Best benchmark... Is still to test in production !
  • 42. Trading - Market Operations Michael Lewis - Flash Boys - ISBN: 978-0393244663 Alexandre Laumonier “4” (ISBN: 978-2930601106) & “5|6” (ISBN: 978-2930601106) The Wall Street Code - youtube.com/watch?v=kFQJNeQDDHA Flash Crash - youtube.com/watch?v=aq1Ln1UCoEU Les Nouveaux Loups de Wall Street - youtube.com/watch?v=0KNwcJgKMbo
  • 43. Trading - Technical reads www.algo-logic.com/sites/default/files/Algo_Logic_How_To_Build_An_Exchange.pdf Timing White Rabbit at Eurex: https://www.eurexchange.com/exchange-en/resources/initiatives/technical- changes/high-precision-time-white-rabbit-pilot Meanderful - meanderful.blogspot.com/ Sniper In Mahwah - sniperinmahwah.wordpress.com/ Microwave KMZ: https://sniperinmahwah.wordpress.com/2015/04/15/hft-in-my-backyard-the-map/ NYSE vs IEX https://www.businessinsider.fr/us/iex-vs-nyse-on-speed-bump-2017-3 Eurex Connection Gateways details: https://www.eurexchange.com/exchange- en/resources/initiatives/technical-changes/connection-gateways
  • 44. Trading - Official Business Websites IEX about NYSE FIX GW: https://iextrading.com/about/press/op-ed/ Cboe (BATS/CHIX) markets.cboe.com/europe/equities/market_share/index/cboe
  • 46. Bonus: Finance is always trending
  • 47. Trading Fashion - High Heels First of all, you have to stand out from the crowd. That’s why you see all those Technicolor jackets. A lot of guys wore shoes with three-inch soles so they’d look taller. There was a guy in the Loop who made his living resoling shoes for traders.

Editor's Notes

  1. There is also the “Dark Pool” where you can’t see the full order book, only current price
  2. Commodities: Starbucks needs coffee Farmer : can buy insurances for days of sun
  3. People around the basket do the deals
  4. 1983 is CAC40 = Cotation Assistée en Continu
  5. Paris Stock exchange is not in paris anymore
  6. It’s in basildon.. In a datacenter… heavily guarded
  7. Markets were always about optimisation. Or “how to be the first to see an opportunity” Colocation: from 9k to 23k (basildon)
  8. Arbitrage: all to first, nothing to the others Some are very costly
  9. Ask: is it good or bad ? Legal or Illegal ? Bad ? Ok What’s HFT ?
  10. 2010 flash crash: Navinder Singh Sarao did smoking. Vwap = prix pondéré par le volume
  11. Blink of an eye = 300ms
  12. Legal, but not fair.
  13. From a business point of view
  14. LSE: 500 worldwide members (reglementation ECB / AMF / Trading rulebook euronext)
  15. Thanks Frederic Weisbecker
  16. We’re using bare-metal servers, with direct connection and very very few
  17. Core placement. On Linux, core distribution depends on ACPI Tables
  18. EUREX uses White Rabbit
  19. When 1 stock moves, many orders moves at the same time Maybe steven will have ideas with ENAPI
  20. HFT In My Backyard 2 : https://sniperinmahwah.wordpress.com/2014/09/25/hft-in-my-backyard-ii/
  21. How would you implement this speed bumb ?