Log time taken for processing single block inside job-runner (#321)

This commit is contained in:
nikugogoi 2021-12-17 15:20:33 +05:30 committed by GitHub
parent 01fa6e2184
commit 5dc6582ec8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 9 deletions

View File

@ -74,7 +74,16 @@ export const processBlockByNumber = async (
// Stop blocks already pushed to job queue. They are already retried after fail.
if (!syncStatus || syncStatus.chainHeadBlockNumber < blockNumber) {
await jobQueue.pushJob(QUEUE_BLOCK_PROCESSING, { kind: JOB_KIND_INDEX, blockHash, blockNumber, parentHash, timestamp });
await jobQueue.pushJob(
QUEUE_BLOCK_PROCESSING,
{
kind: JOB_KIND_INDEX,
blockNumber: Number(blockNumber),
blockHash,
parentHash,
timestamp
}
);
}
}

View File

@ -46,7 +46,6 @@ export const fillBlocks = async (
await eventWatcher.initEventProcessingOnCompleteHandler();
const numberOfBlocks = endBlock - startBlock + 1;
console.time(`time:fill#fillBlocks-process_block_${startBlock}`);
processBlockByNumber(jobQueue, indexer, blockDelayInMilliSecs, startBlock);
@ -65,10 +64,6 @@ export const fillBlocks = async (
const { onBlockProgressEvent: { blockNumber, isComplete } } = data;
if (isComplete) {
console.timeEnd(`time:fill#fillBlocks-process_block_${blockNumber}`);
console.time(`time:fill#fillBlocks-process_block_${blockNumber + 1}`);
const blocksProcessed = blockNumber - startBlock + 1;
const completePercentage = Math.round(blocksProcessed / numberOfBlocks * 100);
log(`Processed ${blocksProcessed} of ${numberOfBlocks} blocks (${completePercentage}%)`);

View File

@ -22,6 +22,7 @@ export class JobRunner {
_indexer: IndexerInterface
_jobQueue: JobQueue
_jobQueueConfig: JobQueueConfig
_blockProcessStartTime?: Date
constructor (jobQueueConfig: JobQueueConfig, indexer: IndexerInterface, jobQueue: JobQueue) {
this._jobQueueConfig = jobQueueConfig;
@ -116,9 +117,18 @@ export class JobRunner {
}
async _indexBlock (job: any): Promise<void> {
const { data: { blockHash, blockNumber, parentHash, priority, timestamp } } = job;
const indexBlockStartTime = new Date();
const { data: { blockHash, blockNumber, parentHash, priority, timestamp } } = job;
// Log time taken to complete processing of previous block.
if (this._blockProcessStartTime) {
const blockProcessDuration = indexBlockStartTime.getTime() - this._blockProcessStartTime.getTime();
log(`time:job-runner#_indexBlock-process-block-${blockNumber - 1}: ${blockProcessDuration}ms`);
log(`Total block process time (${blockNumber - 1}): ${blockProcessDuration}ms`);
}
this._blockProcessStartTime = indexBlockStartTime;
log(`Processing block number ${blockNumber} hash ${blockHash} `);
const syncStatus = await this._indexer.updateSyncStatusChainHead(blockHash, blockNumber);
@ -218,9 +228,9 @@ export class JobRunner {
async _processEvents (job: any): Promise<void> {
const { blockHash } = job.data;
console.time('time:job-runner#_processEvents-get-block-process');
console.time('time:job-runner#_processEvents-get-block-progress');
let block = await this._indexer.getBlockProgress(blockHash);
console.timeEnd('time:job-runner#_processEvents-get-block-process');
console.timeEnd('time:job-runner#_processEvents-get-block-progress');
assert(block);
console.time('time:job-runner#_processEvents-events');