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

Add debug logging to allocator #213

Merged
merged 2 commits into from
Sep 10, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions allocator/allocator.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ import (
"sync"

pq "github.com/ipfs/go-ipfs-pq"
logging "github.com/ipfs/go-log/v2"
peer "github.com/libp2p/go-libp2p-core/peer"
)

var log = logging.Logger("graphsync_allocator")

type Allocator struct {
totalMemoryMax uint64
perPeerMax uint64
Expand Down Expand Up @@ -58,8 +61,10 @@ func (a *Allocator) AllocateBlockMemory(p peer.ID, amount uint64) <-chan error {
if (a.totalAllocatedAllPeers+amount <= a.totalMemoryMax) && (status.totalAllocated+amount <= a.perPeerMax) && len(status.pendingAllocations) == 0 {
a.totalAllocatedAllPeers += amount
status.totalAllocated += amount
log.Debugw("bytes allocated", "amount", amount, "peer", p, "peer total", status.totalAllocated, "global total", a.totalAllocatedAllPeers)
responseChan <- nil
} else {
log.Debugw("byte allocation deferred pending memory release", "amount", amount, "peer", p, "peer total", status.totalAllocated, "global total", a.totalAllocatedAllPeers, "max per peer", a.perPeerMax, "global max", a.totalMemoryMax)
pendingAllocation := pendingAllocation{p, amount, responseChan, a.nextAllocIndex}
a.nextAllocIndex++
status.pendingAllocations = append(status.pendingAllocations, pendingAllocation)
Expand All @@ -86,6 +91,7 @@ func (a *Allocator) ReleaseBlockMemory(p peer.ID, amount uint64) error {
} else {
a.totalAllocatedAllPeers = 0
}
log.Debugw("memory released", "amount", amount, "peer", p, "peer total", status.totalAllocated, "global total", a.totalAllocatedAllPeers, "max per peer", a.perPeerMax, "global max", a.totalMemoryMax)
a.peerStatusQueue.Update(status.Index())
a.processPendingAllocations()
return nil
Expand All @@ -104,6 +110,7 @@ func (a *Allocator) ReleasePeerMemory(p peer.ID) error {
pendingAllocation.response <- errors.New("peer has been deallocated")
}
a.totalAllocatedAllPeers -= status.totalAllocated
log.Debugw("memory released", "amount", status.totalAllocated, "peer", p, "peer total", 0, "global total", a.totalAllocatedAllPeers, "max per peer", a.perPeerMax, "global max", a.totalMemoryMax)
a.processPendingAllocations()
return nil
}
Expand Down Expand Up @@ -139,6 +146,7 @@ func (a *Allocator) processNextPendingAllocationForPeer(nextPeer *peerStatus) bo
a.totalAllocatedAllPeers += pendingAllocation.amount
nextPeer.totalAllocated += pendingAllocation.amount
nextPeer.pendingAllocations = nextPeer.pendingAllocations[1:]
log.Debugw("bytes allocated", "amount", pendingAllocation.amount, "peer", nextPeer.p, "peer total", nextPeer.totalAllocated, "global total", a.totalAllocatedAllPeers)
pendingAllocation.response <- nil
return true
}
Expand Down