mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-14 16:03:45 +00:00
metric radius rate
This commit is contained in:
parent
9b9d666dc4
commit
c5d13e4b74
1 changed files with 20 additions and 0 deletions
|
|
@ -14,12 +14,17 @@ import (
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||||
"github.com/ethereum/go-ethereum/log"
|
"github.com/ethereum/go-ethereum/log"
|
||||||
|
"github.com/ethereum/go-ethereum/metrics"
|
||||||
"github.com/ethereum/go-ethereum/p2p/enode"
|
"github.com/ethereum/go-ethereum/p2p/enode"
|
||||||
"github.com/ethereum/go-ethereum/portalnetwork/storage"
|
"github.com/ethereum/go-ethereum/portalnetwork/storage"
|
||||||
"github.com/holiman/uint256"
|
"github.com/holiman/uint256"
|
||||||
"github.com/mattn/go-sqlite3"
|
"github.com/mattn/go-sqlite3"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
radiusRatio metrics.GaugeFloat64
|
||||||
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
sqliteName = "history.sqlite"
|
sqliteName = "history.sqlite"
|
||||||
contentDeletionFraction = 0.05 // 5% of the content will be deleted when the storage capacity is hit and radius gets adjusted.
|
contentDeletionFraction = 0.05 // 5% of the content will be deleted when the storage capacity is hit and radius gets adjusted.
|
||||||
|
|
@ -107,6 +112,10 @@ func NewHistoryStorage(config storage.PortalStorageConfig) (storage.ContentStora
|
||||||
log: log.New("storage", config.NetworkName),
|
log: log.New("storage", config.NetworkName),
|
||||||
}
|
}
|
||||||
hs.radius.Store(storage.MaxDistance)
|
hs.radius.Store(storage.MaxDistance)
|
||||||
|
if metrics.Enabled {
|
||||||
|
radiusRatio = metrics.NewRegisteredGaugeFloat64("portal/radius_ratio", nil)
|
||||||
|
radiusRatio.Update(1)
|
||||||
|
}
|
||||||
err := hs.createTable()
|
err := hs.createTable()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
@ -332,6 +341,12 @@ func (p *ContentStorage) EstimateNewRadius(currentRadius *uint256.Int) (*uint256
|
||||||
sizeRatio := currrentSize / p.storageCapacityInBytes
|
sizeRatio := currrentSize / p.storageCapacityInBytes
|
||||||
if sizeRatio > 0 {
|
if sizeRatio > 0 {
|
||||||
bigFormat := new(big.Int).SetUint64(sizeRatio)
|
bigFormat := new(big.Int).SetUint64(sizeRatio)
|
||||||
|
if metrics.Enabled {
|
||||||
|
newRadius := new(uint256.Int).Div(currentRadius, uint256.MustFromBig(bigFormat))
|
||||||
|
newRadius.Mul(newRadius, uint256.NewInt(100))
|
||||||
|
newRadius.Mod(newRadius, storage.MaxDistance)
|
||||||
|
radiusRatio.Update(newRadius.Float64() / 100)
|
||||||
|
}
|
||||||
return new(uint256.Int).Div(currentRadius, uint256.MustFromBig(bigFormat)), nil
|
return new(uint256.Int).Div(currentRadius, uint256.MustFromBig(bigFormat)), nil
|
||||||
}
|
}
|
||||||
return currentRadius, nil
|
return currentRadius, nil
|
||||||
|
|
@ -391,6 +406,11 @@ func (p *ContentStorage) deleteContentFraction(fraction float64) (deleteCount in
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
p.radius.Store(dis)
|
p.radius.Store(dis)
|
||||||
|
if metrics.Enabled {
|
||||||
|
dis.Mul(dis, uint256.NewInt(100))
|
||||||
|
dis.Mod(dis, storage.MaxDistance)
|
||||||
|
radiusRatio.Update(dis.Float64() / 100)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// row must close first, or database is locked
|
// row must close first, or database is locked
|
||||||
// rows.Close() can call multi times
|
// rows.Close() can call multi times
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue