From 02d2a49e5ca5e7a8b7031ed01c5fbd74e409f56a Mon Sep 17 00:00:00 2001 From: boolafish Date: Mon, 31 Aug 2020 23:12:17 +0900 Subject: [PATCH] fix: fee for perf tests - 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 --- .../load_test/lib/common/byzantine_events.ex | 2 +- .../load_test/lib/common/extended_perftest.ex | 16 ++++++------ priv/perf/apps/load_test/lib/common/runner.ex | 19 ++++++++------ .../load_test/lib/common/sender_manager.ex | 13 +++++----- .../load_test/lib/common/sender_server.ex | 14 ++++++----- .../common/byzantine_events_test.exs | 25 +++++++++++-------- .../common/extended_perftest_test.exs | 8 +++--- priv/perf/config/test.exs | 1 + 8 files changed, 56 insertions(+), 42 deletions(-) diff --git a/priv/perf/apps/load_test/lib/common/byzantine_events.ex b/priv/perf/apps/load_test/lib/common/byzantine_events.ex index bb9a27f272..0c70901abb 100644 --- a/priv/perf/apps/load_test/lib/common/byzantine_events.ex +++ b/priv/perf/apps/load_test/lib/common/byzantine_events.ex @@ -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) diff --git a/priv/perf/apps/load_test/lib/common/extended_perftest.ex b/priv/perf/apps/load_test/lib/common/extended_perftest.ex index 8e8b37331c..6cd097a879 100644 --- a/priv/perf/apps/load_test/lib/common/extended_perftest.ex +++ b/priv/perf/apps/load_test/lib/common/extended_perftest.ex @@ -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. @@ -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)}" <> @@ -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) diff --git a/priv/perf/apps/load_test/lib/common/runner.ex b/priv/perf/apps/load_test/lib/common/runner.ex index a9c4a65546..06a72a905c 100644 --- a/priv/perf/apps/load_test/lib/common/runner.ex +++ b/priv/perf/apps/load_test/lib/common/runner.ex @@ -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) @@ -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)}") diff --git a/priv/perf/apps/load_test/lib/common/sender_manager.ex b/priv/perf/apps/load_test/lib/common/sender_manager.ex index 29d2141dfa..15cbcee64b 100644 --- a/priv/perf/apps/load_test/lib/common/sender_manager.ex +++ b/priv/perf/apps/load_test/lib/common/sender_manager.ex @@ -32,17 +32,17 @@ 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)}") @@ -50,7 +50,7 @@ defmodule LoadTest.Common.SenderManager do 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) @@ -63,6 +63,7 @@ defmodule LoadTest.Common.SenderManager do {:ok, %{ senders: senders, + fee_amount: fee_amount, events: [], block_times: [], goal: ntx_to_send, diff --git a/priv/perf/apps/load_test/lib/common/sender_server.ex b/priv/perf/apps/load_test/lib/common/sender_server.ex index df8da6f8ba..60c689ddff 100644 --- a/priv/perf/apps/load_test/lib/common/sender_server.ex +++ b/priv/perf/apps/load_test/lib/common/sender_server.ex @@ -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 @@ -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, @@ -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) @@ -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 """ @@ -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 @@ -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, diff --git a/priv/perf/apps/load_test/test/load_tests/common/byzantine_events_test.exs b/priv/perf/apps/load_test/test/load_tests/common/byzantine_events_test.exs index 6009f26a83..2de6c4e51c 100755 --- a/priv/perf/apps/load_test/test/load_tests/common/byzantine_events_test.exs +++ b/priv/perf/apps/load_test/test/load_tests/common/byzantine_events_test.exs @@ -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() @@ -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() @@ -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() @@ -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() @@ -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() diff --git a/priv/perf/apps/load_test/test/load_tests/common/extended_perftest_test.exs b/priv/perf/apps/load_test/test/load_tests/common/extended_perftest_test.exs index 70c56d843e..5a5451f4f4 100644 --- a/priv/perf/apps/load_test/test/load_tests/common/extended_perftest_test.exs +++ b/priv/perf/apps/load_test/test/load_tests/common/extended_perftest_test.exs @@ -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)) diff --git a/priv/perf/config/test.exs b/priv/perf/config/test.exs index 52f8273020..98f543f8e9 100644 --- a/priv/perf/config/test.exs +++ b/priv/perf/config/test.exs @@ -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,