SlideShare a Scribd company logo
1 of 20
Download to read offline
0.5mln packets per second with Erlang
Revelations from a real-world project based on Erlang on Xen
ErLounge/SF
June 6, 2014
Maxim Kharchenko
CTO, Cloudozer LLP
mk@cloudozer.com
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
!
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)
!
The public build service is available
Go to erlangonxen.org
4
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
!
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
6
LINC-Switch is an OpenFlow software switch implemented in ErlangLINC-Switch is an OpenFlow software switch implemented in Erlang
For more details go to http://FlowForwarding.org
Raw network interfaces in Erlang
* LING adds raw network interfaces:
* 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
7
Port	
  =	
  net_vif:open(“eth1”,	
  []),
port_command(Port,	
  <<1,2,3>>),
receive
{Port,{data,Frame}}	
  -­‐>
...
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
8
Processing delay and low-level NIC stats
!
LING can measure a processing delay for a packet:
! 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:
! 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
9
IXIA confirms 460kpps peak rate
!
1GbE hw NICs/128 byte packets
!
IXIA packet generator/analyzer
10
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
!
Q&A
12
Arguments are registers
!
Many arguments do not make a function any slower
!
Do not reshuffle arguments:
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);
...	
  
%%	
  SLOW
animal(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 the performance-critical sections to
see 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};
!
Heap is a list of chunks
!
'new heap' is close to its head, 'old heap' - to its tail
!
A GC run takes 10μs on average
!
GC may run 1000s times per second
15
Garbage collection is key to speed
HTOPproc_t
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
16
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 10-100x slower
!
Use two variables for a counter?
foo(C1,	
  16#ffffff,	
  ...)	
  →
	
   foo(C1+1,	
  0,	
  ...);
foo(C1,	
  C2,	
  ...)	
  -­‐>
	
   foo(C1,	
  C2+1,	
  ...);
...
!
Erlang on Xen 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
Questions?
??? ??

More Related Content

What's hot

SignalFx: Making Cassandra Perform as a Time Series Database
SignalFx: Making Cassandra Perform as a Time Series DatabaseSignalFx: Making Cassandra Perform as a Time Series Database
SignalFx: Making Cassandra Perform as a Time Series DatabaseDataStax Academy
 
Tuning TCP and NGINX on EC2
Tuning TCP and NGINX on EC2Tuning TCP and NGINX on EC2
Tuning TCP and NGINX on EC2Chartbeat
 
Rapid Application Design in Financial Services
Rapid Application Design in Financial ServicesRapid Application Design in Financial Services
Rapid Application Design in Financial ServicesAerospike
 
Performance Profiling in Rust
Performance Profiling in RustPerformance Profiling in Rust
Performance Profiling in RustInfluxData
 
Using eBPF to Measure the k8s Cluster Health
Using eBPF to Measure the k8s Cluster HealthUsing eBPF to Measure the k8s Cluster Health
Using eBPF to Measure the k8s Cluster HealthScyllaDB
 
Apache Flink Training: DataStream API Part 1 Basic
 Apache Flink Training: DataStream API Part 1 Basic Apache Flink Training: DataStream API Part 1 Basic
Apache Flink Training: DataStream API Part 1 BasicFlink Forward
 
January 2015 HUG: Apache Flink: Fast and reliable large-scale data processing
January 2015 HUG: Apache Flink:  Fast and reliable large-scale data processingJanuary 2015 HUG: Apache Flink:  Fast and reliable large-scale data processing
January 2015 HUG: Apache Flink: Fast and reliable large-scale data processingYahoo Developer Network
 
Profiling with Devel::NYTProf
Profiling with Devel::NYTProfProfiling with Devel::NYTProf
Profiling with Devel::NYTProfbobcatfish
 
Top 10 Perl Performance Tips
Top 10 Perl Performance TipsTop 10 Perl Performance Tips
Top 10 Perl Performance TipsPerrin Harkins
 
Apache Flink Stream Processing
Apache Flink Stream ProcessingApache Flink Stream Processing
Apache Flink Stream ProcessingSuneel Marthi
 
CNIT 127 Ch 5: Introduction to heap overflows
CNIT 127 Ch 5: Introduction to heap overflowsCNIT 127 Ch 5: Introduction to heap overflows
CNIT 127 Ch 5: Introduction to heap overflowsSam Bowne
 
Flink history, roadmap and vision
Flink history, roadmap and visionFlink history, roadmap and vision
Flink history, roadmap and visionStephan Ewen
 
