D1 is so much slow : take 600+ms for a single user

I have connect d1 from cloudflire worker and used 'itty-router' Here is my code: const { results } = await env.DB.prepare(SELECT * FROM users).all(); return json(results);
9 Replies
Chaika
Chaika2mo ago
Did you create your D1 DB in a specific region? Alternatively, you can do npx wrangler d1 info <dbName> and look at running_in_region to see where it's running
Al Emran
Al EmranOP2mo ago
@Chaika thank you for reply . Yes I mention region Asia–Pacific. Here is the output of npx wrangler d1 info: DB │ d57481be-fa7f-4507-b1a4-e3f9a493ca63 │ ├───────────────────┼──────────────────────────────────────┤ │ name │ test │ ├───────────────────┼──────────────────────────────────────┤ │ created_at │ 2024-10-19T13:13:13.973Z │ ├───────────────────┼──────────────────────────────────────┤ │ num_tables │ 1 │ ├───────────────────┼──────────────────────────────────────┤ │ running_in_region │ APAC │ ├───────────────────┼──────────────────────────────────────┤ │ database_size │ 16.4 kB │ ├───────────────────┼──────────────────────────────────────┤ │ read_queries_24h │ 30 │ ├───────────────────┼──────────────────────────────────────┤ │ write_queries_24h │ 3 │ ├───────────────────┼──────────────────────────────────────┤ │ rows_read_24h │ 46 │ ├───────────────────┼──────────────────────────────────────┤ │ rows_written_24h │ 4 │ └───────────────────┴──────────────────────────────────────┘ also I am accessing from asia (Bangladesh)
Chaika
Chaika2mo ago
Which colo are you connecting to? You can see at https://income-expense-api.besnik.workers.dev/cdn-cgi/trace, after colo= is the airport code of the Cloudflare data center you are connecting to
Al Emran
Al EmranOP2mo ago
I don't know but https://income-expense-api.besnik.workers.dev/cdn-cgi/trace show Dhaka, but I am from sylhet city that beside Dhaka city
Chaika
Chaika2mo ago
What do you mean "it shows Dhaka"? What's the colo code/the data on the colo line?
Al Emran
Al EmranOP2mo ago
it's colo=DAC Also Checked from colo=ORD and it's take : Time: 1.251016 seconds
Chaika
Chaika2mo ago
well ORD is Chicago, and going all the way to Asia Pacific is going to be slow surprised you're getting routed locally, quite often people in Asia are routed to far away Europe PoPs. I tested from Osaka, JP and your endpoint is ~96ms. Checking your worker and D1 Database metrics would be smart. For Worker Metrics I would expect a Median CPU Time of only a few milliseconds at most, and a higher wall (end to end) time. For your D1 Database Metrics, I'd check Query Latency. Should be only a few milliseconds.
Al Emran
Al EmranOP2mo ago
Thank you @Chaika for your time ! In metrics it show below 1 ms. But I tested from Bangladesh colo=DAC and also from germany colo=ORD it take 600 +ms ,why ?
Want results from more Discord servers?
Add your server