[READ-ONLY] Mirror of https://github.com/vitest-dev/vitest. Next generation testing framework powered by Vite. vitest.dev
test testing-tools vite
12

Configure Feed

Select the types of activity you want to include in your feed.

chore: update threadsCount logic to use availableParallelism (#4126)

authored by

Diogo Torres and committed by
GitHub
(Sep 20, 2023, 8:58 AM +0200) 2f7d42c9 c21c0efa

+24 -9
+8 -3
packages/vitest/src/node/pools/threads.ts
··· 1 1 import { MessageChannel } from 'node:worker_threads' 2 - import { cpus } from 'node:os' 2 + import * as nodeos from 'node:os' 3 3 import { pathToFileURL } from 'node:url' 4 4 import { createBirpc } from 'birpc' 5 5 import { resolve } from 'pathe' ··· 39 39 } 40 40 41 41 export function createThreadsPool(ctx: Vitest, { execArgv, env }: PoolProcessOptions): ProcessPool { 42 + const numCpus 43 + = typeof nodeos.availableParallelism === 'function' 44 + ? nodeos.availableParallelism() 45 + : nodeos.cpus().length 46 + 42 47 const threadsCount = ctx.config.watch 43 - ? Math.max(Math.floor(cpus().length / 2), 1) 44 - : Math.max(cpus().length - 1, 1) 48 + ? Math.max(Math.floor(numCpus / 2), 1) 49 + : Math.max(numCpus - 1, 1) 45 50 46 51 const maxThreads = ctx.config.maxThreads ?? threadsCount 47 52 const minThreads = ctx.config.minThreads ?? threadsCount
+8 -3
packages/vitest/src/node/pools/vm-threads.ts
··· 1 1 import { MessageChannel } from 'node:worker_threads' 2 - import { cpus } from 'node:os' 2 + import * as nodeos from 'node:os' 3 3 import { pathToFileURL } from 'node:url' 4 4 import { createBirpc } from 'birpc' 5 5 import { resolve } from 'pathe' ··· 40 40 } 41 41 42 42 export function createVmThreadsPool(ctx: Vitest, { execArgv, env }: PoolProcessOptions): ProcessPool { 43 + const numCpus 44 + = typeof nodeos.availableParallelism === 'function' 45 + ? nodeos.availableParallelism() 46 + : nodeos.cpus().length 47 + 43 48 const threadsCount = ctx.config.watch 44 - ? Math.max(Math.floor(cpus().length / 2), 1) 45 - : Math.max(cpus().length - 1, 1) 49 + ? Math.max(Math.floor(numCpus / 2), 1) 50 + : Math.max(numCpus - 1, 1) 46 51 47 52 const maxThreads = ctx.config.maxThreads ?? threadsCount 48 53 const minThreads = ctx.config.minThreads ?? threadsCount
+8 -3
packages/vitest/src/utils/memory-limit.ts
··· 5 5 * LICENSE file in the root directory of facebook/jest GitHub project tree. 6 6 */ 7 7 8 - import { cpus } from 'node:os' 8 + import * as nodeos from 'node:os' 9 9 import type { ResolvedConfig } from '../types' 10 10 11 11 function getDefaultThreadsCount(config: ResolvedConfig) { 12 + const numCpus 13 + = typeof nodeos.availableParallelism === 'function' 14 + ? nodeos.availableParallelism() 15 + : nodeos.cpus().length 16 + 12 17 return config.watch 13 - ? Math.max(Math.floor(cpus().length / 2), 1) 14 - : Math.max(cpus().length - 1, 1) 18 + ? Math.max(Math.floor(numCpus / 2), 1) 19 + : Math.max(numCpus - 1, 1) 15 20 } 16 21 17 22 export function getWorkerMemoryLimit(config: ResolvedConfig) {