Worker request time increased drastically after deployment

Hey there, before my deployment i had a quite low request time, usually below a second, only a few hundred milliseconds. But all of a sudden after a few deployments my worker request times went up to 4 or 5 seconds. My worker really doesnt do much besides a few DB requests and console logs, but no extreme loops or anything, and is written in js. The only thing i changed was adding a lookup table for country codes to get the country the request was made from, so
const countryLookup = {
AF: 'Afghanistan',
AL: 'Albania',
DZ: 'Algeria',
AS: 'American Samoa',
AD: 'Andorra',
AO: 'Angola',
AI: 'Anguilla',
...
const countryLookup = {
AF: 'Afghanistan',
AL: 'Albania',
DZ: 'Algeria',
AS: 'American Samoa',
AD: 'Andorra',
AO: 'Angola',
AI: 'Anguilla',
...
but that was actually it. I cant explain to myself how or why the request times went up by so much, but maybe that isnt even the issue and something else.. Any ideas? Also for the metrics, median CPU time is 7 ms, wall time is 3000ms and execution duration is 37.8 GB-sec.
8 Replies
Chaika
Chaika2mo ago
So if your median CPU Time is decent it wouldn't be related to the country lookup, and instead should be in a subrequest or d1 query/binding call you're doing. I would time them all with performance.now() and see how long each one takes. The D1 Console page may also show something interesting for your database under Metrics -> Query Latency
Spuckwaffel
SpuckwaffelOP2mo ago
my query latency is 0ms apparently
No description
Spuckwaffel
SpuckwaffelOP2mo ago
for D1 as its all just primary key queries how are subrequests defined in my worker? I dont do any requests to any websites or anything, just D1 and KV
Spuckwaffel
SpuckwaffelOP2mo ago
these are my KV latencies
No description
Chaika
Chaika2mo ago
Subrequest is any request to another cf service (kv/d1) or an actual url via fetch
Spuckwaffel
SpuckwaffelOP2mo ago
in my js i just use awaits but only for DB requests or KVs if that might be related yea i dont use any fetch okay so magically all requests are now back to their usual times, but all metrics are the same....
Chaika
Chaika2mo ago
If your request time is high, and it's not in your cpu time, your metrics show high wall time, so it should be in one of the kv/d1 calls if that's all you're doing. Maybe an excessive amount that adds up quickly or something? Eitherway I'd just wrap in
const start = performance.now(); //external subrequest (kv, d1, etc) const end = performance.now(); const timing = end - start;
then log that timing + your op name, so you can what's being slow
Spuckwaffel
SpuckwaffelOP2mo ago
alright, from now on i will use that, thank you!
Want results from more Discord servers?
Add your server