© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Cloudflare DevelopersCD
Cloudflare Developers•15mo ago
Magnaboy

Slow worker response

My worked, running in a hotpath which simply returns a response from the cache, is taking 150ms and seems very slow. But after calling it a couple times, it becomes fast (30ms). But then after some very short amount of time, e.g. 30 seconds, it goes back to taking to 150ms. Is this just a cold startup time, or is it a bug/issue I can fix?

Code:
export default {
    async fetch(request, env, ctx): Promise<Response> {
        if (request.method === "OPTIONS") {
            return handleOptions(env, request);
        }
        const url = new URL(request.url);
        const path = url.pathname.substring(1);

        if (path.startsWith("api/")) {
            // Irrelevant
        }

        if (path && !path.startsWith("edit")) {
            const startx = performance.now();
            const response = await cache.match(getRequestForBio(path));
            console.log(`Cache lookup took ${performance.now() - startx}ms`);
                        // Real logs from worker: 
                        //
                        // "Cache lookup took 9ms"
                        // "Cache lookup took 10ms"
                        // "Cache lookup took 8ms" (rest are the same)
            if (response) {
                console.log(`Cache lookup for ${path} HIT. Returning cached response.`);
                return response;
            }
export default {
    async fetch(request, env, ctx): Promise<Response> {
        if (request.method === "OPTIONS") {
            return handleOptions(env, request);
        }
        const url = new URL(request.url);
        const path = url.pathname.substring(1);

        if (path.startsWith("api/")) {
            // Irrelevant
        }

        if (path && !path.startsWith("edit")) {
            const startx = performance.now();
            const response = await cache.match(getRequestForBio(path));
            console.log(`Cache lookup took ${performance.now() - startx}ms`);
                        // Real logs from worker: 
                        //
                        // "Cache lookup took 9ms"
                        // "Cache lookup took 10ms"
                        // "Cache lookup took 8ms" (rest are the same)
            if (response) {
                console.log(`Cache lookup for ${path} HIT. Returning cached response.`);
                return response;
            }


Other information:
- Worker URL: https://nicebioworker.cf-edge.workers.dev/magnaboy . The response is a small 2kb html page.
- Timing/latency as reported by chrome devtools:
Request sent: 0.23ms | Waiting for server response: 142.95ms Content download: 0.34ms
Request sent: 0.23ms | Waiting for server response: 142.95ms Content download: 0.34ms

- Response headers that may be helpful :
cf-cache-status:HIT
cf-cache-status:HIT

server-timing:=cfL4;desc="proto=TCP&rtt=18223&sent=19&recv=21&lost=0&retrans=0&sent_bytes=4324&recv_bytes=3077&delivery_rate=430668&cwnd=235&unsent_bytes=0&cid=95e6d5e7810fc682&ts=322625&x=0"
server-timing:=cfL4;desc="proto=TCP&rtt=18223&sent=19&recv=21&lost=0&retrans=0&sent_bytes=4324&recv_bytes=3077&delivery_rate=430668&cwnd=235&unsent_bytes=0&cid=95e6d5e7810fc682&ts=322625&x=0"

- Although I also use KV/D1, they are not being called in anyway in this code path.
- I am using workers paid.
- I don't think I have any cloudflare settings enabled whatsoever that would
Cloudflare Developers banner
Cloudflare DevelopersJoin
Welcome to the official Cloudflare Developers server. Here you can ask for help and stay updated with the latest news
85,042Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Slow Response Time
Cloudflare DevelopersCDCloudflare Developers / workers-and-pages-help
15mo ago
D1 Response time slow
Cloudflare DevelopersCDCloudflare Developers / workers-and-pages-help
16mo ago
30s+ Worker response times
Cloudflare DevelopersCDCloudflare Developers / workers-and-pages-help
2mo ago
Worker response not streaming
Cloudflare DevelopersCDCloudflare Developers / workers-and-pages-help
15mo ago