Javascript Lambda functions takes ~200ms to execute

0

As simple as possible of a function:

export const main = async (event: any, context: any) => {
    return "Hello world!"
}

This lambda function takes ~200ms to execute when hot from a localhost call API.get("...", "/hello-world",{}).

How fast is a js lambda function approximately when hot (assuming closest region)?

I am located in Denmark and using EU-north as the region. I think 200ms for a hot lambda call is simply too high. Is this normal? If not, what might have caused this high timing?

I should add that I execute API.get("...", "/hello-world",{}) in the frontends and then check the timing column in the devtools, and that is where it says ~200ms each time when executing it.

I know I am using javascript and that partly might explain it, but still 200ms seems to high, I would expect no more than 100ms.

yasdfjb
asked 4 months ago154 views
2 Answers
0

How long is the round trip network from your local machine to the region?

In addition, you have both API Gateway and Lambda functions which both have some added latency.

To measure the actual Lambda time, you can look at CloudWatch logs at the REPORT line.

profile pictureAWS
EXPERT
Uri
answered 4 months ago
  • Sorry, just realized I posted my comment as an answer instead. Can you read the answer (which is not actually an answer) below please?

  • So based on your report lines, iy seems your function takes 126-194 ms for warm invocations. It takes 1.5 sec for cold invocations. This explains why you see the 200 ms from the client (network latency: ~ 25ms + API GW latency: ~ 30ms + Lambda duration).

    The duration of your function depends on what it does. I don't know what your function does, but if you think it is too long, try increasing the memory (it will get more CPU) and try profiling the code to find out where you are spending the time.

0

My latency-test (https://aws-latency-test.com/) for eu-north is 29ms! https://i.gyazo.com/052bea1d0f2e7afbeff8f77d21884c7d.png


Round-trip latency calculated on another website: https://i.gyazo.com/2d545f286876ec4519a7a19e4d1fa4a1.png It doesn't mention eu-north (europe - stockholm), but mentions (europe - frankfurt) at 35 ms.


My internet specs: 950Mbps download, 500Mbps upload


I looked at an request to the "hello-world lambda", here are all the lines with "report" in them (I am not sure what to make of it. If it says "Duration: 194.11 ms", does that mean the lambda is the bottleneck taking that long to execute. Meaning, the round-trip is actually very-low and not the problem here?):

REPORT RequestId: f54f5c18-3e16-4c86-924f-fc6b91c56819 Duration: 775.76 ms Billed Duration: 776 ms Memory Size: 1024 MB Max Memory Used: 127 MB Init Duration: 739.80 ms XRAY TraceId: 1-6593dcb9-222d2201694be8e90f7ec013 SegmentId: 1717f27339b7166e Sampled: true

REPORT RequestId: 80a52e0e-ce2f-4fa9-9ab3-cbba077c377d Duration: 194.11 ms Billed Duration: 195 ms Memory Size: 1024 MB Max Memory Used: 128 MB XRAY TraceId: 1-6593dcc4-5ac1a3353cf5e80a7f20d5ed SegmentId: 4863eb7209550a79 Sampled: true

REPORT RequestId: a9383d99-1344-4a70-bb58-c01b45d92522 Duration: 131.87 ms Billed Duration: 132 ms Memory Size: 1024 MB Max Memory Used: 128 MB XRAY TraceId: 1-6593dcc5-102277c31ff856e37e7adf8c SegmentId: 1002e494397385f0 Sampled: true

REPORT RequestId: 2ea5e015-f451-4b09-a729-67f8b5ca0bc0 Duration: 126.08 ms Billed Duration: 127 ms Memory Size: 1024 MB Max Memory Used: 128 MB XRAY TraceId: 1-6593dcc5-5dfcbea5297c6baa29c0a0a2 SegmentId: 7395974264634bc9 Sampled: true

yasdfjb
answered 4 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions