Optimise network performance across endpoints #346
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
We’ve seen quite a high time-to-first-byte (TTFB) on
GET /letters.I took a quick look to see if there are any low-risk quick wins that could reduce response time without changing any behaviour.
This is motivated by the "AT15 – Performance testing" acceptance testing requirement.
1. Lambda memory allocation
The
get-lettersLambda appears to be configured with a low memory setting.Increasing memory size in Lambda functions also increases available CPU and network bandwidth, which can reduce latency (and often cost) for functions with network I/O.
AWS only recommends 128 MB for very simple functions, based on the work going on in this function I think it'd benefit from an increased setting. I've set all functions to 512 MB as a baseline, and get-letters to 1024 MB.
Ref: https://docs.aws.amazon.com/lambda/latest/dg/configuration-memory.html#configuration-memory-use-cases
2. Pretty-printed JSON responses
It looks like the handler returns formatted JSON (indentation/newlines).
Bearing in mind get-letters returns a large payload, this would add:
Returning compact JSON would be functionally identical, just smaller/faster and reduced network bandwidth. On one test it was around ~40% reduction in payload size.
The indention formatting has been removed from responses.
3. Max results per call
In the testing Q&A: "The API has been restricted to have 1500 letters being returned per call…" I wondered whether max_get_limit should be aligned with that (to avoid the API returning more than intended).
Context
This PR attempts to optimise network performance across lambda functions without changing code or behaviour, giving consumers additional time budget in performance testing.
Type of changes
Checklist
Sensitive Information Declaration
To ensure the utmost confidentiality and protect your and others privacy, we kindly ask you to NOT including PII (Personal Identifiable Information) / PID (Personal Identifiable Data) or any other sensitive data in this PR (Pull Request) and the codebase changes. We will remove any PR that do contain any sensitive information. We really appreciate your cooperation in this matter.