Skip to content
Open
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
1 change: 1 addition & 0 deletions src/ipc-types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ interface FeatureFlags {

interface BetaFeatures {
studioSitesCli: boolean;
multiWorkerSupport: boolean;
}

interface AppGlobals extends FeatureFlags {
Expand Down
6 changes: 6 additions & 0 deletions src/lib/beta-features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ const BETA_FEATURES_DEFINITION: Record< keyof BetaFeatures, BetaFeatureDefinitio
default: false,
description: '"studio site" command to manage local sites from terminal',
},
multiWorkerSupport: {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Documentation suggestion: The description is clear, but you might want to add a note about system requirements or performance characteristics:

description: 'Enable experimental multi-worker PHP processing for faster performance on multi-core systems',

This helps users understand that the benefit is tied to having multiple CPU cores available.

label: 'Multi-Worker Support',
key: 'multiWorkerSupport',
default: false,
description: 'Enable multi-worker PHP processing for faster performance',
},
} as const;

export const BETA_FEATURES: Record< keyof BetaFeatures, BetaFeatureDefinition > =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { RecommendedPHPVersion } from '@wp-playground/common';
import { recursiveCopyDirectory, pathExists, isWordPressDirectory } from 'common/lib/fs-utils';
import { DEFAULT_LOCALE } from 'common/lib/locale';
import { isOnline } from 'common/lib/network-utils';
import { getBetaFeatures } from 'src/lib/beta-features';
import { getPreferredSiteLanguage } from 'src/lib/site-language';
import { keepSqliteIntegrationUpdated } from 'src/lib/sqlite-versions';
import { isValidWordPressVersion } from 'src/lib/wordpress-version-utils';
Expand All @@ -25,6 +26,7 @@ export interface PlaygroundCliOptions {
autoMount: boolean;
skipWordpressSetup: boolean;
blueprint?: Blueprint;
enableMultiWorker?: boolean;
}

export const PLAYGROUND_CLI_PROVIDER_NAME = 'playground-cli';
Expand Down Expand Up @@ -65,13 +67,21 @@ export class PlaygroundCliProvider implements WordPressProvider {
const phpVersion = options.phpVersion || '8.3';
const hasWordPress = isWordPressDirectory( options.path );

// Get beta features to check if multi-worker support is enabled
const betaFeatures = await getBetaFeatures();

if ( betaFeatures.multiWorkerSupport ) {
console.log( '[PlaygroundCliProvider] Multi-worker support is enabled via beta features' );
}

const playgroundOptions: PlaygroundCliOptions = {
port,
phpVersion,
documentRoot: options.path,
autoMount: true,
skipWordpressSetup: hasWordPress,
blueprint: options.blueprint,
enableMultiWorker: betaFeatures.multiWorkerSupport,
};

const serverOptions: WordPressServerOptions = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { cpus } from 'os';
import { SupportedPHPVersion, PHPRunOptions } from '@php-wasm/universal';
import { runCLI, RunCLIArgs, RunCLIServer } from '@wp-playground/cli';
import { sanitizeRunCLIArgs } from 'src/lib/sentry-sanitizer';
Expand Down Expand Up @@ -161,6 +162,7 @@ async function startServer(
const defaultConstants = {
WP_SQLITE_AST_DRIVER: true,
};

const mounts = [
{
hostPath: options.documentRoot,
Expand Down Expand Up @@ -189,6 +191,15 @@ async function startServer(
skipWordPressSetup: options.skipWordpressSetup,
};

// Enable multi-worker support if beta feature is enabled
if ( options.enableMultiWorker ) {
const workerCount = Math.max( 1, cpus().length - 1 );
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Edge case consideration: On systems with 1 CPU core, Math.max(1, cpus().length - 1) would return 1 worker. While this is safe, it means multi-worker mode effectively does nothing on single-core systems.

Consider either:

  1. Adding a minimum threshold check (e.g., only enable if cpus().length >= 2)
  2. Documenting this behavior
  3. Logging a warning if cpus().length === 1

Example:

if ( options.enableMultiWorker ) {
	const cpuCount = cpus().length;
	if ( cpuCount === 1 ) {
		console.log( '[playground-cli] Multi-worker support enabled but system has only 1 CPU core, using 1 worker' );
	}
	const workerCount = Math.max( 1, cpuCount - 1 );
	// ...
}

Not blocking, but worth considering for better UX.

console.log(
`[playground-cli] Enabling experimental multi-worker support with ${ workerCount } workers (CPU cores - 1)`
);
args.experimentalMultiWorker = workerCount;
}

if ( options.phpVersion ) {
args.php = options.phpVersion as SupportedPHPVersion;
}
Expand All @@ -207,6 +218,13 @@ async function startServer(

server = await runCLI( args );

// Log actual worker count for verification
if ( options.enableMultiWorker ) {
console.log(
`[playground-cli] Server started with ${ server.workerThreadCount } worker thread(s)`
);
}

if ( serverOptions.adminPassword ) {
await setAdminPassword( server, serverOptions.adminPassword );
}
Expand Down