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

[WIP] diagnostics: additional peer info #12488

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
9 changes: 7 additions & 2 deletions erigon-lib/diagnostics/entities.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,13 @@ type FileDownloadedStatisticsUpdate struct {
}

type SegmentPeer struct {
Url string `json:"url"`
DownloadRate uint64 `json:"downloadRate"`
Url string `json:"url"`
DownloadRate uint64 `json:"downloadRate"`
UploadRate uint64 `json:"uploadRate"`
PiecesCount uint64 `json:"piecesCount"`
RemoteAddr string `json:"remoteAddr"`
PeerId [20]byte `json:"peerId"`
TorrentName string `json:"torrentName"`
}

type SnapshotIndexingStatistics struct {
Expand Down
48 changes: 31 additions & 17 deletions erigon-lib/downloader/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -1570,7 +1570,7 @@ func (d *Downloader) torrentDownload(t *torrent.Torrent, statusChan chan downloa
return
case <-t.Complete.On():
downloadTime := time.Since(downloadStarted)
downloaded := t.Stats().BytesReadUsefulData
downloaded := t.Stats().BytesCompleted

diagnostics.Send(diagnostics.FileDownloadedStatisticsUpdate{
FileName: t.Name(),
Expand Down Expand Up @@ -2294,7 +2294,7 @@ func (d *Downloader) ReCalcStats(interval time.Duration) {
d.lock.Unlock()

if !stats.Completed {
logger.Debug("[snapshots] downloading",
log.Info("[1snapshots] downloading",
"len", len(torrents),
"webTransfers", webTransfers,
"torrent", torrentInfo,
Expand All @@ -2306,6 +2306,8 @@ func (d *Downloader) ReCalcStats(interval time.Duration) {
"completion-rate", fmt.Sprintf("%s/s", common.ByteCount(stats.CompletionRate)),
"flushed", common.ByteCount(stats.BytesFlushed),
"flush-rate", fmt.Sprintf("%s/s", common.ByteCount(stats.FlushRate)),
"downloaded", common.ByteCount(stats.BytesDownload),
"download-rate", fmt.Sprintf("%s/s", common.ByteCount(stats.DownloadRate)),
"webseed-trips", stats.WebseedTripCount.Load(),
"webseed-active", stats.WebseedActiveTrips.Load(),
"webseed-max-active", stats.WebseedMaxActiveTrips.Load(),
Expand Down Expand Up @@ -2375,10 +2377,16 @@ func getWebseedsRatesForlogs(weebseedPeersOfThisFile []*torrent.Peer, fName stri
if peerUrl, err := webPeerUrl(peer); err == nil {
if shortUrl, err := url.JoinPath(peerUrl.Host, peerUrl.Path); err == nil {
rate := uint64(peer.DownloadRate())
//upRate := uint64(peer.UploadRate()) - TODO: uncomment when torrent lib wil be fixed
if !finished {
seed := diagnostics.SegmentPeer{
Url: peerUrl.Host,
DownloadRate: rate,
UploadRate: 0,
RemoteAddr: peer.RemoteAddr.String(),
PeerId: [20]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
PiecesCount: 0,
TorrentName: fName,
}
seeds = append(seeds, seed)
}
Expand All @@ -2402,11 +2410,17 @@ func getPeersRatesForlogs(peersOfThisFile []*torrent.PeerConn, fName string) ([]

for _, peer := range peersOfThisFile {
dr := uint64(peer.DownloadRate())
//ur := uint64(peer.UploadRate()) - TODO: uncomment when torrent lib wil be fixed
url := fmt.Sprintf("%v", peer.PeerClientName.Load())

segPeer := diagnostics.SegmentPeer{
Url: url,
DownloadRate: dr,
UploadRate: 0,
PiecesCount: peer.PeerPieces().GetCardinality(),
RemoteAddr: peer.RemoteAddr.String(),
PeerId: peer.PeerID,
TorrentName: fName,
}
peers = append(peers, segPeer)
rates = append(rates, url, fmt.Sprintf("%s/s", common.ByteCount(dr)))
Expand Down Expand Up @@ -2905,22 +2919,22 @@ func (d *Downloader) logProgress() {
"completion-rate", fmt.Sprintf("%s/s", common.ByteCount(d.stats.CompletionRate)),
"alloc", common.ByteCount(m.Alloc),
"sys", common.ByteCount(m.Sys))

diagnostics.Send(diagnostics.SnapshotDownloadStatistics{
Downloaded: bytesDone,
Total: d.stats.BytesTotal,
TotalTime: time.Since(d.startTime).Round(time.Second).Seconds(),
DownloadRate: d.stats.DownloadRate,
UploadRate: d.stats.UploadRate,
Peers: d.stats.PeersUnique,
Files: d.stats.FilesTotal,
Connections: d.stats.ConnectionsTotal,
Alloc: m.Alloc,
Sys: m.Sys,
DownloadFinished: d.stats.Completed,
TorrentMetadataReady: d.stats.MetadataReady,
})
}

diagnostics.Send(diagnostics.SnapshotDownloadStatistics{
Downloaded: bytesDone,
Total: d.stats.BytesTotal,
TotalTime: time.Since(d.startTime).Round(time.Second).Seconds(),
DownloadRate: d.stats.DownloadRate,
UploadRate: d.stats.UploadRate,
Peers: d.stats.PeersUnique,
Files: d.stats.FilesTotal,
Connections: d.stats.ConnectionsTotal,
Alloc: m.Alloc,
Sys: m.Sys,
DownloadFinished: d.stats.Completed,
TorrentMetadataReady: d.stats.MetadataReady,
})
}

func calculateTime(amountLeft, rate uint64) string {
Expand Down
8 changes: 4 additions & 4 deletions erigon-lib/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ require (
github.com/alecthomas/atomic v0.1.0-alpha2 // indirect
github.com/anacrolix/chansync v0.3.0 // indirect
github.com/anacrolix/envpprof v1.3.0 // indirect
github.com/anacrolix/generics v0.0.0-20230816105729-c755655aee45 // indirect
github.com/anacrolix/generics v0.0.2-0.20240227122613-f95486179cab // indirect
github.com/anacrolix/missinggo v1.3.0 // indirect
github.com/anacrolix/missinggo/perf v1.0.0 // indirect
github.com/anacrolix/missinggo/v2 v2.7.2-0.20230527121029-a582b4f397b9 // indirect
github.com/anacrolix/missinggo/v2 v2.7.3 // indirect
github.com/anacrolix/mmsg v1.0.0 // indirect
github.com/anacrolix/multiless v0.3.1-0.20221221005021-2d12701f83f7 // indirect
github.com/anacrolix/stm v0.4.1-0.20221221005312-96d17df0e496 // indirect
Expand All @@ -97,7 +97,7 @@ require (
github.com/docker/go-units v0.5.0 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/go-llsqlite/adapter v0.0.0-20230927005056-7f5ce7f0c916 // indirect
github.com/go-llsqlite/crawshaw v0.4.0 // indirect
github.com/go-llsqlite/crawshaw v0.5.2-0.20240425034140-f30eb7704568 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
Expand Down Expand Up @@ -153,7 +153,7 @@ require (
)

replace (
github.com/anacrolix/torrent => github.com/erigontech/torrent v1.54.2-alpha-38
github.com/anacrolix/torrent => github.com/erigontech/torrent v1.54.2
github.com/holiman/bloomfilter/v2 => github.com/AskAlexSharov/bloomfilter/v2 v2.0.8
github.com/tidwall/btree => github.com/AskAlexSharov/btree v1.6.2
)
16 changes: 8 additions & 8 deletions erigon-lib/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ github.com/anacrolix/envpprof v1.0.0/go.mod h1:KgHhUaQMc8cC0+cEflSgCFNFbKwi5h54g
github.com/anacrolix/envpprof v1.1.0/go.mod h1:My7T5oSqVfEn4MD4Meczkw/f5lSIndGAKu/0SM/rkf4=
github.com/anacrolix/envpprof v1.3.0 h1:WJt9bpuT7A/CDCxPOv/eeZqHWlle/Y0keJUvc6tcJDk=
github.com/anacrolix/envpprof v1.3.0/go.mod h1:7QIG4CaX1uexQ3tqd5+BRa/9e2D02Wcertl6Yh0jCB0=
github.com/anacrolix/generics v0.0.0-20230816105729-c755655aee45 h1:Kmcl3I9K2+5AdnnR7hvrnVT0TLeFWWMa9bxnm55aVIg=
github.com/anacrolix/generics v0.0.0-20230816105729-c755655aee45/go.mod h1:ff2rHB/joTV03aMSSn/AZNnaIpUw0h3njetGsaXcMy8=
github.com/anacrolix/generics v0.0.2-0.20240227122613-f95486179cab h1:MvuAC/UJtcohN6xWc8zYXSZfllh1LVNepQ0R3BCX5I4=
github.com/anacrolix/generics v0.0.2-0.20240227122613-f95486179cab/go.mod h1:ff2rHB/joTV03aMSSn/AZNnaIpUw0h3njetGsaXcMy8=
github.com/anacrolix/go-libutp v1.3.1 h1:idJzreNLl+hNjGC3ZnUOjujEaryeOGgkwHLqSGoige0=
github.com/anacrolix/go-libutp v1.3.1/go.mod h1:heF41EC8kN0qCLMokLBVkB8NXiLwx3t8R8810MTNI5o=
github.com/anacrolix/log v0.3.0/go.mod h1:lWvLTqzAnCWPJA08T2HCstZi0L1y2Wyvm3FJgwU9jwU=
Expand All @@ -62,8 +62,8 @@ github.com/anacrolix/missinggo/perf v1.0.0/go.mod h1:ljAFWkBuzkO12MQclXzZrosP5ur
github.com/anacrolix/missinggo/v2 v2.2.0/go.mod h1:o0jgJoYOyaoYQ4E2ZMISVa9c88BbUBVQQW4QeRkNCGY=
github.com/anacrolix/missinggo/v2 v2.5.1/go.mod h1:WEjqh2rmKECd0t1VhQkLGTdIWXO6f6NLjp5GlMZ+6FA=
github.com/anacrolix/missinggo/v2 v2.5.2/go.mod h1:yNvsLrtZYRYCOI+KRH/JM8TodHjtIE/bjOGhQaLOWIE=
github.com/anacrolix/missinggo/v2 v2.7.2-0.20230527121029-a582b4f397b9 h1:W/oGeHhYwxueeiDjQfmK9G+X9M2xJgfTtow62v0TWAs=
github.com/anacrolix/missinggo/v2 v2.7.2-0.20230527121029-a582b4f397b9/go.mod h1:mIEtp9pgaXqt8VQ3NQxFOod/eQ1H0D1XsZzKUQfwtac=
github.com/anacrolix/missinggo/v2 v2.7.3 h1:Ee//CmZBMadeNiYB/hHo9ly2PFOEZ4Fhsbnug3rDAIE=
github.com/anacrolix/missinggo/v2 v2.7.3/go.mod h1:mIEtp9pgaXqt8VQ3NQxFOod/eQ1H0D1XsZzKUQfwtac=
github.com/anacrolix/mmsg v0.0.0-20180515031531-a4a3ba1fc8bb/go.mod h1:x2/ErsYUmT77kezS63+wzZp8E3byYB0gzirM/WMBLfw=
github.com/anacrolix/mmsg v1.0.0 h1:btC7YLjOn29aTUAExJiVUhQOuf/8rhm+/nWCMAnL3Hg=
github.com/anacrolix/mmsg v1.0.0/go.mod h1:x8kRaJY/dCrY9Al0PEcj1mb/uFHwP6GCJ9fLl4thEPc=
Expand Down Expand Up @@ -158,8 +158,8 @@ github.com/erigontech/secp256k1 v1.1.0 h1:mO3YJMUSoASE15Ya//SoHiisptUhdXExuMUN1M
github.com/erigontech/secp256k1 v1.1.0/go.mod h1:GokhPepsMB+EYDs7I5JZCprxHW6+yfOcJKaKtoZ+Fls=
github.com/erigontech/speedtest v0.0.2 h1:W9Cvky/8AMUtUONwkLA/dZjeQ2XfkBdYfJzvhMZUO+U=
github.com/erigontech/speedtest v0.0.2/go.mod h1:vulsRNiM51BmSTbVtch4FWxKxx53pS2D35lZTtao0bw=
github.com/erigontech/torrent v1.54.2-alpha-38 h1:0KQTLlotAWy63MuyUatAzvIYwULYMSHI51A8Jl+3TC4=
github.com/erigontech/torrent v1.54.2-alpha-38/go.mod h1:QtK2WLdEz1Iy1Dh/325UltdHU0nA1xujh2rN6aov6y0=
github.com/erigontech/torrent v1.54.2 h1:oZCD1l96J7ei3780qHzMgOu+8GlW79J0t9tU1nx4o+U=
github.com/erigontech/torrent v1.54.2/go.mod h1:QtK2WLdEz1Iy1Dh/325UltdHU0nA1xujh2rN6aov6y0=
github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM=
github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE=
github.com/frankban/quicktest v1.9.0/go.mod h1:ui7WezCLWMWxVWr1GETZY3smRy0G4KWq9vcPtJmFl7Y=
Expand All @@ -178,8 +178,8 @@ github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2
github.com/go-kit/log v0.1.0/go.mod h1:zbhenjAZHb184qTLMA9ZjW7ThYL0H2mk7Q6pNt4vbaY=
github.com/go-llsqlite/adapter v0.0.0-20230927005056-7f5ce7f0c916 h1:OyQmpAN302wAopDgwVjgs2HkFawP9ahIEqkUYz7V7CA=
github.com/go-llsqlite/adapter v0.0.0-20230927005056-7f5ce7f0c916/go.mod h1:DADrR88ONKPPeSGjFp5iEN55Arx3fi2qXZeKCYDpbmU=
github.com/go-llsqlite/crawshaw v0.4.0 h1:L02s2jZBBJj80xm1VkkdyB/JlQ/Fi0kLbNHfXA8yrec=
github.com/go-llsqlite/crawshaw v0.4.0/go.mod h1:/YJdV7uBQaYDE0fwe4z3wwJIZBJxdYzd38ICggWqtaE=
github.com/go-llsqlite/crawshaw v0.5.2-0.20240425034140-f30eb7704568 h1:3EpZo8LxIzF4q3BT+vttQQlRfA6uTtTb/cxVisWa5HM=
github.com/go-llsqlite/crawshaw v0.5.2-0.20240425034140-f30eb7704568/go.mod h1:/YJdV7uBQaYDE0fwe4z3wwJIZBJxdYzd38ICggWqtaE=
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A=
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,6 @@ require (
)

replace (
github.com/anacrolix/torrent => github.com/erigontech/torrent v1.54.2-alpha-38
github.com/anacrolix/torrent => github.com/erigontech/torrent v1.54.2
github.com/holiman/bloomfilter/v2 => github.com/AskAlexSharov/bloomfilter/v2 v2.0.8
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,8 @@ github.com/erigontech/silkworm-go v0.18.0 h1:j56p61xZHBFhZGH1OixlGU8KcfjHzcw9pjA
github.com/erigontech/silkworm-go v0.18.0/go.mod h1:O50ux0apICEVEGyRWiE488K8qz8lc3PA/SXbQQAc8SU=
github.com/erigontech/speedtest v0.0.2 h1:W9Cvky/8AMUtUONwkLA/dZjeQ2XfkBdYfJzvhMZUO+U=
github.com/erigontech/speedtest v0.0.2/go.mod h1:vulsRNiM51BmSTbVtch4FWxKxx53pS2D35lZTtao0bw=
github.com/erigontech/torrent v1.54.2-alpha-38 h1:0KQTLlotAWy63MuyUatAzvIYwULYMSHI51A8Jl+3TC4=
github.com/erigontech/torrent v1.54.2-alpha-38/go.mod h1:QtK2WLdEz1Iy1Dh/325UltdHU0nA1xujh2rN6aov6y0=
github.com/erigontech/torrent v1.54.2 h1:oZCD1l96J7ei3780qHzMgOu+8GlW79J0t9tU1nx4o+U=
github.com/erigontech/torrent v1.54.2/go.mod h1:QtK2WLdEz1Iy1Dh/325UltdHU0nA1xujh2rN6aov6y0=
github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM=
github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE=
github.com/fjl/gencodec v0.0.0-20220412091415-8bb9e558978c h1:CndMRAH4JIwxbW8KYq6Q+cGWcGHz0FjGR3QqcInWcW0=
Expand Down
Loading