Running the profiler on your functions provides insight into how your code performs at different memory allocations, allowing you to make better decisions about how to configure your functions. This is because more memory provides greater computational capability, but it does not impact the response time of downstream services in network calls. Generally, CPU-bound Lambda functions see the most benefit when memory increases, whereas network-bound see the least. In this example, you can see that a function has the lowest cost at 1024 MB and 1536 MB of memory, but the fastest execution at 3008 MB: You can graph the results to visualize the performance and cost trade-off. You can also implement a CI/CD process to use this tool to automatically measure the performance of new functions you deploy. The input function is run in your AWS account, performing live HTTP calls and SDK interaction, to measure likely performance in a live production scenario. This tool uses AWS Step Functions to run multiple concurrent versions of a Lambda function at different memory allocations and measure the performance. While you can manually run tests on functions by configuring different memory allocations and measuring the time taken to complete, the AWS Lambda Power Tuning tool allows you to automate the process. Profiling functions with AWS Lambda Power TuningĬhoosing the memory allocated to Lambda functions is an optimization process that balances speed (duration) and cost. In these cases, increasing the memory can help resolve the compute or network bottlenecks. For CPU-bound and IO-bound functions, monitoring the duration can often provide more insight. This can help identify memory-bound functions. You can monitor functions with Amazon CloudWatch and set alarms if memory consumption is approaching the configured maximum. For a one-thousandth of a cent cost difference, the function has a 10-fold improvement in performance. When the memory is increased to 1024 MB, the duration average drops to 1.465 seconds, so the cost is $0.024638. In this case, at 128 MB, the function takes 11.722 seconds on average to complete, at a cost of $0.024628 for 1,000 invocations. As a result, the overall cost increase may be negligible or may even decrease.įor example, 1000 invocations of a function that computes prime numbers may have the following average durations at different memory levels: Memory However, in many cases, increasing the memory available causes a decrease in the duration. Gigabyte-seconds are the product of total memory (in gigabytes) and duration (in seconds). Since the Lambda service charges for the total amount of gigabyte-seconds consumed by a function, increasing the memory has an impact on overall cost if the total duration stays constant. If a function is CPU-, network- or memory-bound, then changing the memory setting can dramatically improve its performance. Adding more memory proportionally increases the amount of CPU, increasing the overall computational power available. The amount of memory also determines the amount of virtual CPU available to a function. ![]() If the function imports libraries or Lambda layers, or interacts with data loaded from Amazon S3 or Amazon EFS, it’s likely to be more performant with a higher memory allocation. However, 128 MB should usually only be used for the simplest of Lambda functions, such as those that transform and route events to other AWS services. The Lambda console defaults new functions to the smallest setting and many developers also choose 128 MB for their functions. You can configure the amount of memory allocated to a Lambda function, between 128 MB and 10,240 MB. ![]() Memory is the principal lever available to Lambda developers for controlling the performance of a function. This blog post explains the effect of the memory configuration on Lambda performance, and how to optimize static initialization code. Part 1 describes the Lambda execution environment lifecycle, and explains defining, measuring, and improving cold starts. ![]() This three-part series discusses performance optimization for Lambda-based applications. Consider the following AWS Lambda function: var i = 0 Įxports.In the Operating Lambda series, I cover important topics for developers, architects, and systems administrators who are managing AWS Lambda-based applications.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |