PrismaP
Prisma12mo ago
3 replies
CeeJay

Cloudflare D1 Performance

I'm doing a straight forward query of a small DB from a cloudflare worker (with Hono) using Prisma. Locally the query take 8ms (measured from worker), but on the cloud the query takes between 200ms to over 1s.

start = performance.now()
if (c.get('caller') !== 'worker') {
  return c.json({ error: 'Unauthorized caller' }, 401)
}
const clip = await prisma.videoClip.findFirst({
  where: {
    status: 'waiting'
  },
  orderBy: {
    createdAt: 'desc'
  }
});

let end = performance.now()
console.log(`PERFLOG [JOB NEXT RETRIEVE]: ${c.req.method} ${c.req.url} ${end - start}ms`)


Cloudflare D1 reports that the queries are taking less than 1ms. Also I think the calls are generating lots of cpuTime which is adversely affecting my service given it routinely exceeds the limits.

There are two issues: the latency and the (reported) CPU consumption - how can I further diagnose / remedy?
Was this page helpful?