Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support profiling the startup phase of a Worker #8026

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

penalosa
Copy link
Contributor

@penalosa penalosa commented Feb 4, 2025

This PR adds two features (separate changesets):

  • Support for the --outfile argument for wrangler deploy, which outputs the exact Worker bundle that Wrangler will upload to the Cloudflare API. This has more information than just --outdir because it bakes in bindings & module types.
  • wrangler check startup, which profiles the startup time of a Worker and generates a .cpuprofile file that can be opened in Chrome DevTools/directly in VSCode for further investigation. Additionally, this is automatically generated when Wrangler encounters a startup time error from the API.

  • Tests
    • TODO (before merge)
    • Tests included
    • Tests not necessary because:
  • E2E Tests CI Job required? (Use "e2e" label or ask maintainer to run separately)
    • I don't know
    • Required
    • Not required because:
  • Public documentation

@penalosa penalosa requested a review from a team as a code owner February 4, 2025 17:01
Copy link

changeset-bot bot commented Feb 4, 2025

🦋 Changeset detected

Latest commit: 989f763

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
wrangler Minor
@cloudflare/vitest-pool-workers Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@penalosa penalosa force-pushed the penalosa/check-startup branch from 50f8524 to 682fc9b Compare February 4, 2025 17:18
Copy link
Contributor

github-actions bot commented Feb 4, 2025

A wrangler prerelease is available for testing. You can install this latest build in your project with:

npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13265276676/npm-package-wrangler-8026

You can reference the automatically updated head of this PR with:

npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/prs/8026/npm-package-wrangler-8026

Or you can use npx with this latest build directly:

npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13265276676/npm-package-wrangler-8026 dev path/to/script.js
Additional artifacts:

cloudflare-workers-bindings-extension:

wget https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13265276676/npm-package-cloudflare-workers-bindings-extension-8026 -O ./cloudflare-workers-bindings-extension.0.0.0-vd6e483add.vsix && code --install-extension ./cloudflare-workers-bindings-extension.0.0.0-vd6e483add.vsix

create-cloudflare:

npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13265276676/npm-package-create-cloudflare-8026 --no-auto-update

@cloudflare/kv-asset-handler:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13265276676/npm-package-cloudflare-kv-asset-handler-8026

miniflare:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13265276676/npm-package-miniflare-8026

@cloudflare/pages-shared:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13265276676/npm-package-cloudflare-pages-shared-8026

@cloudflare/unenv-preset:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13265276676/npm-package-cloudflare-unenv-preset-8026

@cloudflare/vite-plugin:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13265276676/npm-package-cloudflare-vite-plugin-8026

@cloudflare/vitest-pool-workers:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13265276676/npm-package-cloudflare-vitest-pool-workers-8026

@cloudflare/workers-editor-shared:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13265276676/npm-package-cloudflare-workers-editor-shared-8026

@cloudflare/workers-shared:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13265276676/npm-package-cloudflare-workers-shared-8026

@cloudflare/workflows-shared:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13265276676/npm-package-cloudflare-workflows-shared-8026

Note that these links will no longer work once the GitHub Actions artifact expires.


[email protected] includes the following runtime dependencies:

Package Constraint Resolved
miniflare workspace:* 3.20250129.0
workerd 1.20250204.0 1.20250204.0
workerd --version 1.20250204.0 2025-02-04

Please ensure constraints are pinned, and miniflare/workerd minor versions match.

@penalosa penalosa force-pushed the penalosa/check-startup branch 2 times, most recently from 71e85b3 to 07d1f70 Compare February 4, 2025 18:14
packages/miniflare/src/index.ts Outdated Show resolved Hide resolved
packages/miniflare/src/index.ts Outdated Show resolved Hide resolved
packages/wrangler/src/deploy/deploy.ts Show resolved Hide resolved
packages/wrangler/src/deploy/index.ts Show resolved Hide resolved
packages/wrangler/src/deploy/index.ts Outdated Show resolved Hide resolved
packages/wrangler/src/utils/friendly-validator-errors.ts Outdated Show resolved Hide resolved
packages/wrangler/src/utils/friendly-validator-errors.ts Outdated Show resolved Hide resolved
@penalosa penalosa force-pushed the penalosa/check-startup branch from d6c31a2 to 650bd73 Compare February 7, 2025 16:22
@penalosa penalosa force-pushed the penalosa/check-startup branch from 650bd73 to 6d62eeb Compare February 7, 2025 18:10
@penalosa penalosa added the e2e Run wrangler e2e tests on a PR label Feb 10, 2025
Copy link
Contributor

@emily-shen emily-shen left a comment

Choose a reason for hiding this comment

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

Pages build already has an outfile, is this supposed to reuse that...? Can pages deploy fail due to startup time, and should this generate a cpuprofile if that's the case?

packages/wrangler/src/check/commands.ts Outdated Show resolved Hide resolved
packages/wrangler/src/check/commands.ts Outdated Show resolved Hide resolved

const mimeTypeModuleType = flipObject(moduleTypeMimeType);

export const checkNamespace = createNamespace({
Copy link
Contributor

Choose a reason for hiding this comment

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

not blocking, especially since its hidden, but it feels odd this has its own command. Do we anticipate other 'check' commands?

...maybe we should make wrangler deploy --dry-run a check command?? (come to think of it, maybe we should resurrect wrangler build for wrangler deploy --dry-run 🤔)
(these are only semi-serious suggestions)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree–we should definitely resurrect wrangler build!

In terms of the command structure here, I went with check startup since it seemed feasible that we might want to have other check * commands in future (check types? check config?), but since this is an alpha command we can always change that later.

@penalosa
Copy link
Contributor Author

Pages build already has an outfile, is this supposed to reuse that...?

It's meant to be doing that, yeah—does that seem buggy to you?

@emily-shen
Copy link
Contributor

Pages build already has an outfile, is this supposed to reuse that...?

It's meant to be doing that, yeah—does that seem buggy to you?

Ah no that’s fine, the lack of changes in the pages deploy path just threw me for a moment but it makes sense now.

Will the cpuprofile be generated automatically if a pages deploy fails?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
e2e Run wrangler e2e tests on a PR
Projects
Status: Approved
Development

Successfully merging this pull request may close these issues.

2 participants