Skip to content

Commit

Permalink
Fix benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
nsweeting committed Jun 13, 2019
1 parent bd9eabf commit 709c83c
Showing 1 changed file with 45 additions and 7 deletions.
52 changes: 45 additions & 7 deletions bench/bench.exs
Original file line number Diff line number Diff line change
@@ -1,23 +1,61 @@
{:ok, conn} = Rabbit.Connection.start_link()
{:ok, prod} = Rabbit.Producer.start_link(conn, pool_size: 10)
defmodule Connection do
use Rabbit.Connection

def start_link(opts \\ []) do
Rabbit.Connection.start_link(__MODULE__, opts, name: __MODULE__)
end

@impl true
def init(_type, opts) do
{:ok, opts}
end
end

defmodule Producer do
use Rabbit.Producer

def start_link(opts \\ []) do
Rabbit.Producer.start_link(__MODULE__, opts, name: __MODULE__)
end

@impl true
def init(_type, opts) do
{:ok, opts}
end
end

# Setup the RabbitMQ bench queues
{:ok, conn} = AMQP.Connection.open()
{:ok, chan} = AMQP.Channel.open(conn)
AMQP.Queue.declare(chan, "bench_json")
AMQP.Queue.declare(chan, "bench_etf")

# Start the connection and producer
{:ok, _} = Connection.start_link()
{:ok, _} = Producer.start_link(connection: Connection, pool_size: 10)

Benchee.run(%{
"publish json" => fn ->
Rabbit.Producer.publish(
prod,
Producer,
"",
"test1",
"bench_json",
%{foo: "bar", bar: "baz"},
content_type: "application/json"
)
end,
"publish etf" => fn ->
Rabbit.Producer.publish(
prod,
Producer,
"",
"test2",
"bench_etf",
%{foo: "bar", bar: "baz"},
content_type: "application/erlang-binary"
content_type: "application/etf"
)
end
})

# Purge the RabbitMQ bench queues
:timer.sleep(1_000)
AMQP.Queue.purge(chan, "bench_json")
AMQP.Queue.purge(chan, "bench_etf")

0 comments on commit 709c83c

Please sign in to comment.