From aad2a3220e79a0b0289359cf336064d6fe421cd8 Mon Sep 17 00:00:00 2001 From: mrmlnc Date: Sun, 24 Dec 2023 15:59:40 +0300 Subject: [PATCH] refactor: remove the concurrency option --- README.md | 26 ----------------------- src/benchmark/suites/product/async.ts | 1 - src/benchmark/suites/product/stream.ts | 1 - src/benchmark/suites/regression/async.ts | 1 - src/benchmark/suites/regression/stream.ts | 1 - src/providers/provider.spec.ts | 1 - src/providers/provider.ts | 1 - src/settings.spec.ts | 2 -- src/settings.ts | 14 ------------ 9 files changed, 48 deletions(-) diff --git a/README.md b/README.md index c4f02360..b686bd97 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,6 @@ This package provides methods for traversing the file system and returning pathn * [convertPathToPattern](#convertpathtopatternpath) * [Options](#options-3) * [Common](#common) - * [concurrency](#concurrency) * [cwd](#cwd) * [deep](#deep) * [followSymbolicLinks](#followsymboliclinks) @@ -307,31 +306,6 @@ fg.win32.convertPathToPattern('\\\\?\\c:\\Program Files (x86)') + '/**/*'; ### Common options -#### concurrency - -* Type: `number` -* Default: `os.cpus().length` - -Specifies the maximum number of concurrent requests from a reader to read directories. - -> :book: The higher the number, the higher the performance and load on the file system. If you want to read in quiet mode, set the value to a comfortable number or `1`. - -
- -More details - -In Node, there are [two types of threads][nodejs_thread_pool]: Event Loop (code) and a Thread Pool (fs, dns, …). The thread pool size controlled by the `UV_THREADPOOL_SIZE` environment variable. Its default size is 4 ([documentation][libuv_thread_pool]). The pool is one for all tasks within a single Node process. - -Any code can make 4 real concurrent accesses to the file system. The rest of the FS requests will wait in the queue. - -> :book: Each new instance of FG in the same Node process will use the same Thread pool. - -But this package also has the `concurrency` option. This option allows you to control the number of concurrent accesses to the FS at the package level. By default, this package has a value equal to the number of cores available for the current Node process. This allows you to set a value smaller than the pool size (`concurrency: 1`) or, conversely, to prepare tasks for the pool queue more quickly (`concurrency: Number.POSITIVE_INFINITY`). - -So, in fact, this package can **only make 4 concurrent requests to the FS**. You can increase this value by using an environment variable (`UV_THREADPOOL_SIZE`), but in practice this does not give a multiple advantage. - -
- #### cwd * Type: `string` diff --git a/src/benchmark/suites/product/async.ts b/src/benchmark/suites/product/async.ts index 0f2166f9..8c7a0479 100644 --- a/src/benchmark/suites/product/async.ts +++ b/src/benchmark/suites/product/async.ts @@ -33,7 +33,6 @@ class Glob { cwd: this.#cwd, unique: false, followSymbolicLinks: false, - concurrency: Number.POSITIVE_INFINITY, })); } diff --git a/src/benchmark/suites/product/stream.ts b/src/benchmark/suites/product/stream.ts index 1ef56a4d..490b1384 100644 --- a/src/benchmark/suites/product/stream.ts +++ b/src/benchmark/suites/product/stream.ts @@ -49,7 +49,6 @@ class Glob { cwd: this.#cwd, unique: false, followSymbolicLinks: false, - concurrency: Number.POSITIVE_INFINITY, }); const action = new Promise((resolve, reject) => { diff --git a/src/benchmark/suites/regression/async.ts b/src/benchmark/suites/regression/async.ts index 28f67d03..f6b4a6cb 100644 --- a/src/benchmark/suites/regression/async.ts +++ b/src/benchmark/suites/regression/async.ts @@ -20,7 +20,6 @@ class Glob { this.#options = { unique: false, followSymbolicLinks: false, - concurrency: Number.POSITIVE_INFINITY, ...options, }; } diff --git a/src/benchmark/suites/regression/stream.ts b/src/benchmark/suites/regression/stream.ts index 3329d317..d22fdeb0 100644 --- a/src/benchmark/suites/regression/stream.ts +++ b/src/benchmark/suites/regression/stream.ts @@ -20,7 +20,6 @@ class Glob { this.#options = { unique: false, followSymbolicLinks: false, - concurrency: Number.POSITIVE_INFINITY, ...options, }; } diff --git a/src/providers/provider.spec.ts b/src/providers/provider.spec.ts index d1a8f942..bfbaa25e 100644 --- a/src/providers/provider.spec.ts +++ b/src/providers/provider.spec.ts @@ -75,7 +75,6 @@ describe('Providers → Provider', () => { const actual = provider.getReaderOptions(task); assert.strictEqual(actual.basePath, ''); - assert.strictEqual(actual.concurrency, settings.concurrency); assert.strictEqual(typeof actual.deepFilter, 'function'); assert.strictEqual(typeof actual.entryFilter, 'function'); assert.strictEqual(typeof actual.errorFilter, 'function'); diff --git a/src/providers/provider.ts b/src/providers/provider.ts index c24b7211..2f3057e1 100644 --- a/src/providers/provider.ts +++ b/src/providers/provider.ts @@ -40,7 +40,6 @@ export abstract class Provider { return { basePath, pathSegmentSeparator: '/', - concurrency: this.#settings.concurrency, deepFilter: this.deepFilter.getFilter(basePath, task.positive, task.negative), entryFilter: this.entryFilter.getFilter(task.positive, task.negative), errorFilter: this.errorFilter.getFilter(), diff --git a/src/settings.spec.ts b/src/settings.spec.ts index 0eddc02c..40b61298 100644 --- a/src/settings.spec.ts +++ b/src/settings.spec.ts @@ -1,5 +1,4 @@ import * as assert from 'node:assert'; -import * as os from 'node:os'; import Settings, { DEFAULT_FILE_SYSTEM_ADAPTER } from './settings'; @@ -26,7 +25,6 @@ describe('Settings', () => { assert.ok(settings.globstar); assert.ok(settings.onlyFiles); assert.ok(settings.unique); - assert.strictEqual(settings.concurrency, os.cpus().length); assert.strictEqual(settings.cwd, process.cwd()); }); diff --git a/src/settings.ts b/src/settings.ts index d16e7757..697bdeea 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -1,5 +1,4 @@ import * as fs from 'node:fs'; -import * as os from 'node:os'; import type { FileSystemAdapter, Pattern } from './types'; @@ -38,13 +37,6 @@ export interface Options { * @default true */ caseSensitiveMatch?: boolean; - /** - * Specifies the maximum number of concurrent requests from a reader to read - * directories. - * - * @default os.cpus().length - */ - concurrency?: number; /** * The current working directory in which to search. * @@ -153,7 +145,6 @@ export default class Settings { public readonly baseNameMatch: boolean; public readonly braceExpansion: boolean; public readonly caseSensitiveMatch: boolean; - public readonly concurrency: number; public readonly cwd: string; public readonly deep: number; public readonly dot: boolean; @@ -177,11 +168,6 @@ export default class Settings { this.baseNameMatch = options.baseNameMatch ?? false; this.braceExpansion = options.braceExpansion ?? true; this.caseSensitiveMatch = options.caseSensitiveMatch ?? true; - /** - * The `os.cpus` method can return zero. We expect the number of cores to be greater than zero. - * https://github.com/nodejs/node/blob/7faeddf23a98c53896f8b574a6e66589e8fb1eb8/lib/os.js#L106-L107 - */ - this.concurrency = options.concurrency ?? Math.max(os.cpus().length, 1); this.cwd = options.cwd ?? process.cwd(); this.deep = options.deep ?? Number.POSITIVE_INFINITY; this.dot = options.dot ?? false;