Skip to content

Commit 3f79eab

Browse files
committed
Collect some additional stats.
License: MIT Signed-off-by: Kevin Atkinson <k@kevina.org>
1 parent c6be2e2 commit 3f79eab

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

unixfs/hamt/fetcher.go

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package hamt
22

33
import (
44
"context"
5+
"time"
56
//"fmt"
67
//"os"
78

@@ -29,7 +30,7 @@ type fetcher struct {
2930

3031
idle bool
3132

32-
done chan int
33+
done chan batchJob
3334

3435
todoFirst *job // do this job first since we are waiting for its results
3536
todo jobStack // stack of jobs that still need to be done
@@ -43,6 +44,8 @@ type fetcher struct {
4344

4445
// other useful stats
4546
cidCnt int
47+
48+
start time.Time
4649
}
4750

4851
// batchSize must be at least as large as the largest number of cids
@@ -65,7 +68,7 @@ func startFetcher(ctx context.Context, dserv ipld.DAGService) *fetcher {
6568
reqRes: make(chan *Shard),
6669
result: make(chan result),
6770
idle: true,
68-
done: make(chan int),
71+
done: make(chan batchJob),
6972
jobs: make(map[*Shard]*job),
7073
}
7174
go f.mainLoop()
@@ -109,6 +112,7 @@ type jobStack struct {
109112

110113
func (f *fetcher) mainLoop() {
111114
var want *Shard
115+
f.start = time.Now()
112116
for {
113117
select {
114118
case id := <-f.reqRes:
@@ -142,8 +146,9 @@ func (f *fetcher) mainLoop() {
142146
}
143147
want = id
144148
}
145-
case cnt := <-f.done:
146-
f.doneCnt += cnt
149+
case bj := <-f.done:
150+
f.doneCnt += len(bj.jobs)
151+
f.cidCnt += len(bj.cids)
147152
f.launch()
148153
if want != nil {
149154
j := f.jobs[want]
@@ -153,11 +158,10 @@ func (f *fetcher) mainLoop() {
153158
}
154159
}
155160
log.Infof("fetcher: batch job done")
156-
log.Infof("fetcher stats (done, hits, nearMisses, misses): %d %d %d %d", f.doneCnt, f.hits, f.nearMisses, f.misses)
161+
f.mainLoopLogStats()
157162
case <-f.ctx.Done():
158163
log.Infof("fetcher: exiting")
159-
log.Infof("fetcher stats (done, hits, nearMisses, misses): %d %d %d %d", f.doneCnt, f.hits, f.nearMisses, f.misses)
160-
log.Infof("fetcher total number of CIDs retrieved: %d", f.cidCnt)
164+
f.mainLoopLogStats()
161165
return
162166
}
163167
}
@@ -173,7 +177,6 @@ func (f *fetcher) mainLoopAddJob(hamt *Shard) *job {
173177
// programmer error
174178
panic("job size larger than batchSize")
175179
}
176-
f.cidCnt += len(j.cids)
177180
f.todo.push(j)
178181
f.jobs[j.id] = j
179182
return j
@@ -197,6 +200,12 @@ func (f *fetcher) mainLoopSendResult(j *job) {
197200
}
198201
}
199202

203+
func (f *fetcher) mainLoopLogStats() {
204+
log.Infof("fetcher stats (cids, done, hits, nearMisses, misses): %d %d %d %d %d", f.cidCnt, f.doneCnt, f.hits, f.nearMisses, f.misses)
205+
elapsed := time.Now().Sub(f.start).Seconds()
206+
log.Infof("fetcher perf (cids/sec, jobs/sec) %f %f", float64(f.cidCnt)/elapsed, float64(f.doneCnt+f.hits+f.nearMisses+f.misses)/elapsed)
207+
}
208+
200209
type batchJob struct {
201210
cids []*cid.Cid
202211
jobs []*job
@@ -252,7 +261,7 @@ func (f *fetcher) launch() {
252261
for _, job := range bj.jobs {
253262
job.res = fetched
254263
}
255-
f.done <- len(bj.jobs)
264+
f.done <- bj
256265
}()
257266
}
258267

0 commit comments

Comments
 (0)