Skip to content

Commit

Permalink
Fix bls pool size
Browse files Browse the repository at this point in the history
  • Loading branch information
wemeetagain committed May 19, 2022
1 parent 68752e2 commit 16bad3b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 18 deletions.
5 changes: 3 additions & 2 deletions packages/lodestar/src/chain/bls/multithread/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import {QueueError, QueueErrorCode} from "../../../util/queue/index.js";
import {IMetrics} from "../../../metrics/index.js";
import {IBlsVerifier, VerifySignatureOpts} from "../interface.js";
import {BlsWorkReq, BlsWorkResult, WorkerData, WorkResultCode} from "./types.js";
import {chunkifyMaximizeChunkSize, getDefaultPoolSize} from "./utils.js";
import {chunkifyMaximizeChunkSize} from "./utils.js";
import {defaultPoolSize} from "./poolSize.js";
import {ISignatureSet} from "@chainsafe/lodestar-beacon-state-transition";
import {getAggregatedPubkey} from "../utils.js";
import {verifySignatureSetsMaybeBatch} from "../maybeBatch.js";
Expand Down Expand Up @@ -126,7 +127,7 @@ export class BlsMultiThreadWorkerPool implements IBlsVerifier {
// THe worker is not able to deserialize from uncompressed
// `Error: err _wrapDeserialize`
this.format = implementation === "blst-native" ? PointFormat.uncompressed : PointFormat.compressed;
this.workers = this.createWorkers(implementation, getDefaultPoolSize());
this.workers = this.createWorkers(implementation, defaultPoolSize);

this.signal.addEventListener(
"abort",
Expand Down
16 changes: 16 additions & 0 deletions packages/lodestar/src/chain/bls/multithread/poolSize.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
let defaultPoolSize: number;

try {
if (typeof navigator !== "undefined") {
defaultPoolSize = navigator.hardwareConcurrency ?? 4;
} else {
defaultPoolSize = (await import("node:os")).cpus().length;
}
} catch (e) {
defaultPoolSize = 8;
}

/**
* Cross-platform aprox number of logical cores
*/
export {defaultPoolSize};
16 changes: 0 additions & 16 deletions packages/lodestar/src/chain/bls/multithread/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,3 @@ export function chunkifyMaximizeChunkSize<T>(arr: T[], minPerChunk: number): T[]

return arrArr;
}

/**
* Cross-platform fetch an aprox number of logical cores
*/
export function getDefaultPoolSize(): number {
if (typeof navigator !== "undefined") {
return navigator.hardwareConcurrency ?? 4;
}

if (typeof require !== "undefined") {
// eslint-disable-next-line
return require("node:os").cpus().length;
}

return 8;
}

0 comments on commit 16bad3b

Please sign in to comment.