From 3ab9033c3f0b82e3511e699134a5efbd058c3c49 Mon Sep 17 00:00:00 2001 From: Tim Mecklem Date: Tue, 26 Jun 2018 16:47:20 -0400 Subject: [PATCH 1/4] Use indexed column in count --- apps/explorer/lib/explorer/chain/statistics.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/explorer/lib/explorer/chain/statistics.ex b/apps/explorer/lib/explorer/chain/statistics.ex index cebe2975fe..cc12beba9a 100644 --- a/apps/explorer/lib/explorer/chain/statistics.ex +++ b/apps/explorer/lib/explorer/chain/statistics.ex @@ -30,7 +30,7 @@ defmodule Explorer.Chain.Statistics do """ @block_velocity_query """ - SELECT count(blocks.hash) + SELECT count(blocks.inserted_at) FROM blocks WHERE blocks.inserted_at > NOW() - interval '1 minute' """ From d78114b73d2bdf6dab9a9a0aff7aeff1a301ab21 Mon Sep 17 00:00:00 2001 From: Tim Mecklem Date: Tue, 26 Jun 2018 16:58:53 -0400 Subject: [PATCH 2/4] Use indexed column for count in transaction velocity --- apps/explorer/lib/explorer/chain/statistics.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/explorer/lib/explorer/chain/statistics.ex b/apps/explorer/lib/explorer/chain/statistics.ex index cc12beba9a..2319452e6c 100644 --- a/apps/explorer/lib/explorer/chain/statistics.ex +++ b/apps/explorer/lib/explorer/chain/statistics.ex @@ -36,7 +36,7 @@ defmodule Explorer.Chain.Statistics do """ @transaction_velocity_query """ - SELECT count(transactions.hash) + SELECT count(transactions.inserted_at) FROM transactions WHERE transactions.inserted_at > NOW() - interval '1 minute' """ From cb327d573dd72e2800196662809e3f73882a83c5 Mon Sep 17 00:00:00 2001 From: Tim Mecklem Date: Tue, 26 Jun 2018 17:02:36 -0400 Subject: [PATCH 3/4] Remove unused block velocity from statistics --- apps/explorer/lib/explorer/chain/statistics.ex | 10 ---------- apps/explorer/test/explorer/chain/statistics_test.exs | 10 ---------- 2 files changed, 20 deletions(-) diff --git a/apps/explorer/lib/explorer/chain/statistics.ex b/apps/explorer/lib/explorer/chain/statistics.ex index 2319452e6c..57a7938228 100644 --- a/apps/explorer/lib/explorer/chain/statistics.ex +++ b/apps/explorer/lib/explorer/chain/statistics.ex @@ -29,12 +29,6 @@ defmodule Explorer.Chain.Statistics do ) t """ - @block_velocity_query """ - SELECT count(blocks.inserted_at) - FROM blocks - WHERE blocks.inserted_at > NOW() - interval '1 minute' - """ - @transaction_velocity_query """ SELECT count(transactions.inserted_at) FROM transactions @@ -53,7 +47,6 @@ defmodule Explorer.Chain.Statistics do @typedoc """ * `average_time` - the average time it took to mine/validate the last <= 100 `t:Explorer.Chain.Block.t/0` - * `block_velocity` - the number of `t:Explorer.Chain.Block.t/0` mined/validated in the last minute * `blocks` - the last <= 5 `t:Explorer.Chain.Block.t/0` * `lag` - the average time over the last hour between when the block was mined/validated (`t:Explorer.Chain.Block.t/0` `timestamp`) and when it was inserted into the databasse @@ -66,7 +59,6 @@ defmodule Explorer.Chain.Statistics do """ @type t :: %__MODULE__{ average_time: Duration.t(), - block_velocity: blocks_per_minute(), blocks: [Block.t()], lag: Duration.t(), number: Block.block_number(), @@ -76,7 +68,6 @@ defmodule Explorer.Chain.Statistics do } defstruct average_time: %Duration{seconds: 0, megaseconds: 0, microseconds: 0}, - block_velocity: 0, blocks: [], lag: %Duration{seconds: 0, megaseconds: 0, microseconds: 0}, number: -1, @@ -105,7 +96,6 @@ defmodule Explorer.Chain.Statistics do %__MODULE__{ average_time: query_duration(@average_time_query), - block_velocity: query_value(@block_velocity_query), blocks: Repo.all(blocks), lag: query_duration(@lag_query), transaction_velocity: query_value(@transaction_velocity_query), diff --git a/apps/explorer/test/explorer/chain/statistics_test.exs b/apps/explorer/test/explorer/chain/statistics_test.exs index 78a5f90026..2333678f1f 100644 --- a/apps/explorer/test/explorer/chain/statistics_test.exs +++ b/apps/explorer/test/explorer/chain/statistics_test.exs @@ -53,16 +53,6 @@ defmodule Explorer.Chain.StatisticsTest do assert %Statistics{lag: %Duration{seconds: 5, megaseconds: 0, microseconds: 0}} = Statistics.fetch() end - test "returns the number of blocks inserted in the last minute" do - old_inserted_at = Timex.shift(DateTime.utc_now(), days: -1) - insert(:block, inserted_at: old_inserted_at) - insert(:block) - - statistics = Statistics.fetch() - - assert statistics.block_velocity == 1 - end - test "returns the number of transactions inserted in the last minute" do old_inserted_at = Timex.shift(DateTime.utc_now(), days: -1) insert(:transaction, inserted_at: old_inserted_at) From 9cd21b4bd9cbc15f67aa0c3e1b273638ee1e3481 Mon Sep 17 00:00:00 2001 From: Tim Mecklem Date: Tue, 26 Jun 2018 17:18:33 -0400 Subject: [PATCH 4/4] Remove unused lag query in statistics --- apps/explorer/lib/explorer/chain/statistics.ex | 14 -------------- .../test/explorer/chain/statistics_test.exs | 8 -------- 2 files changed, 22 deletions(-) diff --git a/apps/explorer/lib/explorer/chain/statistics.ex b/apps/explorer/lib/explorer/chain/statistics.ex index 57a7938228..0d058525be 100644 --- a/apps/explorer/lib/explorer/chain/statistics.ex +++ b/apps/explorer/lib/explorer/chain/statistics.ex @@ -19,16 +19,6 @@ defmodule Explorer.Chain.Statistics do ) t """ - @lag_query """ - SELECT coalesce(avg(lag), interval '0 seconds') - FROM ( - SELECT inserted_at - timestamp AS lag - FROM blocks - WHERE blocks.inserted_at > NOW() - interval '1 hour' - AND blocks.timestamp > NOW() - interval '1 hour' - ) t - """ - @transaction_velocity_query """ SELECT count(transactions.inserted_at) FROM transactions @@ -48,7 +38,6 @@ defmodule Explorer.Chain.Statistics do @typedoc """ * `average_time` - the average time it took to mine/validate the last <= 100 `t:Explorer.Chain.Block.t/0` * `blocks` - the last <= 5 `t:Explorer.Chain.Block.t/0` - * `lag` - the average time over the last hour between when the block was mined/validated (`t:Explorer.Chain.Block.t/0` `timestamp`) and when it was inserted into the databasse (`t:Explorer.Chain.Block.t/0` `inserted_at`) * `number` - the latest `t:Explorer.Chain.Block.t/0` `number` @@ -60,7 +49,6 @@ defmodule Explorer.Chain.Statistics do @type t :: %__MODULE__{ average_time: Duration.t(), blocks: [Block.t()], - lag: Duration.t(), number: Block.block_number(), timestamp: :calendar.datetime(), transaction_velocity: transactions_per_minute(), @@ -69,7 +57,6 @@ defmodule Explorer.Chain.Statistics do defstruct average_time: %Duration{seconds: 0, megaseconds: 0, microseconds: 0}, blocks: [], - lag: %Duration{seconds: 0, megaseconds: 0, microseconds: 0}, number: -1, timestamp: nil, transaction_velocity: 0, @@ -97,7 +84,6 @@ defmodule Explorer.Chain.Statistics do %__MODULE__{ average_time: query_duration(@average_time_query), blocks: Repo.all(blocks), - lag: query_duration(@lag_query), transaction_velocity: query_value(@transaction_velocity_query), transactions: transactions } diff --git a/apps/explorer/test/explorer/chain/statistics_test.exs b/apps/explorer/test/explorer/chain/statistics_test.exs index 2333678f1f..ba8a45a239 100644 --- a/apps/explorer/test/explorer/chain/statistics_test.exs +++ b/apps/explorer/test/explorer/chain/statistics_test.exs @@ -45,14 +45,6 @@ defmodule Explorer.Chain.StatisticsTest do } = Statistics.fetch() end - test "returns the lag between validation and insertion time" do - validation_time = DateTime.utc_now() - inserted_at = validation_time |> Timex.shift(seconds: 5) - insert(:block, timestamp: validation_time, inserted_at: inserted_at) - - assert %Statistics{lag: %Duration{seconds: 5, megaseconds: 0, microseconds: 0}} = Statistics.fetch() - end - test "returns the number of transactions inserted in the last minute" do old_inserted_at = Timex.shift(DateTime.utc_now(), days: -1) insert(:transaction, inserted_at: old_inserted_at)