Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add metrics: balance per currency, number of unspent outputs, number of addresses #1666

Closed
wants to merge 3 commits into from

Conversation

unnawut
Copy link
Contributor

@unnawut unnawut commented Jul 23, 2020

Close #1148

Overview

Add metrics for childchain's balances, number of unspent outputs and addresses with unspent outputs.

image

Changes

  • Adds total_unspent_outputs: The total number of unspent outputs being tracked in the childchain service
  • Adds total_unspent_addresses: The total number of addresses holding at least 1 unspent output
  • Updates balance: Same definition. Fixed where the balance was calculating only from the recent cache
  • Removes unique_users: Replaced by total_unspent_addresses

Note that I originally wanted to avoid or optimize utxos calling but it requires lower level opimization and the current DB can handle the load for the foreseeable future (see #1667 for some benchmark).

With this PR we get the utxos db observability and can monitor when the metrics become concerning so I think it's worth the extra call.

Testing

Follow these steps:

  1. Configure DD_DISABLED: false and DD_API_KEY at least on the childchain
  2. Run make docker-build
  3. Run cd priv/cabbage && make start_daemon_services-2
  4. Make some deposits and transfers
  5. The 3 metrics should be reported

@unnawut unnawut self-assigned this Jul 23, 2020
@unnawut unnawut mentioned this pull request Jul 24, 2020
23 tasks
end

defp collect_stats(db) do
{:ok, utxos} = db.utxos()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't this like the worst query you could make? pull millions of records into memory?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup! Without revamping the data structure, we can chunk-calculate this, but that means a full table scan for each query, e.g. one to group by currency, another one to group by address, etc. and that's read-heavy on rocksdb which is even more severe than being memory-intensive.

And we need utxoset observability so 🤷‍♂️

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually hang on, lemme try create OMG.DB.RocksDB.reduce() that processes each utxo while it iterates through the full utxoset.

@unnawut unnawut marked this pull request as draft August 24, 2020 08:38
@unnawut
Copy link
Contributor Author

unnawut commented Sep 16, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Calculate metrics on lazily loaded UTXO set
2 participants