From bf6da9d94f32c4fc3f14874db8f8e5a19157cdfc Mon Sep 17 00:00:00 2001 From: Ryan Schmukler Date: Fri, 14 Apr 2017 15:20:22 -0400 Subject: [PATCH] build(): benchmarks --- bench/rox_bench.exs | 49 ++++++++++++++++++++ bench/snapshots/2017-04-14_12-35-54.snapshot | 3 ++ bench/snapshots/2017-04-14_12-44-40.snapshot | 2 + bench/snapshots/2017-04-14_12-50-20.snapshot | 2 + bench/snapshots/2017-04-14_12-50-59.snapshot | 2 + bench/snapshots/2017-04-14_12-51-19.snapshot | 2 + bench/snapshots/2017-04-14_12-52-26.snapshot | 3 ++ bench/snapshots/2017-04-14_12-52-50.snapshot | 3 ++ bench/snapshots/2017-04-14_12-55-19.snapshot | 3 ++ mix.exs | 10 ++-- mix.lock | 6 ++- 11 files changed, 81 insertions(+), 4 deletions(-) create mode 100644 bench/rox_bench.exs create mode 100644 bench/snapshots/2017-04-14_12-35-54.snapshot create mode 100644 bench/snapshots/2017-04-14_12-44-40.snapshot create mode 100644 bench/snapshots/2017-04-14_12-50-20.snapshot create mode 100644 bench/snapshots/2017-04-14_12-50-59.snapshot create mode 100644 bench/snapshots/2017-04-14_12-51-19.snapshot create mode 100644 bench/snapshots/2017-04-14_12-52-26.snapshot create mode 100644 bench/snapshots/2017-04-14_12-52-50.snapshot create mode 100644 bench/snapshots/2017-04-14_12-55-19.snapshot diff --git a/bench/rox_bench.exs b/bench/rox_bench.exs new file mode 100644 index 0000000..0e6beb4 --- /dev/null +++ b/bench/rox_bench.exs @@ -0,0 +1,49 @@ +defmodule RoxBench do + use Benchfella + + @sample_record %{name: "Bob", age: 38, favorite_color: "Blue", gender: :male, is_likeable: false, pets: [%{name: "Woof", species: :dog}]} + + setup_all do + :ok = + Application.ensure_started(:faker) + + {:ok, db, cfs} = + Rox.open("./bench.rocksdb", [create_if_missing: true, auto_create_column_families: true], ["a", "b", "c"]) + + {:ok, %{db: db, cfs: cfs, default_cf: cfs["a"]}} + end + + teardown_all _ do + File.rm_rf!("./bench.rocksdb") + end + + bench "random_writes" do + Rox.put(bench_context.default_cf, random_key(), random_record()) + end + + defp random_key() do + :crypto.rand_uniform(1, 10_000_000) + |> Integer.to_string() + end + + defp random_record() do + num_pets = + :crypto.rand_uniform(0, 3) + + %{ + name: Faker.Name.name(), + age: :crypto.rand_uniform(20, 50), + favorite_color: Faker.Color.name(), + description: Faker.Lorem.words(10), + profile_url: Faker.Internet.image_url(), + pets: Enum.map(0..num_pets, fn _ -> random_pet() end) + } + end + + defp random_pet() do + %{ + name: Faker.Name.first_name(), + age: :crypto.rand_uniform(1, 7), + } + end +end diff --git a/bench/snapshots/2017-04-14_12-35-54.snapshot b/bench/snapshots/2017-04-14_12-35-54.snapshot new file mode 100644 index 0000000..baa4e0e --- /dev/null +++ b/bench/snapshots/2017-04-14_12-35-54.snapshot @@ -0,0 +1,3 @@ +duration:1.0;mem stats:false;sys mem stats:false +module;test;tags;iterations;elapsed +RoxBench random_writes 500000 2514784 diff --git a/bench/snapshots/2017-04-14_12-44-40.snapshot b/bench/snapshots/2017-04-14_12-44-40.snapshot new file mode 100644 index 0000000..213481c --- /dev/null +++ b/bench/snapshots/2017-04-14_12-44-40.snapshot @@ -0,0 +1,2 @@ +duration:1.0;mem stats:false;sys mem stats:false +module;test;tags;iterations;elapsed diff --git a/bench/snapshots/2017-04-14_12-50-20.snapshot b/bench/snapshots/2017-04-14_12-50-20.snapshot new file mode 100644 index 0000000..213481c --- /dev/null +++ b/bench/snapshots/2017-04-14_12-50-20.snapshot @@ -0,0 +1,2 @@ +duration:1.0;mem stats:false;sys mem stats:false +module;test;tags;iterations;elapsed diff --git a/bench/snapshots/2017-04-14_12-50-59.snapshot b/bench/snapshots/2017-04-14_12-50-59.snapshot new file mode 100644 index 0000000..213481c --- /dev/null +++ b/bench/snapshots/2017-04-14_12-50-59.snapshot @@ -0,0 +1,2 @@ +duration:1.0;mem stats:false;sys mem stats:false +module;test;tags;iterations;elapsed diff --git a/bench/snapshots/2017-04-14_12-51-19.snapshot b/bench/snapshots/2017-04-14_12-51-19.snapshot new file mode 100644 index 0000000..213481c --- /dev/null +++ b/bench/snapshots/2017-04-14_12-51-19.snapshot @@ -0,0 +1,2 @@ +duration:1.0;mem stats:false;sys mem stats:false +module;test;tags;iterations;elapsed diff --git a/bench/snapshots/2017-04-14_12-52-26.snapshot b/bench/snapshots/2017-04-14_12-52-26.snapshot new file mode 100644 index 0000000..af07b78 --- /dev/null +++ b/bench/snapshots/2017-04-14_12-52-26.snapshot @@ -0,0 +1,3 @@ +duration:1.0;mem stats:false;sys mem stats:false +module;test;tags;iterations;elapsed +RoxBench random_writes 500000 2802990 diff --git a/bench/snapshots/2017-04-14_12-52-50.snapshot b/bench/snapshots/2017-04-14_12-52-50.snapshot new file mode 100644 index 0000000..099a2f6 --- /dev/null +++ b/bench/snapshots/2017-04-14_12-52-50.snapshot @@ -0,0 +1,3 @@ +duration:1.0;mem stats:false;sys mem stats:false +module;test;tags;iterations;elapsed +RoxBench random_writes 500000 2798738 diff --git a/bench/snapshots/2017-04-14_12-55-19.snapshot b/bench/snapshots/2017-04-14_12-55-19.snapshot new file mode 100644 index 0000000..46f4cc0 --- /dev/null +++ b/bench/snapshots/2017-04-14_12-55-19.snapshot @@ -0,0 +1,3 @@ +duration:1.0;mem stats:false;sys mem stats:false +module;test;tags;iterations;elapsed +RoxBench random_writes 10000 1380040 diff --git a/mix.exs b/mix.exs index a5c59cd..c9bb474 100644 --- a/mix.exs +++ b/mix.exs @@ -4,7 +4,7 @@ defmodule Rox.Mixfile do def project do [app: :rox, version: "1.0.0", - elixir: "~> 1.3", + elixir: "~> 1.4", build_embedded: Mix.env == :prod, start_permanent: Mix.env == :prod, compilers: [:rustler] ++ Mix.compilers(), @@ -18,7 +18,7 @@ defmodule Rox.Mixfile do # # Type "mix help compile.app" for more information def application do - [applications: [:logger]] + [extra_applications: [:logger]] end # Dependencies can be Hex packages: @@ -33,7 +33,11 @@ defmodule Rox.Mixfile do defp deps do [ {:rustler, "~> 0.9.0"}, - {:ex_doc, ">= 0.0.0", only: :dev} + {:ex_doc, ">= 0.0.0", only: :dev}, + {:benchfella, "~> 0.3", only: :dev}, + {:faker, "~> 0.7", only: :dev}, + {:flow, "~> 0.11", only: :dev}, + {:gen_stage, "~> 0.11", only: :dev}, ] end diff --git a/mix.lock b/mix.lock index 297c60c..75f6ed6 100644 --- a/mix.lock +++ b/mix.lock @@ -1,4 +1,8 @@ -%{"earmark": {:hex, :earmark, "1.2.0", "bf1ce17aea43ab62f6943b97bd6e3dc032ce45d4f787504e3adf738e54b42f3a", [:mix], []}, +%{"benchfella": {:hex, :benchfella, "0.3.4", "41d2c017b361ece5225b5ba2e3b30ae53578c57c6ebc434417b4f1c2c94cf4f3", [:mix], []}, + "earmark": {:hex, :earmark, "1.2.0", "bf1ce17aea43ab62f6943b97bd6e3dc032ce45d4f787504e3adf738e54b42f3a", [:mix], []}, "erocksdb": {:hex, :erocksdb, "0.4.1", "59a3258b1460d0e64f7575d912d9af86fa5aa56729abff18e4d3e4fd4a5e01e0", [:rebar3], []}, "ex_doc": {:hex, :ex_doc, "0.15.0", "e73333785eef3488cf9144a6e847d3d647e67d02bd6fdac500687854dd5c599f", [:mix], [{:earmark, "~> 1.1", [hex: :earmark, optional: false]}]}, + "faker": {:hex, :faker, "0.7.0", "2c42deeac7be717173c78c77fb3edc749fb5d5e460e33d01fe592ae99acc2f0d", [:mix], []}, + "flow": {:hex, :flow, "0.11.1", "cbc35a0236520cc5fec7b5863cd8431cb1e77297c5c9119055676355eb1fb5a6", [:mix], [{:gen_stage, "~> 0.11.0", [hex: :gen_stage, optional: false]}]}, + "gen_stage": {:hex, :gen_stage, "0.11.0", "943bdfa85c75fa624e0a36a9d135baad20a523be040178f5a215444b45c66ea4", [:mix], []}, "rustler": {:hex, :rustler, "0.9.0", "6fa87ac78f48f70aa8ecfb6e16b8af41c398989d33de41d292b5581d6a2eeb5a", [:mix], []}}