
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/">
    <channel>
        <title><![CDATA[ The Cloudflare Blog ]]></title>
        <description><![CDATA[ Get the latest news on how products at Cloudflare are built, technologies used, and join the teams helping to build a better Internet. ]]></description>
        <link>https://blog.cloudflare.com</link>
        <atom:link href="https://blog.cloudflare.com/" rel="self" type="application/rss+xml"/>
        <language>en-us</language>
        <image>
            <url>https://blog.cloudflare.com/favicon.png</url>
            <title>The Cloudflare Blog</title>
            <link>https://blog.cloudflare.com</link>
        </image>
        <lastBuildDate>Wed, 15 Apr 2026 19:11:06 GMT</lastBuildDate>
        <item>
            <title><![CDATA[Profiling Your Workers with Wrangler]]></title>
            <link>https://blog.cloudflare.com/profiling-your-workers-with-wrangler/</link>
            <pubDate>Sat, 18 Sep 2021 12:59:17 GMT</pubDate>
            <description><![CDATA[ To help measure performance of our customers’ Workers, we’re beginning to integrate with the Chrome DevTools protocol. ]]></description>
            <content:encoded><![CDATA[ <p></p><p>In the year since Cloudflare’s launch of Workers Unbound, developers have unlocked the ability to run computationally intensive workloads on the Cloudflare edge network — like image processing, game logic, and other complex algorithms. With all that additional computing power comes a host of questions around performance. Our customers often ask us how they can profile or monitor their Workers to see where they spend the most CPU time, or to see whether their changes improve performance.</p><p>Here at Cloudflare, we not only want to build the fastest, most affordable, and most flexible compute platform at the edge; we also want to make the lives of our developers easier in building their applications. To do this, Cloudflare has begun to integrate with existing tools — places our developers feel comfortable and efficient in their day-to-day work. To help measure performance of our customers’ Workers, we’re beginning to integrate with the Chrome DevTools protocol. Just like you can use chrome://inspect to debug your Node backend, you can also use it to profile your Cloudflare Workers.</p>
    <div>
      <h3>Introducing Chrome DevTools Integration (Beta)</h3>
      <a href="#introducing-chrome-devtools-integration-beta">
        
      </a>
    </div>
    <p>We’re starting off this integration with beta support for local CPU profiling, using Wrangler. To show off how to use this feature, I’m going to be optimizing a simple JavaScript program which outputs the first thousand integers separated by a space. Let’s start by installing the latest version of <a href="https://github.com/cloudflare/wrangler/#installation">Wrangler</a>. We’ll also need a Worker cloned down to your local machine. I’ll be using <a href="https://github.com/kabirsikand/workers-profiling-example/blob/main/slow-worker.js">Workers Profiling Example</a>, but feel free to use any CPU intensive Worker for this tutorial.</p><p>For reference, my sample code is below. You’ll notice this code is intentionally performing a computation that will slow down our Worker.</p>
            <pre><code>addEventListener("fetch", event =&gt; {
  event.respondWith(handleRequest(event.request));
});

async function handleRequest(request) {
  let body = '';
  for (let i = 0; i &lt; 1000; ++i) {
    body = body + ' ' + i;
  }

  return new Response(body, {
    headers: { 'content-type': 'text/plain' },
  });
}</code></pre>
            <p>To confirm this, we’ll run Chrome DevTools and profile our Worker locally. In the directory of your sample project, <code>run wrangler dev --inspect</code>. To launch the DevTools, open <code>chrome://inspect</code> in Chrome or Chromium. You’ll see Chrome’s DevTools homepage pop up:</p>
            <figure>
            
            <img src="https://cf-assets.www.cloudflare.com/zkvhlag99gkb/79e6ioOYPp1SjNBLWEhLWK/d910cbfd5f0ee881541d497c60798baf/image1-22.png" />
            
            </figure><p>Click ‘Configure’ and add <code>localhost://9230</code> as one of the targets. You should see <code>wrangler[{Worker name}]</code> appear under “Remote Targets”, where {Worker name} is the name of your project.</p>
            <figure>
            
            <img src="https://cf-assets.www.cloudflare.com/zkvhlag99gkb/5i0wiIOb2mQG9ZPZseyEdk/2b98a89b3e815f9be0583d10fee9e94e/image2-27.png" />
            
            </figure><p>Click ‘inspect’, then in the popup, ‘Profiler’.</p>
            <figure>
            
            <img src="https://cf-assets.www.cloudflare.com/zkvhlag99gkb/2Kc0LIb3k3O1ldfl18jCBP/380c4f36d6b5d97521a2e3b92aad3ddb/image4-21.png" />
            
            </figure><p>Click ‘Start’ and, in a different browser tab, make a few requests to your site, then click ‘Stop’. It should be available locally on localhost:8787.</p><p>Analyze the flame graph. For my Slow Worker, I see the following graph:</p>
            <figure>
            
            <img src="https://cf-assets.www.cloudflare.com/zkvhlag99gkb/4cA7Ng90JMS4Nt6LOOZI0p/28dda2434c4244a9c9ec4c01bc5e9f1b/image3-25.png" />
            
            </figure><p>When I click on <code>handleRequest</code>, I see the following annotated source of my Worker:</p>
            <figure>
            
            <img src="https://cf-assets.www.cloudflare.com/zkvhlag99gkb/2rQDvm2MGfpBNwWgT7nobE/246a004a99f6e3322a8cd4be0e02b6f6/image5-19.png" />
            
            </figure><p>In particular, it shows that, unsurprisingly, most of the time is being spent on memory allocations in the body of the loop. Note that the profiler is not always accurate with regard to exact timing, but does paint a picture of your largest bottlenecks.</p>
    <div>
      <h3>Understanding the Profile</h3>
      <a href="#understanding-the-profile">
        
      </a>
    </div>
    <p>The profiler works by gathering a stack trace of your program at a sampled rate, so remember that the profile is an approximation of where your code tends to spend the majority of its execution time, and is not meant to be perfectly accurate. In fact, functions that execute in less than 100 microseconds have a chance to not appear in the profile at all.</p>
    <div>
      <h3>What’s Next?</h3>
      <a href="#whats-next">
        
      </a>
    </div>
    <p>With the Workers platform, we’re striving to build in the <a href="https://www.cloudflare.com/learning/performance/what-is-observability/">observability</a> our users expect out of a robust compute platform. We’d love to hear more from the community about ways we can improve visibility into the code you’re writing on the edge. If you haven’t already, please join the Cloudflare Workers Discord community at <a href="https://discord.gg/PX8s2TmJ7s">https://discord.gg/PX8s2TmJ7s</a>. Happy building!</p><div></div><p></p> ]]></content:encoded>
            <category><![CDATA[Speed Week]]></category>
            <category><![CDATA[Wrangler]]></category>
            <category><![CDATA[Cloudflare Workers]]></category>
            <category><![CDATA[Developers]]></category>
            <category><![CDATA[Developer Platform]]></category>
            <guid isPermaLink="false">5qfyGhFsuFodg8NQiKq0BX</guid>
            <dc:creator>Joshua Nelson</dc:creator>
            <dc:creator>Kabir Sikand</dc:creator>
        </item>
    </channel>
</rss>