-
Notifications
You must be signed in to change notification settings - Fork 253
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
Metrics (Objects): Blocks, transactions, receipts and accounts (state) reads/writes #916
base: release/maindbv4
Are you sure you want to change the base?
Changes from 12 commits
822eb97
a751385
e5df4aa
d1ddff0
f801be2
4bb278a
8d1488a
64b9219
98228a5
2b7e909
0cca5f3
9025c5f
db0f469
01aff2c
bdedf37
6dd54f7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// Copyright (c) 2024 The VeChainThor developers | ||
// | ||
// Distributed under the GNU Lesser General Public License v3.0 software license, see the accompanying | ||
// file LICENSE or <https://www.gnu.org/licenses/lgpl-3.0.html> | ||
|
||
package state | ||
|
||
import "github.com/vechain/thor/v2/metrics" | ||
|
||
var metricAccountCounter = metrics.LazyLoadCounterVec("account_state_count", []string{"type", "target"}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -120,6 +120,7 @@ func (s *State) getCachedObject(addr thor.Address) (*cachedObject, error) { | |
if err != nil { | ||
return nil, err | ||
} | ||
metricAccountCounter().AddWithLabel(1, map[string]string{"type": "read", "target": "trie"}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This might not be reflecting the real calling path, but just for demonstrating the path from state to the trie package. I would suggest consider in the low-level packages other than this one. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The problem of this approach is that we miss the concept of object, so at the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's solve this offline. |
||
co := newCachedObject(s.db, addr, a, am) | ||
s.cache[addr] = co | ||
return co, nil | ||
|
@@ -131,6 +132,7 @@ func (s *State) getAccount(addr thor.Address) (*Account, error) { | |
if err != nil { | ||
return nil, err | ||
} | ||
metricAccountCounter().AddWithLabel(1, map[string]string{"type": "read", "target": "stackedmap"}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, will get rid of the |
||
return v.(*Account), nil | ||
} | ||
|
||
|
@@ -538,6 +540,8 @@ func (s *State) Stage(newVer trie.Version) (*Stage, error) { | |
return err | ||
} | ||
} | ||
// Just once for the account trie. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would suggest avoid including metrics in state, as it's the primitive operation and all the metrics will be fallen into trie node cache. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (Copying this conversation here so others could have this context too) let me elaborate a bit more over the code: https://github.com/vechain/thor/blob/miguel/object-write-read2/state/state.go
hope I managed to explain it properly. or if you see I am missing something in my argument please let me know There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for the explanation, I was proposed avoiding including metrics in the state package, reason for that is avoiding potential huge overhead and all state operations are trie operations. Since we already got metrics in the trie package, why don't leave state package without metrics. Secondly, commit function usually being called for every block processing, I would suggest remove this metric. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The idea of having these metrics here is because of the object, in this case |
||
metricAccountCounter().AddWithLabel(int64(len(changes)), map[string]string{"type": "write", "target": "trie"}) | ||
return nil | ||
}, | ||
}, nil | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we already have similar metrics in PR #910?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These metrics are per object, as described in the title. I do not know why #910 was done since cache miss/rate was already covered by this.
But it is true that this other cache looks like a duplicate since it is placed precisely in receipts, transactions and so on with the difference that only applies to reads.
I can align both things. Wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would have put this metric here, but I also wanted to record the domain cache/hit, ie
blocks
,transactions
orreceipts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After looking into the names, now I understand the purpose of them. Regarding
Reads
, I would suggest leveragecache.hit
+cache.miss
. RegardingWrites
I would consider they are immutable based on the blocks imported. Is write inevitable from your point of view?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is indeed a duplicate, the thing is I was working on this ticket so as you can imagine I was not expecting someone else doing the same thing.
About
Writes
, you mean block-wise or also for the other "objects" (tx, receipts...)? Regarding blocks, the metric is only submitted to Prometheus when callingAddBlock
. Not sure what you mean by "inevitable", should not we record them?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nah, I might use wrong word regarding 'inevitable', I was thinking that writing to block/transaction/receipt was deterministic.