Add time logs for eden-watcher (#78)

This commit is contained in:
prathamesh0 2021-12-14 13:53:17 +05:30 committed by nabarun
parent f4d16afa6c
commit 952f68ee58
6 changed files with 38 additions and 7 deletions

View File

@ -82,7 +82,6 @@ export const main = async (): Promise<any> => {
await fillBlocks( await fillBlocks(
jobQueue, jobQueue,
indexer, indexer,
postgraphileClient,
eventWatcher, eventWatcher,
config.upstream.ethServer.blockDelayInMilliSecs, config.upstream.ethServer.blockDelayInMilliSecs,
{ {

View File

@ -74,7 +74,7 @@ export const main = async (): Promise<any> => {
const eventWatcher = new EventWatcher(config.upstream, ethClient, postgraphileClient, indexer, pubsub, jobQueue); const eventWatcher = new EventWatcher(config.upstream, ethClient, postgraphileClient, indexer, pubsub, jobQueue);
await fillBlocks(jobQueue, indexer, postgraphileClient, eventWatcher, config.upstream.ethServer.blockDelayInMilliSecs, argv); await fillBlocks(jobQueue, indexer, eventWatcher, config.upstream.ethServer.blockDelayInMilliSecs, argv);
}; };
main().catch(err => { main().catch(err => {

View File

@ -258,9 +258,13 @@ export class Indexer implements IndexerInterface {
async processCanonicalBlock (job: any): Promise<void> { async processCanonicalBlock (job: any): Promise<void> {
const { data: { blockHash } } = job; const { data: { blockHash } } = job;
console.time('time:indexer#processCanonicalBlock-finalize_auto_diffs');
// Finalize staged diff blocks if any. // Finalize staged diff blocks if any.
await this._baseIndexer.finalizeDiffStaged(blockHash); await this._baseIndexer.finalizeDiffStaged(blockHash);
console.timeEnd('time:indexer#processCanonicalBlock-finalize_auto_diffs');
// Call custom stateDiff hook. // Call custom stateDiff hook.
await createStateDiff(this, blockHash); await createStateDiff(this, blockHash);
} }
@ -271,7 +275,12 @@ export class Indexer implements IndexerInterface {
if (checkpointInterval <= 0) return; if (checkpointInterval <= 0) return;
const { data: { blockHash } } = job; const { data: { blockHash } } = job;
console.time('time:indexer#processCheckpoint-checkpoint');
await this._baseIndexer.processCheckpoint(this, blockHash, checkpointInterval); await this._baseIndexer.processCheckpoint(this, blockHash, checkpointInterval);
console.timeEnd('time:indexer#processCheckpoint-checkpoint');
} }
async processCLICheckpoint (contractAddress: string, blockHash?: string): Promise<string | undefined> { async processCLICheckpoint (contractAddress: string, blockHash?: string): Promise<string | undefined> {
@ -307,7 +316,11 @@ export class Indexer implements IndexerInterface {
} }
async createDiffStaged (contractAddress: string, blockHash: string, data: any): Promise<void> { async createDiffStaged (contractAddress: string, blockHash: string, data: any): Promise<void> {
console.time('time:indexer#createDiffStaged-auto_diff');
await this._baseIndexer.createDiffStaged(contractAddress, blockHash, data); await this._baseIndexer.createDiffStaged(contractAddress, blockHash, data);
console.timeEnd('time:indexer#createDiffStaged-auto_diff');
} }
async createDiff (contractAddress: string, blockHash: string, data: any): Promise<void> { async createDiff (contractAddress: string, blockHash: string, data: any): Promise<void> {
@ -341,9 +354,13 @@ export class Indexer implements IndexerInterface {
async triggerIndexingOnEvent (event: Event): Promise<void> { async triggerIndexingOnEvent (event: Event): Promise<void> {
const resultEvent = this.getResultEvent(event); const resultEvent = this.getResultEvent(event);
console.time('time:indexer#processEvent-mapping_code');
// Call subgraph handler for event. // Call subgraph handler for event.
await this._graphWatcher.handleEvent(resultEvent); await this._graphWatcher.handleEvent(resultEvent);
console.timeEnd('time:indexer#processEvent-mapping_code');
// Call custom hook function for indexing on event. // Call custom hook function for indexing on event.
await handleEvent(this, resultEvent); await handleEvent(this, resultEvent);
} }
@ -354,11 +371,19 @@ export class Indexer implements IndexerInterface {
} }
async processBlock (blockHash: string, blockNumber: number): Promise<void> { async processBlock (blockHash: string, blockNumber: number): Promise<void> {
console.time('time:indexer#processBlock-init_state');
// Call a function to create initial state for contracts. // Call a function to create initial state for contracts.
await this._baseIndexer.createInit(this, blockHash, blockNumber); await this._baseIndexer.createInit(this, blockHash, blockNumber);
console.timeEnd('time:indexer#processBlock-init_state');
console.time('time:indexer#processBlock-mapping_code');
// Call subgraph handler for block. // Call subgraph handler for block.
await this._graphWatcher.handleBlock(blockHash); await this._graphWatcher.handleBlock(blockHash);
console.timeEnd('time:indexer#processBlock-mapping_code');
} }
parseEventNameAndArgs (kind: string, logObj: any): any { parseEventNameAndArgs (kind: string, logObj: any): any {
@ -1256,6 +1281,8 @@ export class Indexer implements IndexerInterface {
async _fetchAndSaveEvents ({ cid: blockCid, blockHash }: DeepPartial<BlockProgress>): Promise<BlockProgress> { async _fetchAndSaveEvents ({ cid: blockCid, blockHash }: DeepPartial<BlockProgress>): Promise<BlockProgress> {
assert(blockHash); assert(blockHash);
console.time('time:indexer#_fetchAndSaveEvents-logs_txs');
const logsPromise = this._ethClient.getLogs({ blockHash }); const logsPromise = this._ethClient.getLogs({ blockHash });
const transactionsPromise = this._postgraphileClient.getBlockWithTransactions({ blockHash }); const transactionsPromise = this._postgraphileClient.getBlockWithTransactions({ blockHash });
@ -1274,6 +1301,8 @@ export class Indexer implements IndexerInterface {
} }
] = await Promise.all([logsPromise, transactionsPromise]); ] = await Promise.all([logsPromise, transactionsPromise]);
console.timeEnd('time:indexer#_fetchAndSaveEvents-logs_txs');
const transactionMap = transactions.reduce((acc: {[key: string]: any}, transaction: {[key: string]: any}) => { const transactionMap = transactions.reduce((acc: {[key: string]: any}, transaction: {[key: string]: any}) => {
acc[transaction.txHash] = transaction; acc[transaction.txHash] = transaction;
return acc; return acc;

View File

@ -82,7 +82,6 @@ export const main = async (): Promise<any> => {
await fillBlocks( await fillBlocks(
jobQueue, jobQueue,
indexer, indexer,
postgraphileClient,
eventWatcher, eventWatcher,
config.upstream.ethServer.blockDelayInMilliSecs, config.upstream.ethServer.blockDelayInMilliSecs,
{ {

View File

@ -74,7 +74,7 @@ export const main = async (): Promise<any> => {
const eventWatcher = new EventWatcher(config.upstream, ethClient, postgraphileClient, indexer, pubsub, jobQueue); const eventWatcher = new EventWatcher(config.upstream, ethClient, postgraphileClient, indexer, pubsub, jobQueue);
await fillBlocks(jobQueue, indexer, postgraphileClient, eventWatcher, config.upstream.ethServer.blockDelayInMilliSecs, argv); await fillBlocks(jobQueue, indexer, eventWatcher, config.upstream.ethServer.blockDelayInMilliSecs, argv);
}; };
main().catch(err => { main().catch(err => {

View File

@ -12,6 +12,8 @@ import { processBlockByNumber } from './common';
const log = debug('vulcanize:fill'); const log = debug('vulcanize:fill');
const DEFAULT_PREFETCH_BATCH_SIZE = 10;
export const fillBlocks = async ( export const fillBlocks = async (
jobQueue: JobQueue, jobQueue: JobQueue,
indexer: IndexerInterface, indexer: IndexerInterface,
@ -20,11 +22,11 @@ export const fillBlocks = async (
argv: { argv: {
startBlock: number, startBlock: number,
endBlock: number, endBlock: number,
prefetch: boolean, prefetch?: boolean,
batchBlocks: number, batchBlocks?: number,
} }
): Promise<any> => { ): Promise<any> => {
let { startBlock, endBlock, prefetch, batchBlocks } = argv; let { startBlock, endBlock, prefetch = false, batchBlocks = DEFAULT_PREFETCH_BATCH_SIZE } = argv;
assert(startBlock <= endBlock, 'endBlock should be greater than or equal to startBlock'); assert(startBlock <= endBlock, 'endBlock should be greater than or equal to startBlock');
const syncStatus = await indexer.getSyncStatus(); const syncStatus = await indexer.getSyncStatus();
@ -137,4 +139,6 @@ const prefetchBlocks = async (
process.exit(0); process.exit(0);
} }
} }
console.timeEnd('time:fill#fillBlocks-process_blocks');
}; };