Skip to content

Commit 152f3cd

Browse files
authored
Track missing vertex lookups in metrics (#3277)
When looking up a VertexID, the entry might not be present in the database - this is currently not tracked since the functionality is not commonly used - with path-based vertex id generation, we'll be making guesses however where empty lookups become "normal" - the same would happen for incomplete databases as well.
1 parent 6341f5f commit 152f3cd

File tree

8 files changed

+29
-13
lines changed

8 files changed

+29
-13
lines changed

execution_chain/db/aristo/aristo_desc/desc_structural.nim

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,9 @@ type
9090
## unfriendly to caches
9191

9292
const
93-
Leaves* = {AccLeaf, StoLeaf}
94-
Branches* = {Branch, ExtBranch}
93+
Leaves* = {VertexType.AccLeaf, VertexType.StoLeaf}
94+
Branches* = {VertexType.Branch, VertexType.ExtBranch}
95+
VertexTypes* = Leaves + Branches
9596

9697
# ------------------------------------------------------------------------------
9798
# Public helpers (misc)

execution_chain/db/aristo/aristo_init/memory_db.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ func memoryBackend*(): AristoDbRef =
208208

209209
iterator walkVtx*(
210210
be: MemBackendRef;
211-
kinds = {Branch, ExtBranch, AccLeaf, StoLeaf};
211+
kinds = VertexTypes;
212212
): tuple[rvid: RootedVertexID, vtx: VertexRef] =
213213
## Iteration over the vertex sub-table.
214214
for n,rvid in be.sTab.keys.toSeq.sorted:

execution_chain/db/aristo/aristo_init/rocks_db.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ proc rocksDbBackend*(
245245

246246
iterator walkVtx*(
247247
be: RdbBackendRef;
248-
kinds = {Branch, ExtBranch, AccLeaf, StoLeaf};
248+
kinds = VertexTypes;
249249
): tuple[evid: RootedVertexID, vtx: VertexRef] =
250250
## Variant of `walk()` iteration over the vertex sub-table.
251251
for (rvid, vtx) in be.rdb.walkVtx(kinds):

execution_chain/db/aristo/aristo_init/rocks_db/rdb_desc.nim

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,20 @@ type
7373
Account
7474
World
7575

76+
RdbVertexType* = enum
77+
Empty
78+
Leaf
79+
Branch
80+
ExtBranch
81+
7682
var
7783
# Hit/miss counters for LRU cache - global so as to integrate easily with
7884
# nim-metrics and `uint64` to ensure that increasing them is fast - collection
7985
# happens from a separate thread.
8086
# TODO maybe turn this into more general framework for LRU reporting since
8187
# we have lots of caches of this sort
8288
rdbBranchLruStats*: array[RdbStateType, RdbLruCounter]
83-
rdbVtxLruStats*: array[RdbStateType, array[VertexType, RdbLruCounter]]
89+
rdbVtxLruStats*: array[RdbStateType, array[RdbVertexType, RdbLruCounter]]
8490
rdbKeyLruStats*: array[RdbStateType, RdbLruCounter]
8591

8692
# ------------------------------------------------------------------------------
@@ -93,6 +99,12 @@ template toOpenArray*(xid: AdminTabID): openArray[byte] =
9399
template to*(v: RootedVertexID, T: type RdbStateType): RdbStateType =
94100
if v.root == VertexID(1): RdbStateType.World else: RdbStateType.Account
95101

102+
template to*(v: VertexType, T: type RdbVertexType): RdbVertexType =
103+
case v
104+
of VertexType.AccLeaf, VertexType.StoLeaf: RdbVertexType.Leaf
105+
of VertexType.Branch: RdbVertexType.Branch
106+
of VertexType.ExtBranch: RdbVertexType.ExtBranch
107+
96108
template inc*(v: var RdbLruCounter, hit: bool) =
97109
discard v[hit].fetchAdd(1, moRelaxed)
98110

execution_chain/db/aristo/aristo_init/rocks_db/rdb_get.nim

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ when defined(metrics):
6363
# We don't care about synchronization between each type of metric or between
6464
# the metrics thread and others since small differences like this don't matter
6565
for state in RdbStateType:
66-
for vtype in VertexType:
66+
for vtype in RdbVertexType:
6767
for hit in [false, true]:
6868
output(
6969
name = "aristo_rdb_vtx_lru_total",
@@ -198,7 +198,9 @@ proc getVtx*(
198198
rdb.rdVtxLru.get(rvid.vid)
199199

200200
if rc.isOk:
201-
rdbVtxLruStats[rvid.to(RdbStateType)][rc.value().vType].inc(true)
201+
rdbVtxLruStats[rvid.to(RdbStateType)][rc.value().vType.to(RdbVertexType)].inc(
202+
true
203+
)
202204
return ok(move(rc.value))
203205

204206
# Otherwise fetch from backend database
@@ -214,8 +216,7 @@ proc getVtx*(
214216
return err((errSym, error))
215217

216218
if not gotData:
217-
# As a hack, we count missing data as leaf nodes
218-
rdbVtxLruStats[rvid.to(RdbStateType)][VertexType.StoLeaf].inc(false)
219+
rdbVtxLruStats[rvid.to(RdbStateType)][RdbVertexType.Empty].inc(false)
219220
return ok(VertexRef(nil))
220221

221222
if res.isErr():
@@ -224,7 +225,9 @@ proc getVtx*(
224225
if res.value.vType == Branch:
225226
rdbBranchLruStats[rvid.to(RdbStateType)].inc(false)
226227
else:
227-
rdbVtxLruStats[rvid.to(RdbStateType)][res.value().vType].inc(false)
228+
rdbVtxLruStats[rvid.to(RdbStateType)][res.value().vType.to(RdbVertexType)].inc(
229+
false
230+
)
228231

229232
# Update cache and return - in peek mode, avoid evicting cache items
230233
if GetVtxFlag.PeekCache notin flags:

execution_chain/db/aristo/aristo_init/rocks_db/rdb_init.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ proc dumpCacheStats(keySize, vtxSize, branchSize: int) =
2727
echo "vtxLru(", vtxSize, ")"
2828
echo " state vtype miss hit total hitrate"
2929
for state in RdbStateType:
30-
for vtype in VertexType:
30+
for vtype in RdbVertexType:
3131
let
3232
(miss, hit) = (
3333
rdbVtxLruStats[state][vtype].get(false),

execution_chain/db/aristo/aristo_walk/memory_only.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export
2929
iterator walkVtxBe*[T: MemBackendRef](
3030
_: type T;
3131
db: AristoDbRef;
32-
kinds = {Branch, ExtBranch, AccLeaf, StoLeaf};
32+
kinds = VertexTypes;
3333
): tuple[rvid: RootedVertexID, vtx: VertexRef] =
3434
## Iterate over filtered memory backend or backend-less vertices. This
3535
## function depends on the particular backend type name which must match

execution_chain/db/aristo/aristo_walk/persistent.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export
3434
iterator walkVtxBe*[T: RdbBackendRef](
3535
_: type T;
3636
db: AristoDbRef;
37-
kinds = {Branch, ExtBranch, AccLeaf, StoLeaf};
37+
kinds = VertexTypes;
3838
): tuple[rvid: RootedVertexID, vtx: VertexRef] =
3939
## Iterate over RocksDB backend vertices. This function depends on
4040
## the particular backend type name which must match the backend descriptor.

0 commit comments

Comments
 (0)