Current section

4 Versions

Jump to

Compare versions

9 files changed
+516 additions
-427 deletions
  @@ -6,10 +6,8 @@ _Elixir style_ documentation is located [here](https://nats-io.github.io/elixir-
6 6
7 7 ## Getting Started
8 8
9 -
10 - Install Elixir
11 -
12 - To use the framework in your project, add the following to your `mix.exs`:
9 + The framework requires Elixir 1.2.2 or above. To use it in your project,
10 + add the following to your `mix.exs`:
13 11
14 12 ```elixir
15 13 defp deps do
  @@ -1,88 +0,0 @@
1 - # Copyright 2016 Apcera Inc. All rights reserved.
2 -
3 - defmodule ClientBench do
4 - use Benchfella
5 - alias Nats.Client
6 -
7 - @moduledoc """
8 - Simple benchmark for NATS client operations. Far from perfect :-(
9 -
10 - ## Overview
11 - This module's goals is to measure the amount of time it takes to perfom
12 - various NATS verbs/operations for a given message size N.
13 -
14 - Our operations here are pub, pubsub and req/rep.
15 -
16 - From a model perspective we wish to define:
17 - - throughout in bytes/memory per second (or some time frame)
18 - - throughout in messages per second
19 - - latency for pub/sub and req/reply operations
20 - """
21 -
22 - # Test how many messages of a given size we can publish
23 - # in a given time frame...
24 - @mesg_sizes [0, 8, 512, 1024, 4096, 8192]
25 - # how many messages we send/receive in one bench run for a given size,
26 - # this should be at least a couple of seconds of activity... not a perfect
27 - @num_chunks 4096
28 -
29 - setup_all do
30 - subject = "subject"
31 - fake_subject = "fake_subject"
32 - {:ok, conn} = Client.start_link
33 - mesgs_by_size =
34 - Enum.reduce(@mesg_sizes, %{},
35 - fn x, acc -> Map.put(acc, x, make_mesg(x)) end)
36 - {:ok, {conn, subject, fake_subject, mesgs_by_size}}
37 - end
38 -
39 - # make a message of the given size...
40 - defp make_mesg(size) do
41 - template = "Hello NATS world!"
42 - template_size = String.length(template)
43 - String.duplicate(template, div(size, template_size)) <>
44 - String.slice(template, 0, rem(size, template_size))
45 - end
46 -
47 - # trickery and pain... with macros...
48 - Enum.each(@mesg_sizes, fn size ->
49 - @msg_size size
50 - @num_pub_chunks @num_chunks
51 - bench "PUB #{@num_pub_chunks} of size #{@msg_size}",
52 - [con: elem(bench_context, 0),
53 - sub: elem(bench_context, 2) <> "_p_#{@msg_size}",
54 - what: elem(bench_context, 3)[@msg_size]] do
55 - do_pub(con, sub, what, @num_pub_chunks)
56 - end
57 -
58 - defp do_pub(_, _, _, 0), do: :ok
59 - defp do_pub(con, sub, what, n) do
60 - :ok = Client.pub(con, sub, what)
61 - do_pub(con, sub, what, n-1)
62 - end
63 - end)
64 -
65 - Enum.each(@mesg_sizes, fn size ->
66 - @msg_size size
67 - @num_pubsub_chunks @num_chunks
68 - bench "PUB-SUB #{@num_pubsub_chunks} of size #{@msg_size}",
69 - [con: elem(bench_context, 0),
70 - sub: elem(bench_context, 1) <> "_ps_#{@msg_size}",
71 - what: elem(bench_context, 3)[@msg_size]] do
72 - # ideally done once, lazy ;-)
73 - {:ok, ref} = Client.sub(con, self(), sub)
74 - do_pubsub(con, ref, sub, what, @num_pubsub_chunks)
75 - Client.unsub(con, ref)
76 - end
77 - defp do_pubsub(_, _, _, _, 0), do: :ok
78 - defp do_pubsub(con, ref, sub, what, n) do
79 - Client.pub(con, sub, what)
80 - new_n = n
81 - receive do
82 - {:msg, ^ref, ^sub, nil, ^what } -> new_n = n - 1
83 - after 500 -> IO.puts "timeout in test..."
84 - end
85 - do_pubsub(con, ref, sub, what, new_n)
86 - end
87 - end)
88 - end
  @@ -1,14 +0,0 @@
1 - duration:2.0;mem stats:false;sys mem stats:false
2 - module;test;tags;iterations;elapsed
3 - ClientBench PUB-SUB 4096 of size 8192 10 4294391
4 - ClientBench PUB-SUB 4096 of size 8 10 2018013
5 - ClientBench PUB-SUB 4096 of size 512 10 2293581
6 - ClientBench PUB-SUB 4096 of size 4096 10 3338064
7 - ClientBench PUB-SUB 4096 of size 1024 10 2486323
8 - ClientBench PUB-SUB 4096 of size 0 20 3976212
9 - ClientBench PUB 4096 of size 8192 500 7253172
10 - ClientBench PUB 4096 of size 8 200 2926929
11 - ClientBench PUB 4096 of size 512 200 3042153
12 - ClientBench PUB 4096 of size 4096 200 3198587
13 - ClientBench PUB 4096 of size 1024 200 2926545
14 - ClientBench PUB 4096 of size 0 200 3199035
  @@ -1,14 +0,0 @@
1 - duration:2.0;mem stats:false;sys mem stats:false
2 - module;test;tags;iterations;elapsed
3 - ClientBench PUB-SUB 4096 of size 8192 10 3741091
4 - ClientBench PUB-SUB 4096 of size 8 20 3947579
5 - ClientBench PUB-SUB 4096 of size 512 20 3948377
6 - ClientBench PUB-SUB 4096 of size 4096 10 2750136
7 - ClientBench PUB-SUB 4096 of size 1024 10 2014082
8 - ClientBench PUB-SUB 4096 of size 0 20 3533230
9 - ClientBench PUB 4096 of size 8192 500 7581972
10 - ClientBench PUB 4096 of size 8 200 3393953
11 - ClientBench PUB 4096 of size 512 200 3270864
12 - ClientBench PUB 4096 of size 4096 200 3148372
13 - ClientBench PUB 4096 of size 1024 200 3370233
14 - ClientBench PUB 4096 of size 0 200 3079585
  @@ -1,14 +1,11 @@
1 1 {<<"app">>,<<"nats">>}.
2 2 {<<"build_tools">>,[<<"mix">>]}.
3 3 {<<"description">>,<<"NATS framework for Elixir">>}.
4 - {<<"elixir">>,<<"~> 1.2">>}.
4 + {<<"elixir">>,<<">= 1.2.0">>}.
5 5 {<<"files">>,
6 6 [<<"lib/nats.ex">>,<<"lib/nats/client.ex">>,<<"lib/nats/connection.ex">>,
7 7 <<"lib/nats/parser.ex">>,<<"src/json_lexer.erl">>,<<"src/json_lexer.xrl">>,
8 - <<"src/json_parser.erl">>,<<"src/json_parser.yrl">>,
9 - <<"bench/client_bench.exs">>,
10 - <<"bench/snapshots/2016-01-28_13-46-13.snapshot">>,
11 - <<"bench/snapshots/2016-01-29_21-29-54.snapshot">>,<<"mix.exs">>,
8 + <<"src/json_parser.erl">>,<<"src/json_parser.yrl">>,<<"mix.exs">>,
12 9 <<"LICENSE">>,<<"README.md">>]}.
13 10 {<<"licenses">>,[<<"MIT">>]}.
14 11 {<<"links">>,
  @@ -18,4 +15,4 @@
18 15 {<<"maintainers">>,[<<"camros">>,<<"nats.io">>,<<"Apcera">>]}.
19 16 {<<"name">>,<<"natsio">>}.
20 17 {<<"requirements">>,[]}.
21 - {<<"version">>,<<"0.1.4">>}.
18 + {<<"version">>,<<"0.1.5">>}.
Loading more files…