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 - Response headers that may be helpful : 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" - 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
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server