Getting Ready to Move to InfluxDB 2.0 | Tim Hall | InfluxData
Getting Ready to Move to InfluxDB 2.0 | Tim Hall | InfluxData Getting Ready to Move to InfluxDB 2.0 | Tim Hall | InfluxData
Getting Ready to Move to InfluxDB 2.0 | Tim Hall | InfluxData InfluxData
 
[231] the simplicity of cluster apps with circuit
[231] the simplicity of cluster apps with circuit[231] the simplicity of cluster apps with circuit
[231] the simplicity of cluster apps with circuitNAVER D2
 
How the OOM Killer Deleted My Namespace
How the OOM Killer Deleted My NamespaceHow the OOM Killer Deleted My Namespace
How the OOM Killer Deleted My NamespaceLaurent Bernaille
 
(WEB401) Optimizing Your Web Server on AWS | AWS re:Invent 2014
(WEB401) Optimizing Your Web Server on AWS | AWS re:Invent 2014(WEB401) Optimizing Your Web Server on AWS | AWS re:Invent 2014
(WEB401) Optimizing Your Web Server on AWS | AWS re:Invent 2014Amazon Web Services
 
K. Tzoumas & S. Ewen – Flink Forward Keynote
K. Tzoumas & S. Ewen – Flink Forward KeynoteK. Tzoumas & S. Ewen – Flink Forward Keynote
K. Tzoumas & S. Ewen – Flink Forward KeynoteFlink Forward
 
Realtime Statistics based on Apache Storm and RocketMQ
Realtime Statistics based on Apache Storm and RocketMQRealtime Statistics based on Apache Storm and RocketMQ
Realtime Statistics based on Apache Storm and RocketMQXin Wang
 
How to Introduce Telemetry Streaming (gNMI) in Your Network with SNMP with Te...
How to Introduce Telemetry Streaming (gNMI) in Your Network with SNMP with Te...How to Introduce Telemetry Streaming (gNMI) in Your Network with SNMP with Te...
How to Introduce Telemetry Streaming (gNMI) in Your Network with SNMP with Te...InfluxData
 

What's hot (20)

SignalFx: Making Cassandra Perform as a Time Series Database
SignalFx: Making Cassandra Perform as a Time Series DatabaseSignalFx: Making Cassandra Perform as a Time Series Database
SignalFx: Making Cassandra Perform as a Time Series Database
 
Tuning TCP and NGINX on EC2
Tuning TCP and NGINX on EC2Tuning TCP and NGINX on EC2
Tuning TCP and NGINX on EC2
 
Rapid Application Design in Financial Services
Rapid Application Design in Financial ServicesRapid Application Design in Financial Services
Rapid Application Design in Financial Services
 
Performance Profiling in Rust
Performance Profiling in RustPerformance Profiling in Rust
Performance Profiling in Rust
 
Using eBPF to Measure the k8s Cluster Health
Using eBPF to Measure the k8s Cluster HealthUsing eBPF to Measure the k8s Cluster Health
Using eBPF to Measure the k8s Cluster Health
 
Apache Flink Training: DataStream API Part 1 Basic
 Apache Flink Training: DataStream API Part 1 Basic Apache Flink Training: DataStream API Part 1 Basic
Apache Flink Training: DataStream API Part 1 Basic
 
January 2015 HUG: Apache Flink: Fast and reliable large-scale data processing
January 2015 HUG: Apache Flink:  Fast and reliable large-scale data processingJanuary 2015 HUG: Apache Flink:  Fast and reliable large-scale data processing
January 2015 HUG: Apache Flink: Fast and reliable large-scale data processing
 
Profiling with Devel::NYTProf
Profiling with Devel::NYTProfProfiling with Devel::NYTProf
Profiling with Devel::NYTProf
 
Top 10 Perl Performance Tips
Top 10 Perl Performance TipsTop 10 Perl Performance Tips
Top 10 Perl Performance Tips
 
Performance
PerformancePerformance
Performance
 
Apache Flink Stream Processing
Apache Flink Stream ProcessingApache Flink Stream Processing
Apache Flink Stream Processing
 
CNIT 127 Ch 5: Introduction to heap overflows
CNIT 127 Ch 5: Introduction to heap overflowsCNIT 127 Ch 5: Introduction to heap overflows
CNIT 127 Ch 5: Introduction to heap overflows
 
Flink history, roadmap and vision
Flink history, roadmap and visionFlink history, roadmap and vision
Flink history, roadmap and vision
 
