CF-Changes Workers, Durable Objects - CPU and heap profiling for Worker Previews

Cloudflare Reporting - Product Changelog

ENF News Bot

Automated News Bot
Joined
Apr 15, 2022
Messages
4,382
You can now profile Worker Previews, following the launch of on-demand CPU and memory profiling ↗︎ for Workers and Durable Objects. This lets you see what a pull request costs in CPU and memory before you merge it.

Send traffic to a Preview, capture a CPU or heap profile from one of its deployments, and see which functions in your branch use the most CPU time or memory. Push a fix, profile the next deployment, and compare. Production stays untouched the whole time.

Flamegraph of a Preview CPU profile showing scoreProduct, tokenize, formatPrice, and buildProduct under handleSearch

In this Preview, formatPrice takes almost a third of the CPU time because it creates a new Intl.NumberFormat for every product. A slowdown like this is easy to miss in code review, but it stands out in a flamegraph.

Let your agent optimize performance​

https://developers.cloudflare.com/changelog/rss/#let-your-agent-optimize-performance

Previews give coding agents a safe place to iterate on performance. An agent can deploy a Preview, send it load, capture a profile, rewrite the hottest function, and deploy again, until CPU time stops dropping. Each Preview deployment has its own ID, so every profile maps to an exact version of the code.

light.svg
dark.svg
light.svg
dark.svg
light.svg
dark.svg
light.svg
dark.svg
Copy promptPrompt copied!
Capture a profile with the Cloudflare CLI:


Code:
cf previews deployments profile latest \
  --worker my-worker \
  --preview my-preview \
  --duration-ms 5000 \
  --profile-type cpu > preview-cpu.pprof

Or with the API. Use latest to target the newest deployment of the Preview:


Code:
curl --request POST \
  "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/workers/workers/$WORKER_ID/previews/$PREVIEW_ID/deployments/latest/profile" \
  --header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
  --header "Content-Type: application/json" \
  --data '{"duration_ms": 5000, "profile_type": "cpu"}' \
  --output preview-cpu.pprof.gz

Profile in the dashboard​

https://developers.cloudflare.com/changelog/rss/#profile-in-the-dashboard

Open your Preview, select Observability, and switch the view to Flamegraph. Choose a profile type and a Preview deployment, then select Capture profile. Explore the result as a flamegraph or table, or download the raw pprof file.

Profile Durable Objects on a Preview​

https://developers.cloudflare.com/changelog/rss/#profile-durable-objects-on-a-preview

Every Preview gets its own Durable Object namespaces. To see what one object is doing on your branch, profile it by ID, just like in production.

To get started, refer to Profile a Preview.

Continue reading...
 
Back
Top