-
Notifications
You must be signed in to change notification settings - Fork 352
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
WIP-assign continuous blocks to worker #1173
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
|
||
import { Injectable } from '@nestjs/common'; | ||
import { RuntimeVersion } from '@polkadot/types/interfaces'; | ||
import { NodeConfig } from '../../configure/NodeConfig'; | ||
import { AutoQueue } from '../../utils/autoQueue'; | ||
import { fetchBlocksBatches } from '../../utils/substrate'; | ||
import { ApiService } from '../api.service'; | ||
|
@@ -17,18 +18,27 @@ export type ProcessBlockResponse = { | |
dynamicDsCreated: boolean; | ||
}; | ||
|
||
export type WorkerStatusResponse = { | ||
threadId: number; | ||
isIndexing: boolean; | ||
fetchedBlocks: number; | ||
toFetchBlocks: number; | ||
}; | ||
|
||
@Injectable() | ||
export class WorkerService { | ||
private fetchedBlocks: Record<string, BlockContent> = {}; | ||
private currentRuntimeVersion: RuntimeVersion | undefined; | ||
private _isIndexing = false; | ||
|
||
private queue: AutoQueue<FetchBlockResponse>; | ||
|
||
constructor( | ||
private apiService: ApiService, | ||
private indexerManager: IndexerManager, | ||
private nodeConfig: NodeConfig, | ||
) { | ||
this.queue = new AutoQueue(undefined, 5); | ||
this.queue = new AutoQueue(undefined, nodeConfig.batchSize); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. improve fetch performance for worker (same as before) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I found this change made the biggest difference. Even on my branch this change increases the performance to match. |
||
} | ||
|
||
async fetchBlock(height: number): Promise<FetchBlockResponse> { | ||
|
@@ -68,6 +78,7 @@ export class WorkerService { | |
} | ||
|
||
async processBlock(height: number): Promise<ProcessBlockResponse> { | ||
this._isIndexing = true; | ||
const block = this.fetchedBlocks[height]; | ||
|
||
if (!block) { | ||
|
@@ -76,7 +87,13 @@ export class WorkerService { | |
|
||
delete this.fetchedBlocks[height]; | ||
|
||
return this.indexerManager.indexBlock(block, this.currentRuntimeVersion); | ||
const response = await this.indexerManager.indexBlock( | ||
block, | ||
this.currentRuntimeVersion, | ||
); | ||
|
||
this._isIndexing = false; | ||
return response; | ||
} | ||
|
||
get numFetchedBlocks(): number { | ||
|
@@ -86,4 +103,8 @@ export class WorkerService { | |
get numFetchingBlocks(): number { | ||
return this.queue.size; | ||
} | ||
|
||
get isIndexing(): boolean { | ||
return this._isIndexing; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* 2
is important so worker can always prepare next batch