Remove benchfella and benchmarks (#351)

These benchmarks are based on a direct comparison to the Apache Thift
Erlang implementation from several Elixir versions ago.

We're also in the process of removing our Erlang runtime coupling (#323)
which will make it difficult to continue maintaining these benchmarks in
their current form.
This commit is contained in:
Jon Parise 2018-07-21 21:51:37 -07:00 committed by GitHub
parent c25599692f
commit 2c1380b36d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 0 additions and 219 deletions

View File

@ -10,36 +10,6 @@ The serialization and deserialization code that is generated by this project is
optimized and is between **10 and 25 times faster**<sub>[why?](#why-is-it-faster-than-the-apache-implementation)</sub> than the code generated by the
Apache Erlang implementation.
#### Binary protocol benchmark
(run `mix bench bench/binary_protocol_benchmark.exs`)
Benchmark name | Iterations | Average time
--------------------------------------------|------------|-------------
elixir serialization (left as IOList) | 2000 | 810.53 µs/op
elixir deserialization | 1000 | 1234.69 µs/op
elixir serialization (converted to binary) | 1000 | 1254.23 µs/op
erlang serialization left as IOList | 100 | 10544.31 µs/op
erlang serialization (converted to binary) | 100 | 11714.74 µs/op
erlang deserialization | 100 | 21671.39 µs/op
*Note: all serialization in this framework leaves its results in iolists for speed and efficiency.*
#### Framed Server Benchmark
(run `mix bench bench/framed_server_benchmark.exs`)
Benchmark name | Iterations | Average time
-------------------------------|--------------|--------------
Returning a boolean in Elixir | 50000 | 51.20 µs/op
Returning a boolean in Erlang | 20000 | 74.46 µs/op
Echoing a struct in Elixir | 10000 | 275.89 µs/op
Echoing a struct in Erlang | 1000 | 1200.35 µs/op
*Note: The Erlang parts of the above benchmark utilized the generated Erlang client
and server from the Apache Thrift project*
*Benchmarks were run on a 2.8Ghz MacbookPro with 16G of ram running macOS Sierra, using Elixir 1.3.4 and Erlang 19.1*
## Setup
Start by adding this package to your project as a dependency:

View File

@ -1,97 +0,0 @@
defmodule BinaryProtocolBenchmark do
use Benchfella
@thrift_file_path "./test/fixtures/app/thrift/simple.thrift"
import ParserUtils
setup_all do
parse_thrift(@thrift_file_path)
|> compile_module
{:ok, :ok}
end
before_each_bench _ do
user_options = [
is_evil: true,
user_id: 1234567,
number_of_hairs_on_head: 26482,
amount_of_red: 182,
nineties_era_color: 24345,
mint_gum: 28.282,
username: "esteban",
friends: [],
# my_map: %{1 => "abc", 2 => "def", 3 => "asldfkjlasdkjf"},
# blocked_user_ids: [2234, 2345, 654365, 4356, 3456, 1234, 234, 2345, 3456, 4567],
optional_integers: [2234, 2345, 654365, 4356, 3456, 1234, 234, 2345, 3456, 4567],
]
erlang_users = for _ <- 1..1000 do
user(:erlang, user_options)
end
elixir_users = for _ <- 1..1000 do
user(:elixir, user_options)
end
user_binary = user(:elixir, user_options)
|> serialize_user_elixir(convert_to_binary: true)
context = [
elixir_users: elixir_users,
erlang_users: erlang_users,
user_binary: user_binary,
]
{:ok, context}
end
bench "erlang serialization (converted to binary)" do
for user <- bench_context[:erlang_users] do
serialize_user_erlang(user, convert_to_binary: true)
end
:ok
end
bench "erlang serialization left as IOList" do
for user <- bench_context[:erlang_users] do
serialize_user_erlang(user, convert_to_binary: false)
end
:ok
end
bench "elixir serialization (iolist_size)" do
for user <- bench_context[:elixir_users] do
serialize_user_elixir(user, convert_to_binary: false)
|> :erlang.iolist_size
end
:ok
end
bench "elixir serialization (converted to binary)" do
for user <- bench_context[:elixir_users] do
serialize_user_elixir(user, convert_to_binary: true)
end
:ok
end
bench "elixir serialization (left as IOList)" do
for user <- bench_context[:elixir_users] do
serialize_user_elixir(user, convert_to_binary: false)
end
:ok
end
bench "erlang deserialization" do
for _ <- 1..1000 do
deserialize_user_erlang(bench_context[:user_binary])
end
:ok
end
bench "elixir deserialization" do
for _ <- 1..1000 do
deserialize_user_elixir(bench_context[:user_binary])
end
:ok
end
end

View File

@ -1,89 +0,0 @@
defmodule FramedServerBenchmark do
use Benchfella
@thrift_file_path "./test/fixtures/app/thrift/simple.thrift"
import ParserUtils
defmodule Simple.Handler do
def echo_user(user) do
user
end
def ping, do: true
end
defmodule ErlangHandlers do
def handle_function(:echo_user, {user}) do
{:reply, user}
end
def handle_function(:ping, _) do
{:reply, true}
end
end
setup_all do
@thrift_file_path
|> parse_thrift
|> compile_module
Application.start(:ranch)
{:ok, server_pid} = SimpleService.Binary.Framed.Server.start_link(Simple.Handler, 12345, [])
{:ok, erlang_server_pid} = :thrift_socket_server.start(handler: ErlangHandlers,
port: 56789,
service: :simple_service_thrift,
framed: true,
socket_opts: [
recv_timeout: 15_000,
keepalive: true])
map_value = 1..100
|> Enum.map(fn num -> {num, "foo#{num}"} end)
|> Map.new
blocked_user_ids = Enum.to_list(50_000..50_150)
user_options = [
is_evil: false,
user_id: 2841204,
number_of_hairs_on_head: 1029448,
amount_of_red: 23,
nineties_era_color: 381221,
mint_gum: 24421.024,
username: "Stinkypants",
my_map: map_value,
optional_integers: Enum.to_list(1..100),
blocked_user_ids: blocked_user_ids
]
erlang_user = user(:erlang, user_options)
elixir_user = user(:elixir, user_options)
{:ok, client} = SimpleService.Binary.Framed.Client.start_link("localhost", 12345, [])
{:ok, erlang_client} = :thrift_client_util.new('localhost', 56789, :simple_service_thrift, framed: true)
{:ok, elixir_user: elixir_user, erlang_user: erlang_user, client: client, erlang_client: erlang_client}
end
bench "Echoing a struct in Elixir" do
user = bench_context[:elixir_user]
client = bench_context[:client]
{:ok, user} = SimpleService.Binary.Framed.Client.echo_user(client, user)
end
bench "Returning a boolean in Elixir" do
client = bench_context[:client]
{:ok, user} = SimpleService.Binary.Framed.Client.ping(client)
end
bench "Echoing a struct in Erlang" do
{_client, {:ok, _u}} = bench_context[:erlang_client]
|> :thrift_client.call(:echo_user, [bench_context[:erlang_user]])
end
bench "Returning a boolean in Erlang" do
{_client, {:ok, true}} = bench_context[:erlang_client]
|> :thrift_client.call(:ping, [])
end
end

View File

@ -26,7 +26,6 @@ defmodule Thrift.Mixfile do
# Testing
test_coverage: [tool: ExCoveralls],
preferred_cli_env: [
"bench": :test,
"coveralls": :test,
"coveralls.detail": :test,
"coveralls.html": :test,
@ -72,7 +71,6 @@ defmodule Thrift.Mixfile do
{:excoveralls, "~> 0.9", only: [:dev, :test]},
{:credo, "~> 0.9", only: [:dev, :test]},
{:dialyxir, "~> 0.5", only: :dev, runtime: false},
{:benchfella, "~> 0.3", only: [:dev, :test]},
{:connection, "~> 1.0"},
{:ranch, "~> 1.4"},
]

View File

@ -1,5 +1,4 @@
%{
"benchfella": {:hex, :benchfella, "0.3.5", "b2122c234117b3f91ed7b43b6e915e19e1ab216971154acd0a80ce0e9b8c05f5", [:mix], [], "hexpm"},
"bunt": {:hex, :bunt, "0.2.0", "951c6e801e8b1d2cbe58ebbd3e616a869061ddadcc4863d0a2182541acae9a38", [:mix], [], "hexpm"},
"certifi": {:hex, :certifi, "2.3.1", "d0f424232390bf47d82da8478022301c561cf6445b5b5fb6a84d49a9e76d2639", [:rebar3], [{:parse_trans, "3.2.0", [hex: :parse_trans, repo: "hexpm", optional: false]}], "hexpm"},
"connection": {:hex, :connection, "1.0.4", "a1cae72211f0eef17705aaededacac3eb30e6625b04a6117c1b2db6ace7d5976", [:mix], [], "hexpm"},