SlideShare a Scribd company logo
Benchmarking in
Elixir
https://github.com/PragTob
/benchee
Developer: JavaScript, Elixir at Blueberry
Gardener
Traveller
Email: antonin.hackenberg@gmail.com
LinkedIn: https://cz.linkedin.com/in/antoninhackenberg
Github: https://github.com/TondaHack
Antonín Hackenberg
Elixir
● 2012 (José Valim)
● Erlang bytecode
● Erlang
○ Amazon, Yahoo, Facebook, WhatsApp, T-Mobile, Motorola, Ericsson,
World of Warcraft
● Low-latency, Distributed, Fault-tolerant
Elixir
● Amazing Tooling
● Good documentation
● Metaprogramming
● Millions users
● Lonely planet, Pinterest,
Bet365, Cabify
Elixir - use-cases
● Web applications - Pheonix Framework
● Web APIs (JSON and GraphQL) - Absinthe
● Real-time web - Channels
Elixir - use-cases
● Stateful web - OTP
● Distributed systems (Erlang Distribution
Protocol :rpc)
● Internet of things - Nerves project
Benchmarking
What?
Where?
How?
80/20
Benchmarking
Benchmark vs. Profile
Micro vs. Macro
Correctness
Tooling
Let’s Benchmark Tail Call
Optimization
Sum recursion - No Tail Call Optimization
defmodule NoTCO do
def sum_no_tco([]), do: 0
def sum_no_tco([head | tail]) do
head + sum_no_tco(tail)
end
end
Sum function - Without Tail Call
defmodule NoTCO do
def sum_no_tco([]), do: 0
def sum_no_tco([head | tail]) do
head + sum_no_tco(tail)
end
end
NoTCO.sum_no_tco([1, 2, 3, 4])
Sum function - Without Tail Call
defmodule NoTCO do
def sum_no_tco([]), do: 0
def sum_no_tco([head | tail]) do
head + sum_no_tco(tail)
end
end
NoTCO.sum_no_tco([1, 2, 3, 4])
1 + sum_no_tco([2, 3, 4])
Sum function - Without Tail Call
defmodule NoTCO do
def sum_no_tco([]), do: 0
def sum_no_tco([head | tail]) do
head + sum_no_tco(tail)
end
end
NoTCO.sum_no_tco([1, 2, 3, 4])
1 + sum_no_tco([2, 3, 4])
+ 2 + sum_no_tco([3, 4])
Sum function - Without Tail Call
defmodule NoTCO do
def sum_no_tco([]), do: 0
def sum_no_tco([head | tail]) do
head + sum_no_tco(tail)
end
end
NoTCO.sum_no_tco([1, 2, 3, 4])
1 + sum_no_tco([2, 3, 4])
+ 2 + sum_no_tco([3, 4])
+ 3 + sum_no_tco([4])
Sum function - Without Tail Call
defmodule NoTCO do
def sum_no_tco([]), do: 0
def sum_no_tco([head | tail]) do
head + sum_no_tco(tail)
end
end
NoTCO.sum_no_tco([1, 2, 3, 4])
1 + sum_no_tco([2, 3, 4])
+ 2 + sum_no_tco([3, 4])
+ 3 + sum_no_tco([4])
+ 4 + sum_no_tco([])
Sum function - Without Tail Call
defmodule NoTCO do
def sum_no_tco([]), do: 0
def sum_no_tco([head | tail]) do
head + sum_no_tco(tail)
end
end
NoTCO.sum_no_tco([1, 2, 3, 4])
1 + sum_no_tco([2, 3, 4])
+ 2 + sum_no_tco([3, 4])
+ 3 + sum_no_tco([4])
+ 4 + sum_no_tco([])
+ 0
Sum function - Without Tail Call
defmodule NoTCO do
def sum_no_tco([]), do: 0
def sum_no_tco([head | tail]) do
head + sum_no_tco(tail)
end
end
NoTCO.sum_no_tco([1, 2, 3, 4])
1 + sum_no_tco([2, 3, 4])
+ 2 + sum_no_tco([3, 4])
+ 3 + sum_no_tco([4])
+ 4 + 0
Sum function - Without Tail Call
defmodule NoTCO do
def sum_no_tco([]), do: 0
def sum_no_tco([head | tail]) do
head + sum_no_tco(tail)
end
end
NoTCO.sum_no_tco([1, 2, 3, 4])
1 + sum_no_tco([2, 3, 4])
+ 2 + sum_no_tco([3, 4])
+ 3 + 4
Sum function - Without Tail Call
defmodule NoTCO do
def sum_no_tco([]), do: 0
def sum_no_tco([head | tail]) do
head + sum_no_tco(tail)
end
end
NoTCO.sum_no_tco([1, 2, 3, 4])
1 + sum_no_tco([2, 3, 4])
+ 2 + 7
Sum function - Without Tail Call
defmodule NoTCO do
def sum_no_tco([]), do: 0
def sum_no_tco([head | tail]) do
head + sum_no_tco(tail)
end
end
NoTCO.sum_no_tco([1, 2, 3, 4])
1 + 9
Sum function - Without Tail Call
defmodule NoTCO do
def sum_no_tco([]), do: 0
def sum_no_tco([head | tail]) do
head + sum_no_tco(tail)
end
end
NoTCO.sum_no_tco([1, 2, 3, 4])
= 10
Sum function - Tail Call Optimization
defmodule TCO do
def sum([], acc), do: acc
def sum([head | tail], acc) do
sum(tail, head + acc)
end
end
Sum function - Tail Call Optimization
defmodule TCO do
def sum([], acc), do: acc
def sum([head | tail], acc) do
sum(tail, head + acc)
end
end
TCO.sum([1, 2, 3, 4], 0)
Sum function - Tail Call Optimization
defmodule TCO do
def sum([], acc), do: acc
def sum([head | tail], acc) do
sum(tail, head + acc)
end
end
TCO.sum([1, 2, 3, 4], 0)
sum([2, 3, 4], 1)
Sum function - Tail Call Optimization
defmodule TCO do
def sum([], acc), do: acc
def sum([head | tail], acc) do
sum(tail, head + acc)
end
end
TCO.sum([1, 2, 3, 4], 0)
sum([3, 4], 3)
Sum function - Tail Call Optimization
defmodule TCO do
def sum([], acc), do: acc
def sum([head | tail], acc) do
sum(tail, head + acc)
end
end
TCO.sum([1, 2, 3, 4], 0)
sum([4], 6)
Sum function - Tail Call Optimization
defmodule TCO do
def sum([], acc), do: acc
def sum([head | tail], acc) do
sum(tail, head + acc)
end
end
TCO.sum([1, 2, 3, 4], 0)
sum([], 10)
Sum function - Tail Call Optimization
defmodule TCO do
def sum([], acc), do: acc
def sum([head | tail], acc) do
sum(tail, head + acc)
end
end
TCO.sum([1, 2, 3, 4], 0)
10
Difference
defmodule TCO do
def sum([], acc), do: acc
def sum([head | tail], acc) do
sum(tail, head + acc)
end
end
defmodule NoTCO do
def sum_no_tco([]), do: 0
def sum_no_tco([head | tail]) do
head + sum_no_tco(tail)
end
end
Benchmarking
iex(1)> :timer.tc fn -> NoTCO.sum_no_tco(Enum.to_list(1..100_000)) end
{17673, 5000050000}
iex(2)> :timer.tc fn -> TCO.sum(Enum.to_list(1..100_000), 0) end
{10518, 5000050000}
inputs = %{
"1_000 list size" => Enum.to_list(1..1_000),
"100_000 list size" => Enum.to_list(1..1000_000),
"1000_000 list size" => Enum.to_list(1..1000_000),
}
Benchee.run(%{
"Tail Call Optimizitation" => fn(list) -> TCO.sum(list, 0) end,
"No TCO" => fn(list) -> NoTCO.sum_no_tco(list) end,
"Enum sum" => fn(list) -> Enum.sum(list) end
},
time: 10,
memory_time: 2,
inputs: inputs,
formatters: [
Benchee.Formatters.HTML,
Benchee.Formatters.Console
],
formatter_options: [html: [file: "lib/report/tco.html"]]
)
Real example
def parse(file_path, modifiers  %{}, options  %{}, take) do
file_path
|> File.stream!()
|> CsvParser.decode_csv()
|> Stream.take(take)
|> Stream.map(&process_item(&1, options, modifiers))
|> Stream.filter(&filter_items(&1, options["elastic_search_index" ]))
|> Stream.chunk_every(1000)
|> Stream.each(&store_items(&1, options["elastic_search_index" ]))
|> Stream.run()
end
[modifiers, file_path] = PpcbeeElixirBackend.Enhance.download(191)
Benchee.run(
%{
"No Parallelism" => fn ->
PpcbeeElixirBackend.DataParser.parse(file_path, modifiers, %{}, 10_000)
end,
"Parallelism Task.async_stream" => fn ->
PpcbeeElixirBackend.DataParser.parse_async_stream(file_path, modifiers, %{},10_000)
end,
"Parallelism Task.async" => fn ->
PpcbeeElixirBackend.DataParser.parse_async_task(file_path, modifiers, %{}, 10_000)
end,
"Parallelism flow" => fn ->
PpcbeeElixirBackend.DataParser.parse_flow(file_path, modifiers, %{}, 10_000)
end
},
time: 5 * 60,
formatters: [
Benchee.Formatters.HTML,
],
formatter_options: [html: [file: "lib/benchmark/report/parallelism/report.html"]]
)
Ruby vs. Elixir - Tested on one machine
Ruby - previous service after optimization
● 200 / items per seconds
● CPU 100%
● RAM 560 mb
Elixir - before optimization
● 310 (no parallelism), 620 (paralellism)
● CPU 100%, 300%
● RAM 65 mb
Profiling - eprof, ExProf
“The module eprof provides a set of functions for time
profiling of Erlang programs to find out how the
execution time is used. The profiling is done using
the Erlang trace BIFs. Tracing of local function calls
for a specified set of processes is enabled when
profiling is begun, and disabled when profiling is
stopped.”
http://erlang.org/doc/man/eprof.html
...
Benchmarking is not real user!
Thank you :)
Sources
● https://www.issart.com/blog/benchmarking-best-practice-fo
r-code-optimization
● https://pragtob.wordpress.com/2016/06/16/tail-call-optimi
zation-in-elixir-erlang-not-as-efficient-and-important-as
-you-probably-think/
● https://www.youtube.com/watch?v=KSrImdsfjL4
● https://www.amberbit.com/blog/2018/5/15/when-to-use-elixi
r-language/
● https://github.com/parroty/exprof
● https://github.com/PragTob/benchee
● https://www.ppcbee.com/

