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

chore: avoid using bigint for metrics #5926

Merged
merged 2 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
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
15 changes: 9 additions & 6 deletions packages/beacon-node/src/chain/bls/multithread/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -432,10 +432,13 @@ export class BlsMultiThreadWorkerPool implements IBlsVerifier {
// If the job, metrics or any code below throws: the job will reject never going stale.
// Only downside is the the job promise may be resolved twice, but that's not an issue

const jobStartNs = process.hrtime.bigint();
const [jobStartSec, jobStartNs] = process.hrtime();
const workResult = await workerApi.verifyManySignatureSets(workReqs);
const jobEndNs = process.hrtime.bigint();
const {workerId, batchRetries, batchSigsSuccess, workerStartNs, workerEndNs, results} = workResult;
const [jobEndSec, jobEndNs] = process.hrtime();
const {workerId, batchRetries, batchSigsSuccess, workerStartTime, workerEndTime, results} = workResult;

const [workerStartSec, workerStartNs] = workerStartTime;
const [workerEndSec, workerEndNs] = workerEndTime;

let successCount = 0;
let errorCount = 0;
Expand Down Expand Up @@ -477,9 +480,9 @@ export class BlsMultiThreadWorkerPool implements IBlsVerifier {
}
}

const workerJobTimeSec = Number(workerEndNs - workerStartNs) / 1e9;
const latencyToWorkerSec = Number(workerStartNs - jobStartNs) / 1e9;
const latencyFromWorkerSec = Number(jobEndNs - workerEndNs) / 1e9;
const workerJobTimeSec = workerEndSec - workerStartSec + (workerEndNs - workerStartNs) / 1e9;
const latencyToWorkerSec = workerStartSec - jobStartSec + (workerStartNs - jobStartNs) / 1e9;
const latencyFromWorkerSec = jobEndSec - workerEndSec + Number(jobEndNs - workerEndNs) / 1e9;

this.metrics?.blsThreadPool.timePerSigSet.observe(workerJobTimeSec / startedSigSets);
this.metrics?.blsThreadPool.jobsWorkerTime.inc({workerId}, workerJobTimeSec);
Expand Down
8 changes: 4 additions & 4 deletions packages/beacon-node/src/chain/bls/multithread/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ export type BlsWorkResult = {
batchRetries: number;
/** Total num of sigs that have been successfully verified with batching */
batchSigsSuccess: number;
/** Time worker function starts - UNIX timestamp in nanoseconds */
workerStartNs: bigint;
/** Time worker function ends - UNIX timestamp in nanoseconds */
workerEndNs: bigint;
/** Time worker function starts - UNIX timestamp in seconds and nanoseconds */
workerStartTime: [number, number];
/** Time worker function ends - UNIX timestamp in seconds and nanoseconds */
workerEndTime: [number, number];
results: WorkResult<boolean>[];
};
8 changes: 5 additions & 3 deletions packages/beacon-node/src/chain/bls/multithread/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ expose({
});

function verifyManySignatureSets(workReqArr: BlsWorkReq[]): BlsWorkResult {
const startNs = process.hrtime.bigint();
const [startSec, startNs] = process.hrtime();
const results: WorkResult<boolean>[] = [];
let batchRetries = 0;
let batchSigsSuccess = 0;
Expand Down Expand Up @@ -95,12 +95,14 @@ function verifyManySignatureSets(workReqArr: BlsWorkReq[]): BlsWorkResult {
}
}

const [workerEndSec, workerEndNs] = process.hrtime();

return {
workerId,
batchRetries,
batchSigsSuccess,
workerStartNs: startNs,
workerEndNs: process.hrtime.bigint(),
workerStartTime: [startSec, startNs],
workerEndTime: [workerEndSec, workerEndNs],
results,
};
}
Expand Down
17 changes: 8 additions & 9 deletions packages/beacon-node/src/chain/bls/singleThread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,13 @@ export class BlsSingleThreadVerifier implements IBlsVerifier {
}));

// Count time after aggregating
const startNs = process.hrtime.bigint();

const timer = this.metrics?.blsThreadPool.mainThreadDurationInThreadPool.startTimer();
const isValid = verifySignatureSetsMaybeBatch(setsAggregated);

// Don't use a try/catch, only count run without exceptions
const endNs = process.hrtime.bigint();
const totalSec = Number(startNs - endNs) / 1e9;
this.metrics?.blsThreadPool.mainThreadDurationInThreadPool.observe(totalSec);
if (timer) {
timer();
}

return isValid;
}
Expand All @@ -40,7 +39,7 @@ export class BlsSingleThreadVerifier implements IBlsVerifier {
sets: {publicKey: PublicKey; signature: Uint8Array}[],
message: Uint8Array
): Promise<boolean[]> {
const startNs = process.hrtime.bigint();
const timer = this.metrics?.blsThreadPool.mainThreadDurationInThreadPool.startTimer();
const pubkey = bls.PublicKey.aggregate(sets.map((set) => set.publicKey));
let isAllValid = true;
// validate signature = true
Expand Down Expand Up @@ -72,9 +71,9 @@ export class BlsSingleThreadVerifier implements IBlsVerifier {
});
}

const endNs = process.hrtime.bigint();
const totalSec = Number(startNs - endNs) / 1e9;
this.metrics?.blsThreadPool.mainThreadDurationInThreadPool.observe(totalSec);
if (timer) {
timer();
}

return result;
}
Expand Down