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

Increase channel size, seperate variable logic, remove info prints #22

Merged
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
36 changes: 17 additions & 19 deletions quaistats/quaistats.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,15 @@ const (
)

var (
c_blocksPerMinute uint64
c_blocksPerHour uint64
c_txLookupCacheLimit uint64 // Number of tx batches to have in the cache
chainID9000 = big.NewInt(9000)
chainID12000 = big.NewInt(12000)
chainID15000 = big.NewInt(15000)
chainID17000 = big.NewInt(17000)
chainID1337 = big.NewInt(1337)
c_blocksPerMinute uint64
c_blocksPerHour uint64
c_txLookupCacheLimit uint64
c_txLookupCacheEvictLimit uint64
chainID9000 = big.NewInt(9000)
chainID12000 = big.NewInt(12000)
chainID15000 = big.NewInt(15000)
chainID17000 = big.NewInt(17000)
chainID1337 = big.NewInt(1337)
)

// backend encompasses the bare-minimum functionality needed for quaistats reporting
Expand Down Expand Up @@ -252,7 +253,8 @@ func New(node *node.Node, backend backend, engine consensus.Engine, url string,

c_blocksPerMinute = 60 / durationLimitInt
c_blocksPerHour = 60 * c_blocksPerMinute
c_txLookupCacheLimit = c_blocksPerHour / c_txBatchSize
c_txLookupCacheEvictLimit = c_blocksPerHour / c_txBatchSize
c_txLookupCacheLimit = 2 * c_txLookupCacheEvictLimit

txLookupCache, _ := lru.New(int(c_txLookupCacheLimit * 2))

Expand Down Expand Up @@ -311,8 +313,8 @@ func (s *Service) loopBlocks(chainHeadCh chan core.ChainHeadEvent, chainSideCh c
}()

quitCh := make(chan struct{})
headCh := make(chan *types.Block, 1)
sideCh := make(chan *types.Block, 1)
headCh := make(chan *types.Block, chainHeadChanSize)
sideCh := make(chan *types.Block, chainSideChanSize)

go func() {
HandleLoop:
Expand Down Expand Up @@ -1047,7 +1049,6 @@ func (s *Service) calculateTPS(block *types.Block) *tps {

// Try to get the data from the LRU cache
cachedBatchObject, ok := s.txLookupCache.Get(uint64(startBlockNum))
log.Info("TPS - just looked in cache", "startBlockNum", startBlockNum)
if !ok {
// Not in cache, so we need to calculate the transaction count for this batch
txCount := uint64(0)
Expand Down Expand Up @@ -1078,25 +1079,22 @@ func (s *Service) calculateTPS(block *types.Block) *tps {
var err error
currentBlock, err = fullBackend.BlockByNumber(context.Background(), rpc.BlockNumber(currentNumber-1))
if err != nil {
log.Error(fmt.Sprintf("TPS - Error getting block number %d: %s", currentNumber-1, err.Error()))
log.Error(fmt.Sprintf("Error getting block number %d: %s", currentNumber-1, err.Error()))
break
}
if currentBlock == nil {
log.Error(fmt.Sprintf("TPS - No block found at number %d", currentNumber-1))
log.Error(fmt.Sprintf("No block found at number %d", currentNumber-1))
break
}
}

log.Info("TPS - Batch Object", "currentBlockNum", currentBlock.NumberU64(), "txCount", txCount, "oldestBlockTimeInBatch", oldestBlockTimeInBatch)

batchObject := &BatchObject{
TotalNoTransactions: txCount,
OldestBlockTime: oldestBlockTimeInBatch,
}

// Store the sum in the cache
s.txLookupCache.Add(startBlockNum, batchObject)
log.Info("TPS - just added to cache", "startBlockNum", startBlockNum)

cachedBatchObject = batchObject
}
Expand All @@ -1106,7 +1104,7 @@ func (s *Service) calculateTPS(block *types.Block) *tps {
startBlockNum -= uint64(c_txBatchSize)
}

if s.txLookupCache.Len() > int(c_txLookupCacheLimit) {
if s.txLookupCache.Len() > int(c_txLookupCacheEvictLimit) {
s.evictOutdatedEntries(int(block.NumberU64() - c_blocksPerHour))
}

Expand Down Expand Up @@ -1141,7 +1139,7 @@ func (s *Service) calculateTPS(block *types.Block) *tps {
// Type assert the value to a *BatchObject
batchObject, ok = value.(*BatchObject)
if !ok {
log.Warn("TPS - Error casting value to *BatchObject")
log.Warn("Error casting value to *BatchObject")
return &tps{
TPS1m: totalTransactions1m / 60,
TPS1hr: totalTransactions1h / 3600,
Expand Down
Loading