SlideShare a Scribd company logo
1 of 22
0.5 mln packets per second with Erlang 
Nov 22, 2014 
Maxim Kharchenko 
CTO/Cloudozer LLP
The road map 
Erlang on Xen intro 
LINCX project overview 
Speed-related notes 
– Arguments are registers 
– ETS tables are (mostly) ok 
– Do not overuse records 
– GC is key to speed 
– gen_server vs. barebone process 
– NIFS: more pain than gain 
– Fast counters 
– Static compiler? 
Q&A
Erlang on Xen a.k.a. LING 
A new Erlang platform that runs without OS 
Conceived in 2009 
Highly-compatible with Erlang/OTP 
Built from scratch, not a “port” 
Optimized for low startup latency 
Open sourced in 2014 (github.com/cloudozer/ling) 
Local and remote builds 
Go to erlangonxen.org
Zerg demo: zerg.erlangonxen.org
The road map 
Erlang on Xen intro 
LINCX project overview 
Speed-related notes 
– Arguments are registers 
– ETS tables are (mostly) ok 
– Do not overuse records 
– GC is key to speed 
– gen_server vs. barebone process 
– NIFS: more pain than gain 
– Fast counters 
– Static compiler? 
Q&A
LINCX: project overview 
Started in December, 2013 
Initial scope = porting LINC-Switch to LING 
High degree of compatibility demonstrated for LING 
Extended scope = fix LINC-Switch fast path 
Beta version of LINCX open sourced on March 3, 2014 
LINCX runs 100x faster than the old code 
LINCX repository: 
github.com/FlowForwarding/lincx
Raw network interfaces in Erlang 
LING adds raw network interfaces: 
Port = net_vif:open(“eth1”, []), 
port_command(Port, <<1,2,3>>), 
receive 
{Port,{data,Frame}} ‐> 
... 
Raw interface receives whole Ethernet frames 
LINCX uses standard gen_tcp for the control connection and net_vif - for 
data ports 
Raw interfaces support mailbox_limit option - packets get dropped if the 
mailbox of the receiving process overflows: 
Port = net_vif:open(“eth1”, [{mailbox_limit,16384}]), 
...
Testbed configuration 
* Test traffic goes between vm1 and vm2 
* LINCX runs as a separate Xen domain 
* Virtual interfaces are bridged in Dom0
IXIA confirms 460kpps peak rate 
1GbE hw NICs/128 byte packets 
IXIA packet generator/analyzer
Processing delay and low-level stats 
LING can measure a processing delay for a packet: 
1> ling:experimental(processing_delay, []). 
Processing delay statistics: 
Packets: 2000 Delay: 1.342us +‐ 0.143 (95%) 
LING can collect low-level stats for a network interface: 
1> ling:experimental(llstat, 1). %% stop/display 
Duration: 4868.6ms 
RX: interrupts: 69170 (0 kicks 0.0%) (freq 14207.4/s period 70.4us) 
RX: reqs per int: 0/0.0/0 
RX: tx buf freed per int: 0/8.5/234 
TX: outputs: 1479707 (112263 kicks 7.6) (freq 303928.8/s period 3.3us) 
TX: tx buf freed per int: 0/0.6/113 
TX: rates: 303.9kpps 3622.66Mbps avg pkt size 1489.9B 
TX: drops: 12392 (freq 2545.3/s period 392.9us) 
TX: drop rates: 2.5kpps 30.26Mbps avg pkt size 1486.0B
The road map 
Erlang on Xen intro 
LINCX project overview 
Speed-related notes 
– Arguments are registers 
– ETS tables are (mostly) ok 
– Do not overuse records 
– GC is key to speed 
– gen_server vs. barebone process 
– NIFS: more pain than gain 
– Fast counters 
– Static compiler? 
Q&A
Arguments are registers 
animal(batman = Cat, Dog, Horse, Pig, Cow, State) ‐> 
feed(Cat, Dog, Horse, Pig, Cow, State); 
animal(Cat, deli = Dog, Horse, Pig, Cow, State) ‐> 
pet(Cat, Dog, Horse, Pig, Cow, State); 
... 
Many arguments do not make a function any slower 
But do not reshuffle arguments: 
%% SLOW 
animal(batman = Cat, Dog, Horse, Pig, Cow, State) ‐> 
feed(Goat, Cat, Dog, Horse, Pig, Cow, State); 
...
ETS tables are (mostly) ok 
A small ETS table lookup = 10x function activations 
Do not use ets:tab2list() inside tight loops 
Treat ETS as a database; not a pool of global variables 
1-2 ETS lookups on the fast path are ok 
Beware that ets:lookup(), etc create a copy of the data on the heap of 
the caller, similarly to message passing
Do not overuse records 
selelement() creates a copy of the tuple 
State#state{foo=Foo1,bar=Bar1,baz=Baz1} creates 3(?) copies of the 
tuple 
Use tuples explicitly in performance-critical sections to control the heap 
footprint of the code: 
%% from 9p.erl 
mixer({rauth,_,_}, {tauth,_,Afid,_,_}, _) ‐> {write_auth,AFid}; 
mixer({rauth,_,_}, {tauth,_,Afid,_,_,_}, _) ‐> {write_auth,AFid}; 
mixer({rwrite,_,_}, _, initial) ‐> start_attaching; 
mixer({rerror,_,_}, _, initial) ‐> auth_failed; 
mixer({rlerror,_,_}, _, initial) ‐> auth_failed; 
mixer({rattach,_,Qid}, {tattach,_,Fid,_,_,Aname,_}, initial) ‐> 
{attach_more,Fid,AName,qid_type(Qid)}; 
mixer({rclunk,_}, {tclunk,_,Fid}, initial) ‐> {forget,Fid};
Garbage collection is key to speed 
Heap is a list of chunks 
'new heap' is close to its head, 'old heap' - to its tail 
proc_t 
A GC run takes 10μs on average 
GC may run 1000s times per second 
HTO 
P 
...
How to tackle GC-related issues 
(Priority 1) Call erlang:garbage_collect() at strategic points 
(Priority 2) For the fastest code avoid GC completely – restart the fast 
process regularly: 
spawn(F, [{suppress_gc,true}]), %% LING‐only 
(Priority 3) Use fullsweep_after option
gen_server vs barebone process 
Message passing using gen_server:call() is 2x slower than Pid ! Msg 
For speedy code prefer barebone processes to gen_servers 
Design Principles are about high availability, not high performance
NIFs: more pain than gain 
A new principle of Erlang development: do not use NIFs 
For a small performance boost, NIFs undermine key properties of 
Erlang: reliability and soft-realtime guarantees 
Most of the time Erlang code can be made as fast as C 
Most of performance problems of Erlang are traceable to NIFs, or 
external C libraries, which are similar 
Erlang on Xen does not have NIFs and we do not plan to add them
Fast counters 
32-bit or 64-bit unsigned integer counters with overflow - trivial in C, not 
easy in Erlang 
FIXNUMs are signed 29-bit integers, BIGNUMs consume heap and are 
10-100x slower 
Use two variables for a counter? 
foo(C1, 16#ffffff, ...) -> foo(C1+1, 0, ...); 
foo(C1, C2, ...) ‐> foo(C1, C2+1, ...); 
... 
LING has a new experimental feature – fast counters: 
erlang:new_counter(Bits) ‐> Ref 
erlang:increment_counter(Ref, Incr) 
erlang:read_counter(Ref) 
erlang:release_counter(Ref)
Future: static compiler for Erlang 
Scalars and algebraic types 
Structural types only – no nominal types 
Target compiler efficiency not static type checking 
A middle ground between: 
“Type is a first class citizen” (Haskell) 
“A single type is good enough” (Python, Erlang)
Future: static compiler for Erlang - 2 
Challenges: 
Pattern matching compilation 
Type inference for recursive types 
y = {(unit | y), x, (unit | y)} 
y = nil | {x, y} 
Work started in 2013 
Currently the compiler is at the proof-of-concept stage
Questions 
? 
e-mail: maxim.kharchenko@gmail.com

More Related Content

What's hot

Erlang For Five Nines
Erlang For Five NinesErlang For Five Nines
Erlang For Five NinesBarcamp Cork
 
CNIT 127 Ch 2: Stack overflows on Linux
CNIT 127 Ch 2: Stack overflows on LinuxCNIT 127 Ch 2: Stack overflows on Linux
CNIT 127 Ch 2: Stack overflows on LinuxSam Bowne
 
CNIT 127: Ch 2: Stack overflows on Linux
CNIT 127: Ch 2: Stack overflows on LinuxCNIT 127: Ch 2: Stack overflows on Linux
CNIT 127: Ch 2: Stack overflows on LinuxSam Bowne
 
127 Ch 2: Stack overflows on Linux
127 Ch 2: Stack overflows on Linux127 Ch 2: Stack overflows on Linux
127 Ch 2: Stack overflows on LinuxSam Bowne
 
CNIT 127: Ch 8: Windows overflows (Part 2)
CNIT 127: Ch 8: Windows overflows (Part 2)CNIT 127: Ch 8: Windows overflows (Part 2)
CNIT 127: Ch 8: Windows overflows (Part 2)Sam Bowne
 
Performance optimization 101 - Erlang Factory SF 2014
Performance optimization 101 - Erlang Factory SF 2014Performance optimization 101 - Erlang Factory SF 2014
Performance optimization 101 - Erlang Factory SF 2014lpgauth
 
Streaming Data Flow with Apache Flink @ Paris Flink Meetup 2015
Streaming Data Flow with Apache Flink @ Paris Flink Meetup 2015Streaming Data Flow with Apache Flink @ Paris Flink Meetup 2015
Streaming Data Flow with Apache Flink @ Paris Flink Meetup 2015Till Rohrmann
 
CNIT 127 Ch 1: Before you Begin
CNIT 127 Ch 1: Before you BeginCNIT 127 Ch 1: Before you Begin
CNIT 127 Ch 1: Before you BeginSam Bowne
 
Apache Flink internals
Apache Flink internalsApache Flink internals
Apache Flink internalsKostas Tzoumas
 
CNIT 127 Ch 4: Introduction to format string bugs (rev. 2-9-17)
CNIT 127 Ch 4: Introduction to format string bugs (rev. 2-9-17)CNIT 127 Ch 4: Introduction to format string bugs (rev. 2-9-17)
CNIT 127 Ch 4: Introduction to format string bugs (rev. 2-9-17)Sam Bowne
 
CNIT 127: Ch 4: Introduction to format string bugs
CNIT 127: Ch 4: Introduction to format string bugsCNIT 127: Ch 4: Introduction to format string bugs
CNIT 127: Ch 4: Introduction to format string bugsSam Bowne
 
CNIT 127 Ch 2: Stack overflows on Linux
CNIT 127 Ch 2: Stack overflows on LinuxCNIT 127 Ch 2: Stack overflows on Linux
CNIT 127 Ch 2: Stack overflows on LinuxSam Bowne
 
Parallel program design
Parallel program designParallel program design
Parallel program designZongYing Lyu
 
Click-Through Example for Flink’s KafkaConsumer Checkpointing
Click-Through Example for Flink’s KafkaConsumer CheckpointingClick-Through Example for Flink’s KafkaConsumer Checkpointing
Click-Through Example for Flink’s KafkaConsumer CheckpointingRobert Metzger
 
Apache Flink @ NYC Flink Meetup
Apache Flink @ NYC Flink MeetupApache Flink @ NYC Flink Meetup
Apache Flink @ NYC Flink MeetupStephan Ewen
 
CNIT 127: Ch 3: Shellcode
CNIT 127: Ch 3: ShellcodeCNIT 127: Ch 3: Shellcode
CNIT 127: Ch 3: ShellcodeSam Bowne
 
(1) cpp introducing the_cpp_programming_language
(1) cpp introducing the_cpp_programming_language(1) cpp introducing the_cpp_programming_language
(1) cpp introducing the_cpp_programming_languageNico Ludwig
 
CNIT 127 Lecture 7: Intro to 64-Bit Assembler (not in book)
CNIT 127 Lecture 7: Intro to 64-Bit Assembler (not in book)CNIT 127 Lecture 7: Intro to 64-Bit Assembler (not in book)
CNIT 127 Lecture 7: Intro to 64-Bit Assembler (not in book)Sam Bowne
 

What's hot (20)

Erlang For Five Nines
Erlang For Five NinesErlang For Five Nines
Erlang For Five Nines
 
CNIT 127 Ch 2: Stack overflows on Linux
CNIT 127 Ch 2: Stack overflows on LinuxCNIT 127 Ch 2: Stack overflows on Linux
CNIT 127 Ch 2: Stack overflows on Linux
 
CNIT 127: Ch 2: Stack overflows on Linux
CNIT 127: Ch 2: Stack overflows on LinuxCNIT 127: Ch 2: Stack overflows on Linux
CNIT 127: Ch 2: Stack overflows on Linux
 
127 Ch 2: Stack overflows on Linux
127 Ch 2: Stack overflows on Linux127 Ch 2: Stack overflows on Linux
127 Ch 2: Stack overflows on Linux
 
CNIT 127: Ch 8: Windows overflows (Part 2)
CNIT 127: Ch 8: Windows overflows (Part 2)CNIT 127: Ch 8: Windows overflows (Part 2)
CNIT 127: Ch 8: Windows overflows (Part 2)
 
Return Oriented Programming
Return Oriented ProgrammingReturn Oriented Programming
Return Oriented Programming
 
Performance optimization 101 - Erlang Factory SF 2014
Performance optimization 101 - Erlang Factory SF 2014Performance optimization 101 - Erlang Factory SF 2014
Performance optimization 101 - Erlang Factory SF 2014
 
Streaming Data Flow with Apache Flink @ Paris Flink Meetup 2015
Streaming Data Flow with Apache Flink @ Paris Flink Meetup 2015Streaming Data Flow with Apache Flink @ Paris Flink Meetup 2015
Streaming Data Flow with Apache Flink @ Paris Flink Meetup 2015
 
Erlang OTP
Erlang OTPErlang OTP
Erlang OTP
 
CNIT 127 Ch 1: Before you Begin
CNIT 127 Ch 1: Before you BeginCNIT 127 Ch 1: Before you Begin
CNIT 127 Ch 1: Before you Begin
 
Apache Flink internals
Apache Flink internalsApache Flink internals
Apache Flink internals
 
CNIT 127 Ch 4: Introduction to format string bugs (rev. 2-9-17)
CNIT 127 Ch 4: Introduction to format string bugs (rev. 2-9-17)CNIT 127 Ch 4: Introduction to format string bugs (rev. 2-9-17)
CNIT 127 Ch 4: Introduction to format string bugs (rev. 2-9-17)
 
CNIT 127: Ch 4: Introduction to format string bugs
CNIT 127: Ch 4: Introduction to format string bugsCNIT 127: Ch 4: Introduction to format string bugs
CNIT 127: Ch 4: Introduction to format string bugs
 
CNIT 127 Ch 2: Stack overflows on Linux
CNIT 127 Ch 2: Stack overflows on LinuxCNIT 127 Ch 2: Stack overflows on Linux
CNIT 127 Ch 2: Stack overflows on Linux
 
Parallel program design
Parallel program designParallel program design
Parallel program design
 
Click-Through Example for Flink’s KafkaConsumer Checkpointing
Click-Through Example for Flink’s KafkaConsumer CheckpointingClick-Through Example for Flink’s KafkaConsumer Checkpointing
Click-Through Example for Flink’s KafkaConsumer Checkpointing
 
Apache Flink @ NYC Flink Meetup
Apache Flink @ NYC Flink MeetupApache Flink @ NYC Flink Meetup
Apache Flink @ NYC Flink Meetup
 
CNIT 127: Ch 3: Shellcode
CNIT 127: Ch 3: ShellcodeCNIT 127: Ch 3: Shellcode
CNIT 127: Ch 3: Shellcode
 
(1) cpp introducing the_cpp_programming_language
(1) cpp introducing the_cpp_programming_language(1) cpp introducing the_cpp_programming_language
(1) cpp introducing the_cpp_programming_language
 
CNIT 127 Lecture 7: Intro to 64-Bit Assembler (not in book)
CNIT 127 Lecture 7: Intro to 64-Bit Assembler (not in book)CNIT 127 Lecture 7: Intro to 64-Bit Assembler (not in book)
CNIT 127 Lecture 7: Intro to 64-Bit Assembler (not in book)
 

Similar to 0.5mln packets per second with Erlang

Network Programming: Data Plane Development Kit (DPDK)
Network Programming: Data Plane Development Kit (DPDK)Network Programming: Data Plane Development Kit (DPDK)
Network Programming: Data Plane Development Kit (DPDK)Andriy Berestovskyy
 
Sioux Hot-or-Not: Functional programming: unlocking the real power of multi-c...
Sioux Hot-or-Not: Functional programming: unlocking the real power of multi-c...Sioux Hot-or-Not: Functional programming: unlocking the real power of multi-c...
Sioux Hot-or-Not: Functional programming: unlocking the real power of multi-c...siouxhotornot
 
Erlang Message Passing Concurrency, For The Win
Erlang  Message  Passing  Concurrency,  For  The  WinErlang  Message  Passing  Concurrency,  For  The  Win
Erlang Message Passing Concurrency, For The Winl xf
 
Keynote joearmstrong
Keynote joearmstrongKeynote joearmstrong
Keynote joearmstrongSentifi
 
Pragmatic Optimization in Modern Programming - Demystifying the Compiler
Pragmatic Optimization in Modern Programming - Demystifying the CompilerPragmatic Optimization in Modern Programming - Demystifying the Compiler
Pragmatic Optimization in Modern Programming - Demystifying the CompilerMarina Kolpakova
 
Handling Large State on BEAM
Handling Large State on BEAMHandling Large State on BEAM
Handling Large State on BEAMYoshihiro TANAKA
 
[Webinar Slides] Programming the Network Dataplane in P4
[Webinar Slides] Programming the Network Dataplane in P4[Webinar Slides] Programming the Network Dataplane in P4
[Webinar Slides] Programming the Network Dataplane in P4Open Networking Summits
 
Understand and Harness the Capabilities of Intel® Xeon Phi™ Processors
Understand and Harness the Capabilities of Intel® Xeon Phi™ ProcessorsUnderstand and Harness the Capabilities of Intel® Xeon Phi™ Processors
Understand and Harness the Capabilities of Intel® Xeon Phi™ ProcessorsIntel® Software
 
Porting a Streaming Pipeline from Scala to Rust
Porting a Streaming Pipeline from Scala to RustPorting a Streaming Pipeline from Scala to Rust
Porting a Streaming Pipeline from Scala to RustEvan Chan
 
cs241-f06-final-overview
cs241-f06-final-overviewcs241-f06-final-overview
cs241-f06-final-overviewColin Bell
 
Fletcher Framework for Programming FPGA
Fletcher Framework for Programming FPGAFletcher Framework for Programming FPGA
Fletcher Framework for Programming FPGAGanesan Narayanasamy
 
Quantifying Container Runtime Performance: OSCON 2017 Open Container Day
Quantifying Container Runtime Performance: OSCON 2017 Open Container DayQuantifying Container Runtime Performance: OSCON 2017 Open Container Day
Quantifying Container Runtime Performance: OSCON 2017 Open Container DayPhil Estes
 
Ceph Day Shanghai - Ceph Performance Tools
Ceph Day Shanghai - Ceph Performance Tools Ceph Day Shanghai - Ceph Performance Tools
Ceph Day Shanghai - Ceph Performance Tools Ceph Community
 
Ngrep commands
Ngrep commandsNgrep commands
Ngrep commandsRishu Seth
 
Kernel Recipes 2014 - NDIV: a low overhead network traffic diverter
Kernel Recipes 2014 - NDIV: a low overhead network traffic diverterKernel Recipes 2014 - NDIV: a low overhead network traffic diverter
Kernel Recipes 2014 - NDIV: a low overhead network traffic diverterAnne Nicolas
 
Five major tips to maximize performance on a 200+ SQL HBase/Phoenix cluster
Five major tips to maximize performance on a 200+ SQL HBase/Phoenix clusterFive major tips to maximize performance on a 200+ SQL HBase/Phoenix cluster
Five major tips to maximize performance on a 200+ SQL HBase/Phoenix clustermas4share
 

Similar to 0.5mln packets per second with Erlang (20)

Network Programming: Data Plane Development Kit (DPDK)
Network Programming: Data Plane Development Kit (DPDK)Network Programming: Data Plane Development Kit (DPDK)
Network Programming: Data Plane Development Kit (DPDK)
 
Sioux Hot-or-Not: Functional programming: unlocking the real power of multi-c...
Sioux Hot-or-Not: Functional programming: unlocking the real power of multi-c...Sioux Hot-or-Not: Functional programming: unlocking the real power of multi-c...
Sioux Hot-or-Not: Functional programming: unlocking the real power of multi-c...
 
Erlang Message Passing Concurrency, For The Win
Erlang  Message  Passing  Concurrency,  For  The  WinErlang  Message  Passing  Concurrency,  For  The  Win
Erlang Message Passing Concurrency, For The Win
 
Keynote joearmstrong
Keynote joearmstrongKeynote joearmstrong
Keynote joearmstrong
 
Pragmatic Optimization in Modern Programming - Demystifying the Compiler
Pragmatic Optimization in Modern Programming - Demystifying the CompilerPragmatic Optimization in Modern Programming - Demystifying the Compiler
Pragmatic Optimization in Modern Programming - Demystifying the Compiler
 
Handling Large State on BEAM
Handling Large State on BEAMHandling Large State on BEAM
Handling Large State on BEAM
 
Protocol Independence
Protocol IndependenceProtocol Independence
Protocol Independence
 
[Webinar Slides] Programming the Network Dataplane in P4
[Webinar Slides] Programming the Network Dataplane in P4[Webinar Slides] Programming the Network Dataplane in P4
[Webinar Slides] Programming the Network Dataplane in P4
 
Understand and Harness the Capabilities of Intel® Xeon Phi™ Processors
Understand and Harness the Capabilities of Intel® Xeon Phi™ ProcessorsUnderstand and Harness the Capabilities of Intel® Xeon Phi™ Processors
Understand and Harness the Capabilities of Intel® Xeon Phi™ Processors
 
Linux Network Stack
Linux Network StackLinux Network Stack
Linux Network Stack
 
Porting a Streaming Pipeline from Scala to Rust
Porting a Streaming Pipeline from Scala to RustPorting a Streaming Pipeline from Scala to Rust
Porting a Streaming Pipeline from Scala to Rust
 
Multicore
MulticoreMulticore
Multicore
 
cs241-f06-final-overview
cs241-f06-final-overviewcs241-f06-final-overview
cs241-f06-final-overview
 
ISA.pptx
ISA.pptxISA.pptx
ISA.pptx
 
Fletcher Framework for Programming FPGA
Fletcher Framework for Programming FPGAFletcher Framework for Programming FPGA
Fletcher Framework for Programming FPGA
 
Quantifying Container Runtime Performance: OSCON 2017 Open Container Day
Quantifying Container Runtime Performance: OSCON 2017 Open Container DayQuantifying Container Runtime Performance: OSCON 2017 Open Container Day
Quantifying Container Runtime Performance: OSCON 2017 Open Container Day
 
Ceph Day Shanghai - Ceph Performance Tools
Ceph Day Shanghai - Ceph Performance Tools Ceph Day Shanghai - Ceph Performance Tools
Ceph Day Shanghai - Ceph Performance Tools
 
Ngrep commands
Ngrep commandsNgrep commands
Ngrep commands
 
Kernel Recipes 2014 - NDIV: a low overhead network traffic diverter
Kernel Recipes 2014 - NDIV: a low overhead network traffic diverterKernel Recipes 2014 - NDIV: a low overhead network traffic diverter
Kernel Recipes 2014 - NDIV: a low overhead network traffic diverter
 
Five major tips to maximize performance on a 200+ SQL HBase/Phoenix cluster
Five major tips to maximize performance on a 200+ SQL HBase/Phoenix clusterFive major tips to maximize performance on a 200+ SQL HBase/Phoenix cluster
Five major tips to maximize performance on a 200+ SQL HBase/Phoenix cluster
 

Recently uploaded

React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Matt Ray
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)jennyeacort
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Mater
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Cizo Technology Services
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfLivetecs LLC
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Angel Borroy López
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtimeandrehoraa
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commercemanigoyal112
 