Getting Ready to Move to InfluxDB 2.0 | Tim Hall | InfluxData
Getting Ready to Move to InfluxDB 2.0 | Tim Hall | InfluxData Getting Ready to Move to InfluxDB 2.0 | Tim Hall | InfluxData
Getting Ready to Move to InfluxDB 2.0 | Tim Hall | InfluxData
 
[231] the simplicity of cluster apps with circuit
[231] the simplicity of cluster apps with circuit[231] the simplicity of cluster apps with circuit
[231] the simplicity of cluster apps with circuit
 
How the OOM Killer Deleted My Namespace
How the OOM Killer Deleted My NamespaceHow the OOM Killer Deleted My Namespace
How the OOM Killer Deleted My Namespace
 
(WEB401) Optimizing Your Web Server on AWS | AWS re:Invent 2014
(WEB401) Optimizing Your Web Server on AWS | AWS re:Invent 2014(WEB401) Optimizing Your Web Server on AWS | AWS re:Invent 2014
(WEB401) Optimizing Your Web Server on AWS | AWS re:Invent 2014
 
K. Tzoumas & S. Ewen – Flink Forward Keynote
K. Tzoumas & S. Ewen – Flink Forward KeynoteK. Tzoumas & S. Ewen – Flink Forward Keynote
K. Tzoumas & S. Ewen – Flink Forward Keynote
 
Realtime Statistics based on Apache Storm and RocketMQ
Realtime Statistics based on Apache Storm and RocketMQRealtime Statistics based on Apache Storm and RocketMQ
Realtime Statistics based on Apache Storm and RocketMQ
 
How to Introduce Telemetry Streaming (gNMI) in Your Network with SNMP with Te...
How to Introduce Telemetry Streaming (gNMI) in Your Network with SNMP with Te...How to Introduce Telemetry Streaming (gNMI) in Your Network with SNMP with Te...
How to Introduce Telemetry Streaming (gNMI) in Your Network with SNMP with Te...
 

Similar to 0.5mln packets per second with Erlang

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
 
Osdc 2011 michael_neale
Osdc 2011 michael_nealeOsdc 2011 michael_neale
Osdc 2011 michael_nealeMichael Neale
 
Keynote joearmstrong
Keynote joearmstrongKeynote joearmstrong
Keynote joearmstrongSentifi
 
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
 
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
 
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
 
Kiwipycon2011 async-with-gevent-redis
Kiwipycon2011 async-with-gevent-redisKiwipycon2011 async-with-gevent-redis
Kiwipycon2011 async-with-gevent-redisalexdong
 
Erlang
ErlangErlang
ErlangESUG
 
introduction to data processing using Hadoop and Pig
introduction to data processing using Hadoop and Pigintroduction to data processing using Hadoop and Pig
introduction to data processing using Hadoop and PigRicardo Varela
 
[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
 
Ngrep commands
Ngrep commandsNgrep commands
Ngrep commandsRishu Seth
 
Erlang Lightning Talk
Erlang Lightning TalkErlang Lightning Talk
Erlang Lightning TalkGiltTech
 
Scaling an ELK stack at bol.com
Scaling an ELK stack at bol.comScaling an ELK stack at bol.com
Scaling an ELK stack at bol.comRenzo Tomà
 
Snabbflow: A Scalable IPFIX exporter
Snabbflow: A Scalable IPFIX exporterSnabbflow: A Scalable IPFIX exporter
Snabbflow: A Scalable IPFIX exporterIgalia
 
Network Stack in Userspace (NUSE)
Network Stack in Userspace (NUSE)Network Stack in Userspace (NUSE)
Network Stack in Userspace (NUSE)Hajime Tazaki
 
Tuning Solr and its Pipeline for Logs: Presented by Rafał Kuć & Radu Gheorghe...
Tuning Solr and its Pipeline for Logs: Presented by Rafał Kuć & Radu Gheorghe...Tuning Solr and its Pipeline for Logs: Presented by Rafał Kuć & Radu Gheorghe...
Tuning Solr and its Pipeline for Logs: Presented by Rafał Kuć & Radu Gheorghe...Lucidworks
 

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

Linux Network Stack
Linux Network StackLinux Network Stack
Linux Network Stack
 
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...
 
Osdc 2011 michael_neale
Osdc 2011 michael_nealeOsdc 2011 michael_neale
Osdc 2011 michael_neale
 
Keynote joearmstrong
Keynote joearmstrongKeynote joearmstrong
Keynote joearmstrong
 
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
 
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)
 
