Optimize execution time

This commit is contained in:
Anton Vakhrushev 2020-04-25 12:46:57 +03:00
parent d4aca5162c
commit 09d97584ef
2 changed files with 14 additions and 6 deletions

View File

@ -25,12 +25,22 @@ export class Executor {
async run() { async run() {
await waitForLoad(); await waitForLoad();
await sleepMicro(); await sleepMicro();
markPage('Executor', this.version);
this.renderTaskQueue(); try {
setInterval(() => this.renderTaskQueue(), 5 * 1000); markPage('Executor', this.version);
this.renderTaskQueue();
} catch (e) {
this.logger.warn(e);
}
let skipFirstSleep = true;
while (true) { while (true) {
if (skipFirstSleep) {
skipFirstSleep = false;
} else {
await sleepMicro();
}
await this.doTaskProcessingStep(); await this.doTaskProcessingStep();
} }
} }
@ -40,8 +50,6 @@ export class Executor {
} }
private async doTaskProcessingStep() { private async doTaskProcessingStep() {
await sleepMicro();
const currentTs = timestamp(); const currentTs = timestamp();
const task = this.scheduler.nextTask(currentTs); const task = this.scheduler.nextTask(currentTs);

View File

@ -5,7 +5,7 @@ export function sleep(ms: number) {
} }
export async function sleepMicro() { export async function sleepMicro() {
let ms = 1000 + Math.random() * 2000; let ms = 2000 + Math.random() * 500;
return await sleep(ms); return await sleep(ms);
} }