Functions Response Time being 2s+


I’m in the process of writing a small dummy app mostly to test out Netlify and have so far had an excellent experience. I have reached a small snag, and mostly just wanted to get some insight into netlify function response times and why they might be slower than I would expect.

Here’s the function in question:

When testing locally, I am seeing response times within 200-300ms, which is about what I would expect for a call like this.

Here’s a local log just to show me testing the speed of execution internally:
Request from ::1: GET /.netlify/functions/myFirstFunction?name=Ses
start ms: 1588961969924
Cache hit for Ses
end ms: 1588961970124
duration: 200 ms
Response with status 200 in 203 ms.

Here’s a log from the function running on netlify in production:
2:16:21 PM: 2020-05-08T18:16:21.581Z e1db1dea-a661-4632-81da-0b1e13b862d4 INFO start ms: 1588961781580
2:16:21 PM: 2020-05-08T18:16:21.695Z e1db1dea-a661-4632-81da-0b1e13b862d4 INFO Cache hit for Ses
2:16:21 PM: 2020-05-08T18:16:21.695Z e1db1dea-a661-4632-81da-0b1e13b862d4 INFO end ms: 1588961781695
2:16:21 PM: 2020-05-08T18:16:21.695Z e1db1dea-a661-4632-81da-0b1e13b862d4 INFO duration: 115 ms
2:16:24 PM: Duration: 2908.85 ms Memory Usage: 85 MB Init Duration: 400.03 ms

You can see that the response time is approx 2.9s, which I feel is pretty slow. Being on the free tier, I know I am not a prioritized resource or cache, and I would love to get some insight on the difference between the code execution time I’m seeing (approx 100-200ms) and the actual response time of between 2 and 4 seconds.

If I call the function repeatedly, I’m still seeing similar response times, so I don’t think it’s related to cold startup or anything like that.

I’m trying to use the “preformatted text” thing in the post editor and it doesn’t appear to be changing anything. Apologies for the lack of formatting.

I’m not sure but based on your function logs, the function is invoked and it does its things pretty quickly. The delay happens after. It seems like there is a pause before your function calls the callback function. Are you doing anything async in your function?

1 Like

Definitely am doing async stuff–I decided to set this function up on AWS raw this morning and it’s doing exactly the same thing there–so I can confirm it’s not Netlify adding any processing or overhead. Gonna investigate further and will update this thread once I determine what the issue is!

1 Like

Wanted to provide a quick update:

I rewrote my handler to use async await syntax, and it turns out I was definitely doing processing that didn’t need to be done.

This was entirely my fault and was a simply async-processing related issue. Thanks @Dennis for the reply, appreciate it!

Seeing response times in the 100-200ms range now!

1 Like