More Related Content

What's hot

Going Loopy: Adventures in Iteration with Go
Going Loopy: Adventures in Iteration with GoGoing Loopy: Adventures in Iteration with Go
Going Loopy: Adventures in Iteration with Go
Eleanor McHugh
 
Let's golang
Let's golangLet's golang
Let's golang
SuHyun Jeon
 
Basics
BasicsBasics
Hello Go
Hello GoHello Go
Hello Go
Eleanor McHugh
 
Functional Pattern Matching on Python
Functional Pattern Matching on PythonFunctional Pattern Matching on Python
Functional Pattern Matching on PythonDaker Fernandes
 
Go for the would be network programmer
Go for the would be network programmerGo for the would be network programmer
Go for the would be network programmerEleanor McHugh
 
JFugue, Music, and the Future of Java [JavaOne 2016, CON1851]
JFugue, Music, and the Future of Java [JavaOne 2016, CON1851]JFugue, Music, and the Future of Java [JavaOne 2016, CON1851]
JFugue, Music, and the Future of Java [JavaOne 2016, CON1851]
David Koelle
 
The Art, Joy, and Power of Creating Musical Programs (JFugue at SXSW Interact...
The Art, Joy, and Power of Creating Musical Programs (JFugue at SXSW Interact...The Art, Joy, and Power of Creating Musical Programs (JFugue at SXSW Interact...
The Art, Joy, and Power of Creating Musical Programs (JFugue at SXSW Interact...
David Koelle
 
Encrypt all transports
Encrypt all transportsEncrypt all transports
Encrypt all transports
Eleanor McHugh
 
AnyMQ, Hippie, and the real-time web
AnyMQ, Hippie, and the real-time webAnyMQ, Hippie, and the real-time web
AnyMQ, Hippie, and the real-time webclkao
 
P4 2018 io_functions
P4 2018 io_functionsP4 2018 io_functions
P4 2018 io_functions
Prof. Wim Van Criekinge
 
Fewer cables
Fewer cablesFewer cables
Fewer cables
acme
 
Music as data
Music as dataMusic as data
Music as data
John Vlachoyiannis
 
What's New in PHP 5.5
What's New in PHP 5.5What's New in PHP 5.5
What's New in PHP 5.5
Corey Ballou
 
Abusing text/template for data transformation
Abusing text/template for data transformationAbusing text/template for data transformation
Abusing text/template for data transformation
Arnaud Porterie
 
Elixir @ Paris.rb
Elixir @ Paris.rbElixir @ Paris.rb
Elixir @ Paris.rb
Gregoire Lejeune
 
Exploring slides
Exploring slidesExploring slides
Exploring slides
akaptur
 
Python utan-stodhjul-motorsag
Python utan-stodhjul-motorsagPython utan-stodhjul-motorsag
Python utan-stodhjul-motorsagniklal
 
QA Fest 2019. Saar Rachamim. Developing Tools, While Testing
QA Fest 2019. Saar Rachamim. Developing Tools, While TestingQA Fest 2019. Saar Rachamim. Developing Tools, While Testing
QA Fest 2019. Saar Rachamim. Developing Tools, While Testing
QAFest
 
P3 2018 python_regexes
P3 2018 python_regexesP3 2018 python_regexes
P3 2018 python_regexes
Prof. Wim Van Criekinge
 

What's hot (20)

Going Loopy: Adventures in Iteration with Go
Going Loopy: Adventures in Iteration with GoGoing Loopy: Adventures in Iteration with Go
Going Loopy: Adventures in Iteration with Go
 
Let's golang
Let's golangLet's golang
Let's golang
 
Basics
BasicsBasics
Basics
 
Hello Go
Hello GoHello Go
Hello Go
 
Functional Pattern Matching on Python
Functional Pattern Matching on PythonFunctional Pattern Matching on Python
Functional Pattern Matching on Python
 
Go for the would be network programmer
Go for the would be network programmerGo for the would be network programmer
Go for the would be network programmer
 
JFugue, Music, and the Future of Java [JavaOne 2016, CON1851]
JFugue, Music, and the Future of Java [JavaOne 2016, CON1851]JFugue, Music, and the Future of Java [JavaOne 2016, CON1851]
JFugue, Music, and the Future of Java [JavaOne 2016, CON1851]
 
The Art, Joy, and Power of Creating Musical Programs (JFugue at SXSW Interact...
The Art, Joy, and Power of Creating Musical Programs (JFugue at SXSW Interact...The Art, Joy, and Power of Creating Musical Programs (JFugue at SXSW Interact...
The Art, Joy, and Power of Creating Musical Programs (JFugue at SXSW Interact...
 
Encrypt all transports
Encrypt all transportsEncrypt all transports
Encrypt all transports
 
AnyMQ, Hippie, and the real-time web
AnyMQ, Hippie, and the real-time webAnyMQ, Hippie, and the real-time web
AnyMQ, Hippie, and the real-time web
 
P4 2018 io_functions
P4 2018 io_functionsP4 2018 io_functions
P4 2018 io_functions
 
Fewer cables
Fewer cablesFewer cables
Fewer cables
 
Music as data
Music as dataMusic as data
Music as data
 
What's New in PHP 5.5
What's New in PHP 5.5What's New in PHP 5.5
What's New in PHP 5.5
 
Abusing text/template for data transformation
Abusing text/template for data transformationAbusing text/template for data transformation
Abusing text/template for data transformation
 
Elixir @ Paris.rb
Elixir @ Paris.rbElixir @ Paris.rb
Elixir @ Paris.rb
 
Exploring slides
Exploring slidesExploring slides
Exploring slides
 
Python utan-stodhjul-motorsag
Python utan-stodhjul-motorsagPython utan-stodhjul-motorsag
Python utan-stodhjul-motorsag
 
QA Fest 2019. Saar Rachamim. Developing Tools, While Testing
QA Fest 2019. Saar Rachamim. Developing Tools, While TestingQA Fest 2019. Saar Rachamim. Developing Tools, While Testing
QA Fest 2019. Saar Rachamim. Developing Tools, While Testing
 
P3 2018 python_regexes
P3 2018 python_regexesP3 2018 python_regexes
P3 2018 python_regexes
 

Similar to FPBrno 2018-05-22: Benchmarking in elixir

Very basic functional design patterns
Very basic functional design patternsVery basic functional design patterns
Very basic functional design patterns
Tomasz Kowal
 
Re-Design with Elixir/OTP
Re-Design with Elixir/OTPRe-Design with Elixir/OTP
Re-Design with Elixir/OTP
Mustafa TURAN
 
Developer Experience i TypeScript. Najbardziej ikoniczne duo
Developer Experience i TypeScript. Najbardziej ikoniczne duoDeveloper Experience i TypeScript. Najbardziej ikoniczne duo
Developer Experience i TypeScript. Najbardziej ikoniczne duo
The Software House
 
Elixir cheatsheet
Elixir cheatsheetElixir cheatsheet
Elixir cheatsheet
Héla Ben Khalfallah
 
Introducción a Elixir
Introducción a ElixirIntroducción a Elixir
Introducción a Elixir
Svet Ivantchev
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with ClojureDmitry Buzdin
 
Profiling and optimization
Profiling and optimizationProfiling and optimization
Profiling and optimizationg3_nittala
 
pa-pe-pi-po-pure Python Text Processing
pa-pe-pi-po-pure Python Text Processingpa-pe-pi-po-pure Python Text Processing
pa-pe-pi-po-pure Python Text Processing
Rodrigo Senra
 
Add an interactive command line to your C++ application
Add an interactive command line to your C++ applicationAdd an interactive command line to your C++ application
Add an interactive command line to your C++ application
Daniele Pallastrelli
 
3 things you must know to think reactive - Geecon Kraków 2015
3 things you must know to think reactive - Geecon Kraków 20153 things you must know to think reactive - Geecon Kraków 2015
3 things you must know to think reactive - Geecon Kraków 2015
Manuel Bernhardt
 
The Ring programming language version 1.5.4 book - Part 40 of 185
The Ring programming language version 1.5.4 book - Part 40 of 185The Ring programming language version 1.5.4 book - Part 40 of 185
The Ring programming language version 1.5.4 book - Part 40 of 185
Mahmoud Samir Fayed
 
Do snow.rwn
Do snow.rwnDo snow.rwn
Do snow.rwn
ARUN DN
 
Fourier project presentation
Fourier project  presentationFourier project  presentation
Fourier project presentation
志璿 楊
 
Writing Faster Python 3
Writing Faster Python 3Writing Faster Python 3
Writing Faster Python 3
Sebastian Witowski
 
Valerii Vasylkov Erlang. measurements and benefits.
Valerii Vasylkov Erlang. measurements and benefits.Valerii Vasylkov Erlang. measurements and benefits.
Valerii Vasylkov Erlang. measurements and benefits.
Аліна Шепшелей
 
SE2016 Exotic Valerii Vasylkov "Erlang. Measurements and benefits"
SE2016 Exotic Valerii Vasylkov "Erlang. Measurements and benefits"SE2016 Exotic Valerii Vasylkov "Erlang. Measurements and benefits"
SE2016 Exotic Valerii Vasylkov "Erlang. Measurements and benefits"
Inhacking
 
A Few of My Favorite (Python) Things
A Few of My Favorite (Python) ThingsA Few of My Favorite (Python) Things
A Few of My Favorite (Python) Things
Michael Pirnat
 
CS4200 2019 | Lecture 5 | Transformation by Term Rewriting
CS4200 2019 | Lecture 5 | Transformation by Term RewritingCS4200 2019 | Lecture 5 | Transformation by Term Rewriting
CS4200 2019 | Lecture 5 | Transformation by Term Rewriting
Eelco Visser
 
How to tune a query - ODTUG 2012
How to tune a query - ODTUG 2012How to tune a query - ODTUG 2012
How to tune a query - ODTUG 2012
Connor McDonald
 
Elixir & Phoenix - fast, concurrent and explicit
Elixir & Phoenix - fast, concurrent and explicitElixir & Phoenix - fast, concurrent and explicit
Elixir & Phoenix - fast, concurrent and explicit
Tobias Pfeiffer
 

Similar to FPBrno 2018-05-22: Benchmarking in elixir (20)

Very basic functional design patterns
Very basic functional design patternsVery basic functional design patterns
Very basic functional design patterns
 
Re-Design with Elixir/OTP
Re-Design with Elixir/OTPRe-Design with Elixir/OTP
Re-Design with Elixir/OTP
 
Developer Experience i TypeScript. Najbardziej ikoniczne duo
Developer Experience i TypeScript. Najbardziej ikoniczne duoDeveloper Experience i TypeScript. Najbardziej ikoniczne duo
Developer Experience i TypeScript. Najbardziej ikoniczne duo
 
Elixir cheatsheet
Elixir cheatsheetElixir cheatsheet
Elixir cheatsheet
 
Introducción a Elixir
Introducción a ElixirIntroducción a Elixir
Introducción a Elixir
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with Clojure
 
Profiling and optimization
Profiling and optimizationProfiling and optimization
Profiling and optimization
 
pa-pe-pi-po-pure Python Text Processing
pa-pe-pi-po-pure Python Text Processingpa-pe-pi-po-pure Python Text Processing
pa-pe-pi-po-pure Python Text Processing
 
Add an interactive command line to your C++ application
Add an interactive command line to your C++ applicationAdd an interactive command line to your C++ application
Add an interactive command line to your C++ application
 
3 things you must know to think reactive - Geecon Kraków 2015
3 things you must know to think reactive - Geecon Kraków 20153 things you must know to think reactive - Geecon Kraków 2015
3 things you must know to think reactive - Geecon Kraków 2015
 
The Ring programming language version 1.5.4 book - Part 40 of 185
The Ring programming language version 1.5.4 book - Part 40 of 185The Ring programming language version 1.5.4 book - Part 40 of 185
The Ring programming language version 1.5.4 book - Part 40 of 185
 
Do snow.rwn
Do snow.rwnDo snow.rwn
Do snow.rwn
 
Fourier project presentation
Fourier project  presentationFourier project  presentation
Fourier project presentation
 
Writing Faster Python 3
Writing Faster Python 3Writing Faster Python 3
Writing Faster Python 3
 
Valerii Vasylkov Erlang. measurements and benefits.
Valerii Vasylkov Erlang. measurements and benefits.Valerii Vasylkov Erlang. measurements and benefits.
Valerii Vasylkov Erlang. measurements and benefits.
 
SE2016 Exotic Valerii Vasylkov "Erlang. Measurements and benefits"
SE2016 Exotic Valerii Vasylkov "Erlang. Measurements and benefits"SE2016 Exotic Valerii Vasylkov "Erlang. Measurements and benefits"
SE2016 Exotic Valerii Vasylkov "Erlang. Measurements and benefits"
 
A Few of My Favorite (Python) Things
A Few of My Favorite (Python) ThingsA Few of My Favorite (Python) Things
A Few of My Favorite (Python) Things
 
CS4200 2019 | Lecture 5 | Transformation by Term Rewriting
CS4200 2019 | Lecture 5 | Transformation by Term RewritingCS4200 2019 | Lecture 5 | Transformation by Term Rewriting
CS4200 2019 | Lecture 5 | Transformation by Term Rewriting
 
How to tune a query - ODTUG 2012
How to tune a query - ODTUG 2012How to tune a query - ODTUG 2012
How to tune a query - ODTUG 2012
 
Elixir & Phoenix - fast, concurrent and explicit
Elixir & Phoenix - fast, concurrent and explicitElixir & Phoenix - fast, concurrent and explicit
Elixir & Phoenix - fast, concurrent and explicit
 

Recently uploaded

Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
Globus
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
Google
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Globus
 
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdfEnhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Jay Das
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
Paco van Beckhoven
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
Globus
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
WSO2
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
Max Andersen
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Mind IT Systems
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
Cyanic lab
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
IES VE
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Globus
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Shahin Sheidaei
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
Globus
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
Ortus Solutions, Corp
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
Globus
 

Recently uploaded (20)

Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
 
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdfEnhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
 

FPBrno 2018-05-22: Benchmarking in elixir

  • 2. Developer: JavaScript, Elixir at Blueberry Gardener Traveller Email: antonin.hackenberg@gmail.com LinkedIn: https://cz.linkedin.com/in/antoninhackenberg Github: https://github.com/TondaHack Antonín Hackenberg
  • 3. Elixir ● 2012 (José Valim) ● Erlang bytecode ● Erlang ○ Amazon, Yahoo, Facebook, WhatsApp, T-Mobile, Motorola, Ericsson, World of Warcraft ● Low-latency, Distributed, Fault-tolerant
  • 4. Elixir ● Amazing Tooling ● Good documentation ● Metaprogramming ● Millions users ● Lonely planet, Pinterest, Bet365, Cabify
  • 5. Elixir - use-cases ● Web applications - Pheonix Framework ● Web APIs (JSON and GraphQL) - Absinthe ● Real-time web - Channels
  • 6. Elixir - use-cases ● Stateful web - OTP ● Distributed systems (Erlang Distribution Protocol :rpc) ● Internet of things - Nerves project
  • 8. Benchmarking Benchmark vs. Profile Micro vs. Macro Correctness Tooling
  • 9. Let’s Benchmark Tail Call Optimization
  • 10. Sum recursion - No Tail Call Optimization defmodule NoTCO do def sum_no_tco([]), do: 0 def sum_no_tco([head | tail]) do head + sum_no_tco(tail) end end
  • 11. Sum function - Without Tail Call defmodule NoTCO do def sum_no_tco([]), do: 0 def sum_no_tco([head | tail]) do head + sum_no_tco(tail) end end NoTCO.sum_no_tco([1, 2, 3, 4])
  • 12. Sum function - Without Tail Call defmodule NoTCO do def sum_no_tco([]), do: 0 def sum_no_tco([head | tail]) do head + sum_no_tco(tail) end end NoTCO.sum_no_tco([1, 2, 3, 4]) 1 + sum_no_tco([2, 3, 4])
  • 13. Sum function - Without Tail Call defmodule NoTCO do def sum_no_tco([]), do: 0 def sum_no_tco([head | tail]) do head + sum_no_tco(tail) end end NoTCO.sum_no_tco([1, 2, 3, 4]) 1 + sum_no_tco([2, 3, 4]) + 2 + sum_no_tco([3, 4])
  • 14. Sum function - Without Tail Call defmodule NoTCO do def sum_no_tco([]), do: 0 def sum_no_tco([head | tail]) do head + sum_no_tco(tail) end end NoTCO.sum_no_tco([1, 2, 3, 4]) 1 + sum_no_tco([2, 3, 4]) + 2 + sum_no_tco([3, 4]) + 3 + sum_no_tco([4])
  • 15. Sum function - Without Tail Call defmodule NoTCO do def sum_no_tco([]), do: 0 def sum_no_tco([head | tail]) do head + sum_no_tco(tail) end end NoTCO.sum_no_tco([1, 2, 3, 4]) 1 + sum_no_tco([2, 3, 4]) + 2 + sum_no_tco([3, 4]) + 3 + sum_no_tco([4]) + 4 + sum_no_tco([])
  • 16. Sum function - Without Tail Call defmodule NoTCO do def sum_no_tco([]), do: 0 def sum_no_tco([head | tail]) do head + sum_no_tco(tail) end end NoTCO.sum_no_tco([1, 2, 3, 4]) 1 + sum_no_tco([2, 3, 4]) + 2 + sum_no_tco([3, 4]) + 3 + sum_no_tco([4]) + 4 + sum_no_tco([]) + 0
  • 17. Sum function - Without Tail Call defmodule NoTCO do def sum_no_tco([]), do: 0 def sum_no_tco([head | tail]) do head + sum_no_tco(tail) end end NoTCO.sum_no_tco([1, 2, 3, 4]) 1 + sum_no_tco([2, 3, 4]) + 2 + sum_no_tco([3, 4]) + 3 + sum_no_tco([4]) + 4 + 0
  • 18. Sum function - Without Tail Call defmodule NoTCO do def sum_no_tco([]), do: 0 def sum_no_tco([head | tail]) do head + sum_no_tco(tail) end end NoTCO.sum_no_tco([1, 2, 3, 4]) 1 + sum_no_tco([2, 3, 4]) + 2 + sum_no_tco([3, 4]) + 3 + 4
  • 19. Sum function - Without Tail Call defmodule NoTCO do def sum_no_tco([]), do: 0 def sum_no_tco([head | tail]) do head + sum_no_tco(tail) end end NoTCO.sum_no_tco([1, 2, 3, 4]) 1 + sum_no_tco([2, 3, 4]) + 2 + 7
  • 20. Sum function - Without Tail Call defmodule NoTCO do def sum_no_tco([]), do: 0 def sum_no_tco([head | tail]) do head + sum_no_tco(tail) end end NoTCO.sum_no_tco([1, 2, 3, 4]) 1 + 9
  • 21. Sum function - Without Tail Call defmodule NoTCO do def sum_no_tco([]), do: 0 def sum_no_tco([head | tail]) do head + sum_no_tco(tail) end end NoTCO.sum_no_tco([1, 2, 3, 4]) = 10
  • 22. Sum function - Tail Call Optimization defmodule TCO do def sum([], acc), do: acc def sum([head | tail], acc) do sum(tail, head + acc) end end
  • 23. Sum function - Tail Call Optimization defmodule TCO do def sum([], acc), do: acc def sum([head | tail], acc) do sum(tail, head + acc) end end TCO.sum([1, 2, 3, 4], 0)
  • 24. Sum function - Tail Call Optimization defmodule TCO do def sum([], acc), do: acc def sum([head | tail], acc) do sum(tail, head + acc) end end TCO.sum([1, 2, 3, 4], 0) sum([2, 3, 4], 1)
  • 25. Sum function - Tail Call Optimization defmodule TCO do def sum([], acc), do: acc def sum([head | tail], acc) do sum(tail, head + acc) end end TCO.sum([1, 2, 3, 4], 0) sum([3, 4], 3)
  • 26. Sum function - Tail Call Optimization defmodule TCO do def sum([], acc), do: acc def sum([head | tail], acc) do sum(tail, head + acc) end end TCO.sum([1, 2, 3, 4], 0) sum([4], 6)
  • 27. Sum function - Tail Call Optimization defmodule TCO do def sum([], acc), do: acc def sum([head | tail], acc) do sum(tail, head + acc) end end TCO.sum([1, 2, 3, 4], 0) sum([], 10)
  • 28. Sum function - Tail Call Optimization defmodule TCO do def sum([], acc), do: acc def sum([head | tail], acc) do sum(tail, head + acc) end end TCO.sum([1, 2, 3, 4], 0) 10
  • 29. Difference defmodule TCO do def sum([], acc), do: acc def sum([head | tail], acc) do sum(tail, head + acc) end end defmodule NoTCO do def sum_no_tco([]), do: 0 def sum_no_tco([head | tail]) do head + sum_no_tco(tail) end end
  • 30. Benchmarking iex(1)> :timer.tc fn -> NoTCO.sum_no_tco(Enum.to_list(1..100_000)) end {17673, 5000050000} iex(2)> :timer.tc fn -> TCO.sum(Enum.to_list(1..100_000), 0) end {10518, 5000050000}
  • 31. inputs = %{ "1_000 list size" => Enum.to_list(1..1_000), "100_000 list size" => Enum.to_list(1..1000_000), "1000_000 list size" => Enum.to_list(1..1000_000), } Benchee.run(%{ "Tail Call Optimizitation" => fn(list) -> TCO.sum(list, 0) end, "No TCO" => fn(list) -> NoTCO.sum_no_tco(list) end, "Enum sum" => fn(list) -> Enum.sum(list) end }, time: 10, memory_time: 2, inputs: inputs, formatters: [ Benchee.Formatters.HTML, Benchee.Formatters.Console ], formatter_options: [html: [file: "lib/report/tco.html"]] )
  • 32.
  • 33.
  • 34. Real example def parse(file_path, modifiers %{}, options %{}, take) do file_path |> File.stream!() |> CsvParser.decode_csv() |> Stream.take(take) |> Stream.map(&process_item(&1, options, modifiers)) |> Stream.filter(&filter_items(&1, options["elastic_search_index" ])) |> Stream.chunk_every(1000) |> Stream.each(&store_items(&1, options["elastic_search_index" ])) |> Stream.run() end
  • 35. [modifiers, file_path] = PpcbeeElixirBackend.Enhance.download(191) Benchee.run( %{ "No Parallelism" => fn -> PpcbeeElixirBackend.DataParser.parse(file_path, modifiers, %{}, 10_000) end, "Parallelism Task.async_stream" => fn -> PpcbeeElixirBackend.DataParser.parse_async_stream(file_path, modifiers, %{},10_000) end, "Parallelism Task.async" => fn -> PpcbeeElixirBackend.DataParser.parse_async_task(file_path, modifiers, %{}, 10_000) end, "Parallelism flow" => fn -> PpcbeeElixirBackend.DataParser.parse_flow(file_path, modifiers, %{}, 10_000) end }, time: 5 * 60, formatters: [ Benchee.Formatters.HTML, ], formatter_options: [html: [file: "lib/benchmark/report/parallelism/report.html"]] )
  • 36.
  • 37. Ruby vs. Elixir - Tested on one machine Ruby - previous service after optimization ● 200 / items per seconds ● CPU 100% ● RAM 560 mb Elixir - before optimization ● 310 (no parallelism), 620 (paralellism) ● CPU 100%, 300% ● RAM 65 mb
  • 38. Profiling - eprof, ExProf “The module eprof provides a set of functions for time profiling of Erlang programs to find out how the execution time is used. The profiling is done using the Erlang trace BIFs. Tracing of local function calls for a specified set of processes is enabled when profiling is begun, and disabled when profiling is stopped.” http://erlang.org/doc/man/eprof.html
  • 39. ...
  • 40.
  • 41. Benchmarking is not real user!
  • 42.
  • 44. Sources ● https://www.issart.com/blog/benchmarking-best-practice-fo r-code-optimization ● https://pragtob.wordpress.com/2016/06/16/tail-call-optimi zation-in-elixir-erlang-not-as-efficient-and-important-as -you-probably-think/ ● https://www.youtube.com/watch?v=KSrImdsfjL4 ● https://www.amberbit.com/blog/2018/5/15/when-to-use-elixi r-language/ ● https://github.com/parroty/exprof ● https://github.com/PragTob/benchee ● https://www.ppcbee.com/