Ceph Day Shanghai - Ceph Performance Tools
Ceph Day Shanghai - Ceph Performance Tools Ceph Day Shanghai - Ceph Performance Tools
Ceph Day Shanghai - Ceph Performance Tools
 
Kiwipycon2011 async-with-gevent-redis
Kiwipycon2011 async-with-gevent-redisKiwipycon2011 async-with-gevent-redis
Kiwipycon2011 async-with-gevent-redis
 
Erlang
ErlangErlang
Erlang
 
Multicore
MulticoreMulticore
Multicore
 
introduction to data processing using Hadoop and Pig
introduction to data processing using Hadoop and Pigintroduction to data processing using Hadoop and Pig
introduction to data processing using Hadoop and Pig
 
[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
 
Ngrep commands
Ngrep commandsNgrep commands
Ngrep commands
 
Erlang Lightning Talk
Erlang Lightning TalkErlang Lightning Talk
Erlang Lightning Talk
 
Scaling an ELK stack at bol.com
Scaling an ELK stack at bol.comScaling an ELK stack at bol.com
Scaling an ELK stack at bol.com
 
UNIX Basics and Cluster Computing
UNIX Basics and Cluster ComputingUNIX Basics and Cluster Computing
UNIX Basics and Cluster Computing
 
Snabbflow: A Scalable IPFIX exporter
Snabbflow: A Scalable IPFIX exporterSnabbflow: A Scalable IPFIX exporter
Snabbflow: A Scalable IPFIX exporter
 
Network Stack in Userspace (NUSE)
Network Stack in Userspace (NUSE)Network Stack in Userspace (NUSE)
Network Stack in Userspace (NUSE)
 
Tuning Solr & Pipeline for Logs
Tuning Solr & Pipeline for LogsTuning Solr & Pipeline for Logs
Tuning Solr & Pipeline for Logs
 
Tuning Solr and its Pipeline for Logs: Presented by Rafał Kuć & Radu Gheorghe...
Tuning Solr and its Pipeline for Logs: Presented by Rafał Kuć & Radu Gheorghe...Tuning Solr and its Pipeline for Logs: Presented by Rafał Kuć & Radu Gheorghe...
Tuning Solr and its Pipeline for Logs: Presented by Rafał Kuć & Radu Gheorghe...
 

Recently uploaded

The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 

Recently uploaded (20)

The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 

0.5mln packets per second with Erlang

  • 1. 0.5mln packets per second with Erlang Revelations from a real-world project based on Erlang on Xen ErLounge/SF June 6, 2014 Maxim Kharchenko CTO, Cloudozer LLP mk@cloudozer.com
  • 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 ! Q&A
  • 3. 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) ! The public build service is available 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 ! 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 6 LINC-Switch is an OpenFlow software switch implemented in ErlangLINC-Switch is an OpenFlow software switch implemented in Erlang For more details go to http://FlowForwarding.org
  • 7. Raw network interfaces in Erlang * LING adds raw network interfaces: * 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 7 Port  =  net_vif:open(“eth1”,  []), port_command(Port,  <<1,2,3>>), receive {Port,{data,Frame}}  -­‐> ... 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 8
  • 9. Processing delay and low-level NIC stats ! LING can measure a processing delay for a packet: ! 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: ! 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 9
  • 10. IXIA confirms 460kpps peak rate ! 1GbE hw NICs/128 byte packets ! IXIA packet generator/analyzer 10
  • 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 ! Q&A
  • 12. 12 Arguments are registers ! Many arguments do not make a function any slower ! Do not reshuffle arguments: 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); ...   %%  SLOW animal(Cat,  Dog,  Horse,  Pig,  Cow,  State)  -­‐>   feed(Goat,  Cat,  Dog,  Horse,  Pig,  Cow,  State); ...
  • 13. 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. 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 the performance-critical sections to see 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. ! Heap is a list of chunks ! 'new heap' is close to its head, 'old heap' - to its tail ! A GC run takes 10μs on average ! GC may run 1000s times per second 15 Garbage collection is key to speed HTOPproc_t
  • 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 16
  • 17. 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. 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. 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 10-100x slower ! Use two variables for a counter? foo(C1,  16#ffffff,  ...)  →   foo(C1+1,  0,  ...); foo(C1,  C2,  ...)  -­‐>   foo(C1,  C2+1,  ...); ... ! Erlang on Xen 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)