Add pruning metrics (#1093)
This commit is contained in:
parent
56c3e31efc
commit
6a9d875fe7
|
@ -62,6 +62,7 @@ type
|
||||||
of DbPruned:
|
of DbPruned:
|
||||||
furthestStoredElementDistance*: UInt256
|
furthestStoredElementDistance*: UInt256
|
||||||
fractionOfDeletedContent*: float64
|
fractionOfDeletedContent*: float64
|
||||||
|
numOfDeletedElements*: int64
|
||||||
|
|
||||||
# Objects must be sorted from largest to closest distance
|
# Objects must be sorted from largest to closest distance
|
||||||
proc `<`(a, b: ObjInfo): bool =
|
proc `<`(a, b: ObjInfo): bool =
|
||||||
|
@ -212,7 +213,7 @@ proc del*(db: ContentDB, key: ContentId) =
|
||||||
proc deleteFractionOfContent(
|
proc deleteFractionOfContent(
|
||||||
db: ContentDB,
|
db: ContentDB,
|
||||||
target: Uint256,
|
target: Uint256,
|
||||||
targetFraction: float64): (UInt256, int64, int64) =
|
targetFraction: float64): (UInt256, int64, int64, int64) =
|
||||||
## Procedure which tries to delete fraction of database by scanning maxObjPerScan
|
## Procedure which tries to delete fraction of database by scanning maxObjPerScan
|
||||||
## furthest elements.
|
## furthest elements.
|
||||||
## If the maxObjPerScan furthest elements, is not enough to attain required fraction
|
## If the maxObjPerScan furthest elements, is not enough to attain required fraction
|
||||||
|
@ -224,10 +225,11 @@ proc deleteFractionOfContent(
|
||||||
var bytesDeleted: int64 = 0
|
var bytesDeleted: int64 = 0
|
||||||
let bytesToDelete = int64(targetFraction * float64(totalContentSize))
|
let bytesToDelete = int64(targetFraction * float64(totalContentSize))
|
||||||
let numOfElements = len(furthestElements)
|
let numOfElements = len(furthestElements)
|
||||||
|
var numOfDeletedElements: int64 = 0
|
||||||
|
|
||||||
if numOfElements == 0:
|
if numOfElements == 0:
|
||||||
# no elements in database, return some zero value
|
# no elements in database, return some zero value
|
||||||
return (UInt256.zero, 0'i64, 0'i64)
|
return (UInt256.zero, 0'i64, 0'i64, 0'i64)
|
||||||
|
|
||||||
let lastIdx = len(furthestElements) - 1
|
let lastIdx = len(furthestElements) - 1
|
||||||
|
|
||||||
|
@ -235,13 +237,14 @@ proc deleteFractionOfContent(
|
||||||
if i == lastIdx:
|
if i == lastIdx:
|
||||||
# this is our last element, do not delete it and report it as last non deleted
|
# this is our last element, do not delete it and report it as last non deleted
|
||||||
# element
|
# element
|
||||||
return (elem.distFrom, bytesDeleted, totalContentSize)
|
return (elem.distFrom, bytesDeleted, totalContentSize, numOfDeletedElements)
|
||||||
|
|
||||||
if bytesDeleted + elem.payloadLength < bytesToDelete:
|
if bytesDeleted + elem.payloadLength < bytesToDelete:
|
||||||
db.del(elem.contentId)
|
db.del(elem.contentId)
|
||||||
bytesDeleted = bytesDeleted + elem.payloadLength
|
bytesDeleted = bytesDeleted + elem.payloadLength
|
||||||
|
inc numOfDeletedElements
|
||||||
else:
|
else:
|
||||||
return (elem.distFrom, bytesDeleted, totalContentSize)
|
return (elem.distFrom, bytesDeleted, totalContentSize, numOfDeletedElements)
|
||||||
|
|
||||||
proc put*(
|
proc put*(
|
||||||
db: ContentDB,
|
db: ContentDB,
|
||||||
|
@ -257,7 +260,12 @@ proc put*(
|
||||||
return PutResult(kind: ContentStored)
|
return PutResult(kind: ContentStored)
|
||||||
else:
|
else:
|
||||||
# TODO Add some configuration for this magic number
|
# TODO Add some configuration for this magic number
|
||||||
let (furthestNonDeletedElement, deletedBytes, totalContentSize) =
|
let (
|
||||||
|
furthestNonDeletedElement,
|
||||||
|
deletedBytes,
|
||||||
|
totalContentSize,
|
||||||
|
deletedElements
|
||||||
|
) =
|
||||||
db.deleteFractionOfContent(target, 0.25)
|
db.deleteFractionOfContent(target, 0.25)
|
||||||
|
|
||||||
let deletedFraction = float64(deletedBytes) / float64(totalContentSize)
|
let deletedFraction = float64(deletedBytes) / float64(totalContentSize)
|
||||||
|
@ -267,4 +275,5 @@ proc put*(
|
||||||
return PutResult(
|
return PutResult(
|
||||||
kind: DbPruned,
|
kind: DbPruned,
|
||||||
furthestStoredElementDistance: furthestNonDeletedElement,
|
furthestStoredElementDistance: furthestNonDeletedElement,
|
||||||
fractionOfDeletedContent: deletedFraction)
|
fractionOfDeletedContent: deletedFraction,
|
||||||
|
numOfDeletedElements: deletedElements)
|
||||||
|
|
|
@ -2089,6 +2089,99 @@
|
||||||
"align": false,
|
"align": false,
|
||||||
"alignLevel": null
|
"alignLevel": null
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"datasource": null,
|
||||||
|
"fieldConfig": {
|
||||||
|
"defaults": {
|
||||||
|
"color": {
|
||||||
|
"mode": "palette-classic"
|
||||||
|
},
|
||||||
|
"custom": {
|
||||||
|
"axisLabel": "",
|
||||||
|
"axisPlacement": "auto",
|
||||||
|
"barAlignment": 0,
|
||||||
|
"drawStyle": "line",
|
||||||
|
"fillOpacity": 0,
|
||||||
|
"gradientMode": "none",
|
||||||
|
"hideFrom": {
|
||||||
|
"legend": false,
|
||||||
|
"tooltip": false,
|
||||||
|
"viz": false
|
||||||
|
},
|
||||||
|
"lineInterpolation": "linear",
|
||||||
|
"lineWidth": 1,
|
||||||
|
"pointSize": 5,
|
||||||
|
"scaleDistribution": {
|
||||||
|
"log": 2,
|
||||||
|
"type": "log"
|
||||||
|
},
|
||||||
|
"showPoints": "auto",
|
||||||
|
"spanNulls": false,
|
||||||
|
"stacking": {
|
||||||
|
"group": "A",
|
||||||
|
"mode": "none"
|
||||||
|
},
|
||||||
|
"thresholdsStyle": {
|
||||||
|
"mode": "off"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"mappings": [],
|
||||||
|
"thresholds": {
|
||||||
|
"mode": "absolute",
|
||||||
|
"steps": [
|
||||||
|
{
|
||||||
|
"color": "green",
|
||||||
|
"value": null
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"color": "red",
|
||||||
|
"value": 80
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"overrides": []
|
||||||
|
},
|
||||||
|
"gridPos": {
|
||||||
|
"h": 8,
|
||||||
|
"w": 12,
|
||||||
|
"x": 0,
|
||||||
|
"y": 77
|
||||||
|
},
|
||||||
|
"id": 48,
|
||||||
|
"options": {
|
||||||
|
"legend": {
|
||||||
|
"calcs": [],
|
||||||
|
"displayMode": "list",
|
||||||
|
"placement": "bottom"
|
||||||
|
},
|
||||||
|
"tooltip": {
|
||||||
|
"mode": "single",
|
||||||
|
"sort": "none"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"targets": [
|
||||||
|
{
|
||||||
|
"editorMode": "code",
|
||||||
|
"exemplar": true,
|
||||||
|
"expr": "portal_pruning_counter_total{protocol_id=\"500b\"}",
|
||||||
|
"legendFormat": "Number of pruning event",
|
||||||
|
"range": true,
|
||||||
|
"refId": "A"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"editorMode": "code",
|
||||||
|
"exemplar": true,
|
||||||
|
"expr": "portal_pruning_deleted_elements{protocol_id=\"500b\"}",
|
||||||
|
"hide": false,
|
||||||
|
"legendFormat": "Number of elements deleted in pruning event",
|
||||||
|
"range": true,
|
||||||
|
"refId": "B"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"title": "History network pruning statistics",
|
||||||
|
"type": "timeseries"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"refresh": "5s",
|
"refresh": "5s",
|
||||||
|
|
|
@ -79,6 +79,14 @@ declareHistogram portal_content_enrs_packed,
|
||||||
"Portal wire protocol amount of enrs packed in a content message",
|
"Portal wire protocol amount of enrs packed in a content message",
|
||||||
labels = ["protocol_id"], buckets = enrsBuckets
|
labels = ["protocol_id"], buckets = enrsBuckets
|
||||||
|
|
||||||
|
declareCounter portal_pruning_counter,
|
||||||
|
"Number of pruning event which happened during node lifetime",
|
||||||
|
labels = ["protocol_id"]
|
||||||
|
|
||||||
|
declareGauge portal_pruning_deleted_elements,
|
||||||
|
"Number of elements delted in last pruning",
|
||||||
|
labels = ["protocol_id"]
|
||||||
|
|
||||||
logScope:
|
logScope:
|
||||||
topics = "portal_wire"
|
topics = "portal_wire"
|
||||||
|
|
||||||
|
@ -437,7 +445,6 @@ proc getInitialRadius(rc: RadiusConfig): UInt256 =
|
||||||
# from database after a restart
|
# from database after a restart
|
||||||
return UInt256.high()
|
return UInt256.high()
|
||||||
|
|
||||||
|
|
||||||
proc new*(T: type PortalProtocol,
|
proc new*(T: type PortalProtocol,
|
||||||
baseProtocol: protocol.Protocol,
|
baseProtocol: protocol.Protocol,
|
||||||
protocolId: PortalProtocolId,
|
protocolId: PortalProtocolId,
|
||||||
|
@ -1133,6 +1140,12 @@ proc storeContent*(p: PortalProtocol, key: ContentId, content: openArray[byte])
|
||||||
# radius to store network fraction corresponding to those storage limits.
|
# radius to store network fraction corresponding to those storage limits.
|
||||||
let res = p.contentDB.put(key, content, p.baseProtocol.localNode.id)
|
let res = p.contentDB.put(key, content, p.baseProtocol.localNode.id)
|
||||||
if res.kind == DbPruned:
|
if res.kind == DbPruned:
|
||||||
|
portal_pruning_counter.inc(labelValues = [$p.protocolId])
|
||||||
|
portal_pruning_deleted_elements.set(
|
||||||
|
res.numOfDeletedElements.int64,
|
||||||
|
labelValues = [$p.protocolId]
|
||||||
|
)
|
||||||
|
|
||||||
p.adjustRadius(
|
p.adjustRadius(
|
||||||
res.fractionOfDeletedContent,
|
res.fractionOfDeletedContent,
|
||||||
res.furthestStoredElementDistance
|
res.furthestStoredElementDistance
|
||||||
|
|
|
@ -182,6 +182,7 @@ suite "Content Database":
|
||||||
pr10.kind == DbPruned
|
pr10.kind == DbPruned
|
||||||
|
|
||||||
check:
|
check:
|
||||||
|
pr10.numOfDeletedElements == 2
|
||||||
uint32(db.size()) < maxDbSize
|
uint32(db.size()) < maxDbSize
|
||||||
# With current settings 2 furthers elements will be delted i.e 30 and 40
|
# With current settings 2 furthers elements will be delted i.e 30 and 40
|
||||||
# so the furthest non deleted one will be 20
|
# so the furthest non deleted one will be 20
|
||||||
|
|
Loading…
Reference in New Issue