Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create metric for worker lambda processing rate #795

Merged
merged 6 commits into from
Oct 24, 2022

Conversation

DavidLawes
Copy link
Contributor

@DavidLawes DavidLawes commented Oct 21, 2022

What does this change?

We currently use metrics to see the performance of the whole system. For worker lambdas we have a metric for the processing time, which includes the length of time a message sits on a queue. This is great for determining the impact of changes to the overall performance.

In future PRs we are going to test using batch api calls. This PR adds a new metric to enable us to evaluate improvements to the lambda function.

The functionProcessingRate is a metric for how quickly we process tokens. The rate is calculated by:

number of tokens processed by a particular function invocation / function processing time in seconds

The result is that we get a metric representing the number of tokens being processed per second.

To capture this metric there were a number of changes required:

  • Refactor the sender request handler to abstract logging code into Logger class
  • Capture the start time of the function (we actively didn't want to use the sentTime, i.e. when the message landed on the queue, instead capturing when the function starts)
  • Refactor when we determine the function has completed. Through local testing we could see we create ("compile") our stream before executing it. We changed where we capture the end time to ensure this happened when a chunk of tokens had actually completed sending.
  • Calculate the function processing rate using the function start time, end time and number of tokens
  • Extend cloudwatch embedded metrics to include new metric for function processing rate
  • Update local run to facilitate testing of embedded metrics

How to test

Locally we can test to ensure the lambda compiles and runs successfully. We can see in the log messages that the relevant data was being created.

To test the new embedded metric the lambda logs needed to be parsed by AWS. I deployed to CODE and checked that we could see the lambda metric being recorded via the AWS console.

- refactor sender request handler to move logging code into Logger class
- capture the start time of the function
- calculate the function processing rate using the function start time, end time and number of tokens
- extend cloudwatch embedded metrics to include new metric for function processing rate
- update local run to facilitate testing of embedded metrics
- log extra information to help validation of results in kibana
@DavidLawes
Copy link
Contributor Author

DavidLawes commented Oct 21, 2022

I can currently see the metrics appearing in aws cloudwatch, but the metric values are resolving to 0, always:

Screenshot 2022-10-21 at 15 04 49

This is different to the raw json value that's been parsed, which we can see in kibana:

Screenshot 2022-10-21 at 15 05 47

Will continue to investigate, but for reference the json log generated parses successfully against the schema aws provide for embedded metrics.

EDIT: I tried to be helpful by defining the decimal places of the rate, but this converted the type to a string, aws only accepts numbers. Now the metric is parsed as expected and is viewable in the console (non-zero):

Screenshot 2022-10-21 at 15 37 41

@DavidLawes DavidLawes marked this pull request as ready for review October 21, 2022 14:40
Copy link
Contributor

@waisingyiu waisingyiu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank @DavidLawes for the great work!

@DavidLawes DavidLawes merged commit 4e963aa into main Oct 24, 2022
@DavidLawes DavidLawes deleted the dlawes/worker-function-processing-metric branch October 24, 2022 08:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants