Skip to content

Commit

Permalink
fix: fee for perf tests
Browse files Browse the repository at this point in the history
- set in the test config to use the new fee amount 75
- for LoadTest.Common, pass in the fee_amount and use the value from config
  • Loading branch information
boolafish committed Aug 31, 2020
1 parent c96c39d commit 02d2a49
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 42 deletions.
2 changes: 1 addition & 1 deletion priv/perf/apps/load_test/lib/common/byzantine_events.ex
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ defmodule LoadTest.Common.ByzantineEvents do
You probably want to prefill the child chain with transactions, see `OMG.Performance.ExtendedPerftest` or just:
```
LoadTest.Common.ExtendedPerftest.start(10_000, 16, randomized: false)
LoadTest.Common.ExtendedPerftest.start(10_000, 16, 75, randomized: false)
```
(`randomized: false` is useful to test massive honest-standard-exiting, since it will create many unspent UTXOs for
each of the spenders)
Expand Down
16 changes: 8 additions & 8 deletions priv/perf/apps/load_test/lib/common/extended_perftest.ex
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ defmodule LoadTest.Common.ExtendedPerftest do
Performance.init()
spenders = Generators.generate_users(2)
LoadTest.Common.ExtendedPerftest.start(100, spenders, destdir: destdir)
LoadTest.Common.ExtendedPerftest.start(100, spenders, fee_amount, destdir: destdir)
```
The results are going to be waiting for you in a file within `destdir` and will be logged.
Expand All @@ -49,8 +49,8 @@ defmodule LoadTest.Common.ExtendedPerftest do
- :randomized - whether the non-change outputs of the txs sent out will be random or equal to sender (if `false`),
defaults to `true`
"""
@spec start(pos_integer(), list(map()), keyword()) :: :ok
def start(ntx_to_send, spenders, opts \\ []) do
@spec start(pos_integer(), list(map()), pos_integer(), keyword()) :: :ok
def start(ntx_to_send, spenders, fee_amount, opts \\ []) do
_ =
Logger.info(
"Number of spenders: #{inspect(length(spenders))}, number of tx to send per spender: #{inspect(ntx_to_send)}" <>
Expand All @@ -61,18 +61,18 @@ defmodule LoadTest.Common.ExtendedPerftest do

opts = Keyword.merge(defaults, opts)

utxos = create_deposits(spenders, ntx_to_send)
utxos = create_deposits(spenders, ntx_to_send, fee_amount)

result = LoadTest.Common.Runner.run(ntx_to_send, utxos, opts, false)
result = LoadTest.Common.Runner.run(ntx_to_send, utxos, fee_amount, opts, false)

Process.sleep(20_000)

result
end

@spec create_deposits(list(map()), pos_integer()) :: list()
defp create_deposits(spenders, ntx_to_send) do
Enum.map(make_deposits(ntx_to_send * 2, spenders), fn {:ok, owner, blknum, amount} ->
@spec create_deposits(list(map()), pos_integer(), pos_integer()) :: list()
defp create_deposits(spenders, ntx_to_send, fee_amount) do
Enum.map(make_deposits(ntx_to_send * 2 * fee_amount, spenders), fn {:ok, owner, blknum, amount} ->
utxo_pos = ExPlasma.Utxo.pos(%{blknum: blknum, txindex: 0, oindex: 0})
%{owner: owner, utxo_pos: utxo_pos, amount: amount}
end)
Expand Down
19 changes: 12 additions & 7 deletions priv/perf/apps/load_test/lib/common/runner.ex
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,20 @@ defmodule LoadTest.Common.Runner do
Foreach user runs n submit_transaction requests to the chain server. Requests are done sequentially for every user
"""
@spec run(pos_integer(), list(), keyword(), profile :: boolean()) :: :ok
def run(ntx_to_send, utxos, opts, true), do: do_profiled_run(ntx_to_send, utxos, opts)
def run(ntx_to_send, utxos, opts, false), do: do_run(ntx_to_send, utxos, opts)
@spec run(pos_integer(), list(), pos_integer(), keyword(), profile :: boolean()) :: :ok
def run(ntx_to_send, utxos, fee_amount, opts, true), do: do_profiled_run(ntx_to_send, utxos, fee_amount, opts)
def run(ntx_to_send, utxos, fee_amount, opts, false), do: do_run(ntx_to_send, utxos, fee_amount, opts)

defp do_run(ntx_to_send, utxos, opts) do
defp do_run(ntx_to_send, utxos, fee_amount, opts) do
{duration, _result} =
:timer.tc(fn ->
# fire async transaction senders
manager = LoadTest.Common.SenderManager.start_link_all_senders(ntx_to_send, utxos, opts)
manager = LoadTest.Common.SenderManager.start_link_all_senders(
ntx_to_send,
utxos,
fee_amount,
opts
)

# Wait all senders do their job, checker will stop when it happens and stops itself
wait_for(manager)
Expand All @@ -43,8 +48,8 @@ defmodule LoadTest.Common.Runner do
:ok
end

defp do_profiled_run(ntx_to_send, utxos, opts) do
:fprof.apply(&do_run/3, [ntx_to_send, utxos, opts], procs: [:all])
defp do_profiled_run(ntx_to_send, utxos, fee_amount, opts) do
:fprof.apply(&do_run/4, [ntx_to_send, utxos, fee_amount, opts], procs: [:all])
:fprof.profile()

destfile = Path.join(opts[:destdir], "perf_result_profiling_#{:os.system_time(:seconds)}")
Expand Down
13 changes: 7 additions & 6 deletions priv/perf/apps/load_test/lib/common/sender_manager.ex
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,25 @@ defmodule LoadTest.Common.SenderManager do
@doc """
Starts the sender's manager process
"""
@spec start_link_all_senders(pos_integer(), list(), keyword()) :: pid
def start_link_all_senders(ntx_to_send, utxos, opts) do
{:ok, mypid} = GenServer.start_link(__MODULE__, {ntx_to_send, utxos, opts}, name: __MODULE__)
@spec start_link_all_senders(pos_integer(), list(), pos_integer(), keyword()) :: pid
def start_link_all_senders(ntx_to_send, utxos, fee_amount, opts) do
{:ok, mypid} = GenServer.start_link(__MODULE__, {ntx_to_send, utxos, fee_amount, opts}, name: __MODULE__)
mypid
end

@doc """
Starts sender processes
"""
@spec init({pos_integer(), list(), keyword()}) :: {:ok, map()}
def init({ntx_to_send, utxos, opts}) do
@spec init({pos_integer(), list(), pos_integer(), keyword()}) :: {:ok, map()}
def init({ntx_to_send, utxos, fee_amount, opts}) do
Process.flag(:trap_exit, true)
_ = Logger.debug("init called with utxos: #{inspect(length(utxos))}, ntx_to_send: #{inspect(ntx_to_send)}")

senders =
utxos
|> Enum.with_index(1)
|> Enum.map(fn {utxo, seqnum} ->
{:ok, pid} = LoadTest.Common.SenderServer.start_link({seqnum, utxo, ntx_to_send, opts})
{:ok, pid} = LoadTest.Common.SenderServer.start_link({seqnum, utxo, ntx_to_send, fee_amount, opts})
{seqnum, pid}
end)

Expand All @@ -63,6 +63,7 @@ defmodule LoadTest.Common.SenderManager do
{:ok,
%{
senders: senders,
fee_amount: fee_amount,
events: [],
block_times: [],
goal: ntx_to_send,
Expand Down
14 changes: 8 additions & 6 deletions priv/perf/apps/load_test/lib/common/sender_server.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ defmodule LoadTest.Common.SenderServer do

# Waiting time (in milliseconds) before unsuccessful Tx submission is retried.
@tx_retry_waiting_time_ms 333
@fees_amount 1

use GenServer

Expand All @@ -46,6 +45,7 @@ defmodule LoadTest.Common.SenderServer do
:seqnum,
:ntx_to_send,
:spender,
:fee_amount,
# {blknum, txindex, oindex, amount}, @see %LastTx above
:last_tx,
:child_chain_url,
Expand Down Expand Up @@ -80,7 +80,7 @@ defmodule LoadTest.Common.SenderServer do
defaults to `true`
"""
@spec init({pos_integer(), map(), pos_integer(), keyword()}) :: {:ok, state()}
def init({seqnum, utxo, ntx_to_send, opts}) do
def init({seqnum, utxo, ntx_to_send, fee_amount, opts}) do
defaults = [randomized: true]
opts = Keyword.merge(defaults, opts)

Expand All @@ -90,7 +90,7 @@ defmodule LoadTest.Common.SenderServer do
)

send(self(), :do)
{:ok, init_state(seqnum, utxo, ntx_to_send, opts)}
{:ok, init_state(seqnum, utxo, ntx_to_send, fee_amount, opts)}
end

@doc """
Expand Down Expand Up @@ -120,7 +120,7 @@ defmodule LoadTest.Common.SenderServer do

defp prepare_and_submit_tx(state) do
to_spend = 1
new_amount = state.last_tx.amount - to_spend - @fees_amount
new_amount = state.last_tx.amount - to_spend - state.fee_amount

recipient =
if state.randomized do
Expand Down Expand Up @@ -186,14 +186,16 @@ defmodule LoadTest.Common.SenderServer do
end

# Generates module's initial state
@spec init_state(pos_integer(), map(), pos_integer(), keyword()) :: __MODULE__.state()
defp init_state(seqnum, %{owner: spender, utxo_pos: utxo_pos, amount: amount}, ntx_to_send, opts) do
@spec init_state(pos_integer(), map(), pos_integer(), pos_integer(), keyword()) :: __MODULE__.state()
defp init_state(seqnum, utxo, ntx_to_send, fee_amount, opts) do
%{owner: spender, utxo_pos: utxo_pos, amount: amount} = utxo
{:ok, %ExPlasma.Utxo{blknum: blknum, txindex: txindex, oindex: oindex}} = ExPlasma.Utxo.new(utxo_pos)

%__MODULE__{
seqnum: seqnum,
ntx_to_send: ntx_to_send,
spender: spender,
fee_amount: fee_amount,
last_tx: %LastTx{
# initial state takes deposited value, put there on :init
blknum: blknum,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,17 @@ defmodule LoadTest.Common.ByzantineEventsTest do
_ = String.to_atom("last_validated_child_block_timestamp")

{:ok, destdir} = Briefly.create(directory: true, prefix: "temp_results")
{:ok, %{destdir: destdir}}

fee_amount = Application.fetch_env!(:load_test, :fee_amount)

{:ok, %{destdir: destdir, fee_amount: fee_amount}}
end

test "can provide timing of response when asking for exit data", %{destdir: destdir} do
test "can provide timing of response when asking for exit data", %{destdir: destdir, fee_amount: fee_amount} do
spenders = Generators.generate_users(2)
alice = Enum.at(spenders, 0)

:ok = ExtendedPerftest.start(@number_of_transactions_to_send, spenders, randomized: false, destdir: destdir)
:ok = ExtendedPerftest.start(@number_of_transactions_to_send, spenders, fee_amount, randomized: false, destdir: destdir)

:ok = ByzantineEvents.watcher_synchronize()

Expand All @@ -54,11 +57,11 @@ defmodule LoadTest.Common.ByzantineEventsTest do

# since we're using the same geth node for all tests, this test is not compatible with the test on line 76
@tag :skip
test "can provide timing of status.get under many valid SEs", %{destdir: destdir} do
test "can provide timing of status.get under many valid SEs", %{destdir: destdir, fee_amount: fee_amount} do
spenders = Generators.generate_users(2)
alice = Enum.at(spenders, 0)

:ok = ExtendedPerftest.start(@number_of_transactions_to_send, spenders, randomized: false, destdir: destdir)
:ok = ExtendedPerftest.start(@number_of_transactions_to_send, spenders, fee_amount, randomized: false, destdir: destdir)

:ok = ByzantineEvents.watcher_synchronize()

Expand All @@ -72,11 +75,11 @@ defmodule LoadTest.Common.ByzantineEventsTest do
assert ByzantineEvents.get_byzantine_events("invalid_exit") == []
end

test "can provide timing of status.get under many valid/invalid SEs", %{destdir: destdir} do
test "can provide timing of status.get under many valid/invalid SEs", %{destdir: destdir, fee_amount: fee_amount} do
spenders = Generators.generate_users(2)
alice = Enum.at(spenders, 0)

:ok = ExtendedPerftest.start(@number_of_transactions_to_send, spenders, randomized: true, destdir: destdir)
:ok = ExtendedPerftest.start(@number_of_transactions_to_send, spenders, fee_amount, randomized: true, destdir: destdir)

:ok = ByzantineEvents.watcher_synchronize()

Expand All @@ -90,11 +93,11 @@ defmodule LoadTest.Common.ByzantineEventsTest do
assert Enum.count(ByzantineEvents.get_byzantine_events("invalid_exit")) >= @take
end

test "can provide timing of challenging", %{destdir: destdir} do
test "can provide timing of challenging", %{destdir: destdir, fee_amount: fee_amount} do
spenders = Generators.generate_users(2)
alice = Enum.at(spenders, 0)

:ok = ExtendedPerftest.start(@number_of_transactions_to_send, spenders, randomized: true, destdir: destdir)
:ok = ExtendedPerftest.start(@number_of_transactions_to_send, spenders, fee_amount, randomized: true, destdir: destdir)

:ok = ByzantineEvents.watcher_synchronize()

Expand All @@ -114,11 +117,11 @@ defmodule LoadTest.Common.ByzantineEventsTest do
assert Enum.count(challenge_responses) >= @take
end

test "can provide timing of status.get under many challenged SEs", %{destdir: destdir} do
test "can provide timing of status.get under many challenged SEs", %{destdir: destdir, fee_amount: fee_amount} do
spenders = Generators.generate_users(2)
alice = Enum.at(spenders, 0)

:ok = ExtendedPerftest.start(@number_of_transactions_to_send, spenders, randomized: true, destdir: destdir)
:ok = ExtendedPerftest.start(@number_of_transactions_to_send, spenders, fee_amount, randomized: true, destdir: destdir)

:ok = ByzantineEvents.watcher_synchronize()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ defmodule LoadTest.Common.ExtendedPerftestTest do
@tag timeout: 120_000
test "Smoke test - run start_extended_perf and see if it doesn't crash" do
{:ok, destdir} = Briefly.create(directory: true, prefix: "temp_results")
# 3000 txs sending 1 each, plus 1 for fees
ntxs = 3000
# 1000 txs sending 1 each, plus 1 for fees
ntxs = 1000
senders = Generators.generate_users(2)

assert :ok = ExtendedPerftest.start(ntxs, senders, destdir: destdir)
fee_amount = Application.fetch_env!(:load_test, :fee_amount)

assert :ok = ExtendedPerftest.start(ntxs, senders, fee_amount, destdir: destdir)

assert ["perf_result" <> _ = perf_result] = File.ls!(destdir)
smoke_test_statistics(Path.join(destdir, perf_result), ntxs * length(senders))
Expand Down
1 change: 1 addition & 0 deletions priv/perf/config/test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ config :load_test,
watcher_security_url: "http://localhost:7434",
watcher_info_url: "http://localhost:7534",
faucet_deposit_amount: trunc(:math.pow(10, 18) * 10),
fee_amount: 75, # see testing setup: https://github.com/omgnetwork/fee-rules-public/blob/master/fee_rules.json
utxo_load_test_config: %{
concurrent_sessions: 10,
utxos_to_create_per_session: 5,
Expand Down

0 comments on commit 02d2a49

Please sign in to comment.