From 1b40a919e3c5fc882588a1d0fd0c3adf755dc939 Mon Sep 17 00:00:00 2001 From: Matthew Keil Date: Thu, 24 Aug 2023 16:33:01 -0600 Subject: [PATCH] feat(beacon-node): network worker new space adjustment (#5829) * feat: up worker maxYoungGenerationSizeMb to 32 * feat: up worker maxYoungGenerationSizeMb to 64 * feat(dashboards): update memory panels on vm/host * feat(network-worker): update new space to 512mb * fix(dashboard): add newline to end of file * fix(dashboard): lint vm * feat: up worker maxYoungGenerationSizeMb to 32 * feat: up worker maxYoungGenerationSizeMb to 64 * feat(dashboards): update memory panels on vm/host * feat(network-worker): update new space to 512mb * fix(dashboard): add newline to end of file * fix(dashboard): lint vm * fix: dashboard lint * feat(network-worker): maxYoungGenerationSizeMb to 128mb * fix(dashboards): revert dashboard changes * fix: revert changes to dashboard and package.json * feat(network-worker): use young generation value from research * feat(cli): add hidden maxYoungGenerationSizeMb * fix: update bad merge conflict resolution * fix: update bad merge conflict resolution * chore: lint --fix code --- .../src/network/core/networkCoreWorkerHandler.ts | 16 +++++++++++++++- packages/beacon-node/src/network/options.ts | 3 +++ .../cli/src/options/beaconNodeOptions/network.ts | 10 ++++++++++ .../test/unit/options/beaconNodeOptions.test.ts | 2 ++ 4 files changed, 30 insertions(+), 1 deletion(-) diff --git a/packages/beacon-node/src/network/core/networkCoreWorkerHandler.ts b/packages/beacon-node/src/network/core/networkCoreWorkerHandler.ts index bd9e71e5e6bd..46c06456c429 100644 --- a/packages/beacon-node/src/network/core/networkCoreWorkerHandler.ts +++ b/packages/beacon-node/src/network/core/networkCoreWorkerHandler.ts @@ -107,7 +107,21 @@ export class WorkerNetworkCore implements INetworkCore { loggerOpts: modules.logger.toOpts(), }; - const worker = new Worker("./networkCoreWorker.js", {workerData} as ConstructorParameters[1]); + const worker = new Worker("./networkCoreWorker.js", { + workerData, + /** + * maxYoungGenerationSizeMb defaults to 152mb through the cli option defaults. + * That default value was determined via https://github.com/ChainSafe/lodestar/issues/2115 and + * should be tuned further as needed. If we update network code and see substantial + * difference in the quantity of garbage collected this should get updated. A value that is + * too low will result in too much GC time and a value that is too high causes increased mark + * and sweep for some reason (which is much much slower than scavenge). A marginally too high + * number causes detrimental slowdown from increased variable lookup time. Empirical evidence + * showed that there is a pretty big window of "correct" values but we can always tune as + * necessary + */ + resourceLimits: {maxYoungGenerationSizeMb: opts.maxYoungGenerationSizeMb}, + } as ConstructorParameters[1]); // eslint-disable-next-line @typescript-eslint/no-explicit-any const workerApi = (await spawn(worker, { diff --git a/packages/beacon-node/src/network/options.ts b/packages/beacon-node/src/network/options.ts index 79f5f6544817..b490e3c7206d 100644 --- a/packages/beacon-node/src/network/options.ts +++ b/packages/beacon-node/src/network/options.ts @@ -21,6 +21,7 @@ export interface NetworkOptions version?: string; private?: boolean; useWorker?: boolean; + maxYoungGenerationSizeMb?: number; } export const defaultNetworkOptions: NetworkOptions = { @@ -32,6 +33,8 @@ export const defaultNetworkOptions: NetworkOptions = { discv5: null, rateLimitMultiplier: 1, useWorker: true, + // default set via research in https://github.com/ChainSafe/lodestar/issues/2115 + maxYoungGenerationSizeMb: 152, // subscribe to 2 subnets per node since v1.10 deterministicLongLivedAttnets: true, // subscribe 2 slots before aggregator dutied slot to get stable mesh peers as monitored on goerli diff --git a/packages/cli/src/options/beaconNodeOptions/network.ts b/packages/cli/src/options/beaconNodeOptions/network.ts index e10cfeca0f70..745308ec7c8c 100644 --- a/packages/cli/src/options/beaconNodeOptions/network.ts +++ b/packages/cli/src/options/beaconNodeOptions/network.ts @@ -35,6 +35,7 @@ export type NetworkArgs = { "network.rateLimitMultiplier"?: number; "network.maxGossipTopicConcurrency"?: number; "network.useWorker"?: boolean; + "network.maxYoungGenerationSizeMb"?: number; /** @deprecated This option is deprecated and should be removed in next major release. */ "network.requestCountPeerLimit"?: number; @@ -153,6 +154,7 @@ export function parseArgs(args: NetworkArgs): IBeaconNodeOptions["network"] { rateLimitMultiplier: args["network.rateLimitMultiplier"], maxGossipTopicConcurrency: args["network.maxGossipTopicConcurrency"], useWorker: args["network.useWorker"], + maxYoungGenerationSizeMb: args["network.maxYoungGenerationSizeMb"], }; } @@ -385,4 +387,12 @@ export const options: CliCommandOptions = { hidden: true, group: "network", }, + + "network.maxYoungGenerationSizeMb": { + type: "number", + hidden: true, + group: "network", + description: "Max size of young generation in megabytes. Defaults to 152mb", + defaultDescription: String(defaultOptions.network.maxYoungGenerationSizeMb), + }, }; diff --git a/packages/cli/test/unit/options/beaconNodeOptions.test.ts b/packages/cli/test/unit/options/beaconNodeOptions.test.ts index 442b4c529d9b..b0f0254443dc 100644 --- a/packages/cli/test/unit/options/beaconNodeOptions.test.ts +++ b/packages/cli/test/unit/options/beaconNodeOptions.test.ts @@ -96,6 +96,7 @@ describe("options / beaconNodeOptions", () => { "network.rateLimitMultiplier": 1, "network.maxGossipTopicConcurrency": 64, "network.useWorker": true, + "network.maxYoungGenerationSizeMb": 152, "sync.isSingleNode": true, "sync.disableProcessAsChainSegment": true, @@ -199,6 +200,7 @@ describe("options / beaconNodeOptions", () => { rateLimitMultiplier: 1, maxGossipTopicConcurrency: 64, useWorker: true, + maxYoungGenerationSizeMb: 152, }, sync: { isSingleNode: true,