Recently uploaded (20)

React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdf
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
Advantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your BusinessAdvantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your Business
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtime
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commerce
 

0.5mln packets per second with Erlang

  • 1. 0.5 mln packets per second with Erlang Nov 22, 2014 Maxim Kharchenko CTO/Cloudozer LLP
  • 2. The road map Erlang on Xen intro LINCX project overview Speed-related notes – Arguments are registers – ETS tables are (mostly) ok – Do not overuse records – GC is key to speed – gen_server vs. barebone process – NIFS: more pain than gain – Fast counters – Static compiler? Q&A
  • 3. Erlang on Xen a.k.a. LING A new Erlang platform that runs without OS Conceived in 2009 Highly-compatible with Erlang/OTP Built from scratch, not a “port” Optimized for low startup latency Open sourced in 2014 (github.com/cloudozer/ling) Local and remote builds Go to erlangonxen.org
  • 5. The road map Erlang on Xen intro LINCX project overview Speed-related notes – Arguments are registers – ETS tables are (mostly) ok – Do not overuse records – GC is key to speed – gen_server vs. barebone process – NIFS: more pain than gain – Fast counters – Static compiler? Q&A
  • 6. LINCX: project overview Started in December, 2013 Initial scope = porting LINC-Switch to LING High degree of compatibility demonstrated for LING Extended scope = fix LINC-Switch fast path Beta version of LINCX open sourced on March 3, 2014 LINCX runs 100x faster than the old code LINCX repository: github.com/FlowForwarding/lincx
  • 7. Raw network interfaces in Erlang LING adds raw network interfaces: Port = net_vif:open(“eth1”, []), port_command(Port, <<1,2,3>>), receive {Port,{data,Frame}} ‐> ... Raw interface receives whole Ethernet frames LINCX uses standard gen_tcp for the control connection and net_vif - for data ports Raw interfaces support mailbox_limit option - packets get dropped if the mailbox of the receiving process overflows: Port = net_vif:open(“eth1”, [{mailbox_limit,16384}]), ...
  • 8. Testbed configuration * Test traffic goes between vm1 and vm2 * LINCX runs as a separate Xen domain * Virtual interfaces are bridged in Dom0
  • 9. IXIA confirms 460kpps peak rate 1GbE hw NICs/128 byte packets IXIA packet generator/analyzer
  • 10. Processing delay and low-level stats LING can measure a processing delay for a packet: 1> ling:experimental(processing_delay, []). Processing delay statistics: Packets: 2000 Delay: 1.342us +‐ 0.143 (95%) LING can collect low-level stats for a network interface: 1> ling:experimental(llstat, 1). %% stop/display Duration: 4868.6ms RX: interrupts: 69170 (0 kicks 0.0%) (freq 14207.4/s period 70.4us) RX: reqs per int: 0/0.0/0 RX: tx buf freed per int: 0/8.5/234 TX: outputs: 1479707 (112263 kicks 7.6) (freq 303928.8/s period 3.3us) TX: tx buf freed per int: 0/0.6/113 TX: rates: 303.9kpps 3622.66Mbps avg pkt size 1489.9B TX: drops: 12392 (freq 2545.3/s period 392.9us) TX: drop rates: 2.5kpps 30.26Mbps avg pkt size 1486.0B
  • 11. The road map Erlang on Xen intro LINCX project overview Speed-related notes – Arguments are registers – ETS tables are (mostly) ok – Do not overuse records – GC is key to speed – gen_server vs. barebone process – NIFS: more pain than gain – Fast counters – Static compiler? Q&A
  • 12. Arguments are registers animal(batman = Cat, Dog, Horse, Pig, Cow, State) ‐> feed(Cat, Dog, Horse, Pig, Cow, State); animal(Cat, deli = Dog, Horse, Pig, Cow, State) ‐> pet(Cat, Dog, Horse, Pig, Cow, State); ... Many arguments do not make a function any slower But do not reshuffle arguments: %% SLOW animal(batman = Cat, Dog, Horse, Pig, Cow, State) ‐> feed(Goat, Cat, Dog, Horse, Pig, Cow, State); ...
  • 13. ETS tables are (mostly) ok A small ETS table lookup = 10x function activations Do not use ets:tab2list() inside tight loops Treat ETS as a database; not a pool of global variables 1-2 ETS lookups on the fast path are ok Beware that ets:lookup(), etc create a copy of the data on the heap of the caller, similarly to message passing
  • 14. Do not overuse records selelement() creates a copy of the tuple State#state{foo=Foo1,bar=Bar1,baz=Baz1} creates 3(?) copies of the tuple Use tuples explicitly in performance-critical sections to control the heap footprint of the code: %% from 9p.erl mixer({rauth,_,_}, {tauth,_,Afid,_,_}, _) ‐> {write_auth,AFid}; mixer({rauth,_,_}, {tauth,_,Afid,_,_,_}, _) ‐> {write_auth,AFid}; mixer({rwrite,_,_}, _, initial) ‐> start_attaching; mixer({rerror,_,_}, _, initial) ‐> auth_failed; mixer({rlerror,_,_}, _, initial) ‐> auth_failed; mixer({rattach,_,Qid}, {tattach,_,Fid,_,_,Aname,_}, initial) ‐> {attach_more,Fid,AName,qid_type(Qid)}; mixer({rclunk,_}, {tclunk,_,Fid}, initial) ‐> {forget,Fid};
  • 15. Garbage collection is key to speed Heap is a list of chunks 'new heap' is close to its head, 'old heap' - to its tail proc_t A GC run takes 10μs on average GC may run 1000s times per second HTO P ...
  • 16. How to tackle GC-related issues (Priority 1) Call erlang:garbage_collect() at strategic points (Priority 2) For the fastest code avoid GC completely – restart the fast process regularly: spawn(F, [{suppress_gc,true}]), %% LING‐only (Priority 3) Use fullsweep_after option
  • 17. gen_server vs barebone process Message passing using gen_server:call() is 2x slower than Pid ! Msg For speedy code prefer barebone processes to gen_servers Design Principles are about high availability, not high performance
  • 18. NIFs: more pain than gain A new principle of Erlang development: do not use NIFs For a small performance boost, NIFs undermine key properties of Erlang: reliability and soft-realtime guarantees Most of the time Erlang code can be made as fast as C Most of performance problems of Erlang are traceable to NIFs, or external C libraries, which are similar Erlang on Xen does not have NIFs and we do not plan to add them
  • 19. Fast counters 32-bit or 64-bit unsigned integer counters with overflow - trivial in C, not easy in Erlang FIXNUMs are signed 29-bit integers, BIGNUMs consume heap and are 10-100x slower Use two variables for a counter? foo(C1, 16#ffffff, ...) -> foo(C1+1, 0, ...); foo(C1, C2, ...) ‐> foo(C1, C2+1, ...); ... LING has a new experimental feature – fast counters: erlang:new_counter(Bits) ‐> Ref erlang:increment_counter(Ref, Incr) erlang:read_counter(Ref) erlang:release_counter(Ref)
  • 20. Future: static compiler for Erlang Scalars and algebraic types Structural types only – no nominal types Target compiler efficiency not static type checking A middle ground between: “Type is a first class citizen” (Haskell) “A single type is good enough” (Python, Erlang)
  • 21. Future: static compiler for Erlang - 2 Challenges: Pattern matching compilation Type inference for recursive types y = {(unit | y), x, (unit | y)} y = nil | {x, y} Work started in 2013 Currently the compiler is at the proof-of-concept stage
  • 22. Questions ? e-mail: maxim.kharchenko@gmail.com