Skip to content

Commit

Permalink
fw: simplify pit expiry
Browse files Browse the repository at this point in the history
This has a cost - any interests in the expiry period may get dropped?
  • Loading branch information
pulsejet committed Feb 4, 2025
1 parent 2c02d80 commit 09323a9
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 32 deletions.
3 changes: 1 addition & 2 deletions fw/fw/thread.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ func (t *Thread) Run() {
runtime.LockOSThread()
}

pitUpdateTimer := t.pitCS.UpdateTimer()
for !core.ShouldQuit {
select {
case pkt := <-t.pending:
Expand All @@ -132,7 +131,7 @@ func (t *Thread) Run() {
}
case <-t.deadNonceList.Ticker.C:
t.deadNonceList.RemoveExpiredEntries()
case <-pitUpdateTimer:
case <-t.pitCS.UpdateTicker():
t.pitCS.Update()
case <-t.shouldQuit:
continue
Expand Down
31 changes: 5 additions & 26 deletions fw/table/pit-cs-tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/named-data/ndnd/std/types/priority_queue"
)

const expiredPitTickerInterval = 100 * time.Millisecond
const expiredPitTickerInterval = 200 * time.Millisecond
const pitTokenLookupTableSize = 125000 // 1MB

type OnPitExpiration func(PitEntry)
Expand All @@ -28,7 +28,7 @@ type PitCsTree struct {
csMap map[uint64]*nameTreeCsEntry

pitExpiryQueue priority_queue.Queue[*nameTreePitEntry, int64]
updateTimer chan struct{}
updateTicker *time.Ticker
onExpiration OnPitExpiration
}

Expand Down Expand Up @@ -68,7 +68,7 @@ func NewPitCS(onExpiration OnPitExpiration) *PitCsTree {
pitCs.onExpiration = onExpiration
pitCs.pitTokens = make([]*nameTreePitEntry, pitTokenLookupTableSize)
pitCs.pitExpiryQueue = priority_queue.New[*nameTreePitEntry, int64]()
pitCs.updateTimer = make(chan struct{})
pitCs.updateTicker = time.NewTicker(expiredPitTickerInterval)

// This value has already been validated from loading the configuration,
// so we know it will be one of the following (or else fatal)
Expand All @@ -80,16 +80,11 @@ func NewPitCS(onExpiration OnPitExpiration) *PitCsTree {
}
pitCs.csMap = make(map[uint64]*nameTreeCsEntry)

// Schedule first signal
time.AfterFunc(expiredPitTickerInterval, func() {
pitCs.updateTimer <- struct{}{}
})

return pitCs
}

func (p *PitCsTree) UpdateTimer() <-chan struct{} {
return p.updateTimer
func (p *PitCsTree) UpdateTicker() <-chan time.Time {
return p.updateTicker.C
}

func (p *PitCsTree) Update() {
Expand All @@ -99,22 +94,6 @@ func (p *PitCsTree) Update() {
p.onExpiration(entry)
p.RemoveInterest(entry)
}
if !core.ShouldQuit {
updateDuration := expiredPitTickerInterval
if p.pitExpiryQueue.Len() > 0 {
sleepTime := time.Duration(p.pitExpiryQueue.PeekPriority()-time.Now().UnixNano()) * time.Nanosecond
if sleepTime > 0 {
if sleepTime > expiredPitTickerInterval {
sleepTime = expiredPitTickerInterval
}
updateDuration = sleepTime
}
}
// Schedule next signal
time.AfterFunc(updateDuration, func() {
p.updateTimer <- struct{}{}
})
}
}

func (p *PitCsTree) updatePitExpiry(pitEntry PitEntry) {
Expand Down
6 changes: 2 additions & 4 deletions fw/table/pit-cs.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,9 @@ type PitCsTable interface {
eraseCsDataFromReplacementStrategy(index uint64)
updatePitExpiry(pitEntry PitEntry)

// UpdateTimer returns the channel used to signal regular Update() calls in the forwarding thread.
// <- UpdateTimer() and Update() must be called in pairs.
UpdateTimer() <-chan struct{}
// UpdateTicker returns the channel used to signal regular Update() calls in the forwarding thread.
UpdateTicker() <-chan time.Time
// Update() does whatever the PIT table needs to do regularly.
// It may schedule the next UpdateTimer().
Update()
}

Expand Down

0 comments on commit 09323a9

Please sign in to comment.