使用Lambda Power Tuner UI节省资金并提高性能

这个故事到底是关于什么的?(What is this story all about?)

Through my serverless projects and AWS experience as a Solutions Engineer at Liberty IT, I have became an AWS CDK enthusiast and below is a story about how I open sourced an innovation aimed at helping developers and large organisations.

通过我的无服务器项目以及AWS在Liberty IT担任解决方案工程师的经验,我成为了AWS CDK的狂热者,下面是一个有关我如何开源旨在帮助开发人员和大型组织的创新的故事。

If you want to skip to the setup, follow the GitHub instructions here or read on to find out how this came about and the features of this CDK project.

如果您想跳到安装程序,请按照此处的GitHub指示进行操作或继续阅读以了解它的产生方式以及该CDK项目的功能。

Image for post
Deployed website allowing power tuning with a few simple values
部署的网站允许通过一些简单的值进行功率调整

基础:alexcasalboni的功率调谐器阶跃功能(The foundation: alexcasalboni’s power tuner step function)

Alex Casalboni is an extremely well known AWS developer advocate and developed the AWS Lambda Power Tuning project. This is a state machine powered by AWS Step Functions that helps you optimise your Lambda functions for cost and/or performance in a data-driven way.

Alex Casalboni是一位非常著名的AWS开发人员拥护者,并开发了AWS Lambda Power Tuning项目。 这是由AWS Step Functions驱动的状态机,可帮助您以数据驱动的方式优化Lambda函数以实现成本和/或性能。

There are many ways to deploy this functionality into your AWS environment from:

有多种方法可以通过以下方式将此功能部署到您的AWS环境中:

  • AWS Serverless Application Repository (SAR)

    AWS无服务器应用程序存储库(SAR)
  • Fork the repo and deploy with AWS SAM

    分叉存储库并使用AWS SAM进行部署
  • Deploy the SAR app with an AWS CDK wrapper (created by my colleague Matt Coulter)

    使用AWS CDK包装器部署SAR应用程序(由我的同事Matt Coulter创建)

在组织内部署和执行电源调谐器 (Deploying and executing the power tuner within an organisation)

The above options are great to deploy the base Step function infrastructure but how do you call/execute the state machine? CLI, Manually through the AWS Console, API Gateway?

上面的选项对于部署基本的Step函数基础结构非常有用,但是如何调用/执行状态机呢? CLI,是否通过AWS控制台手动进行API网关?

Let’s look at two teams within an organisation and consider their setup and user experience:

让我们看一下组织中的两个团队,并考虑他们的设置和用户体验:

  • Team X deploys the stack via SAR, create an IAM user and invoke via AWS CLI

    X团队通过SAR部署堆栈,创建IAM用户并通过AWS CLI调用
  • Team Y deploys the stack via SAM, front it with an API Gateway and hit via postman.

    Y小组通过SAM部署堆栈,在其前面放置API网关,然后通过邮递员命中。

This flexibility is great but this leads to differing user experience interacting with the power tuner, differing setup instructions in dreaded wikis and knowledge fragmenting depending on the path.

这种灵活性非常好,但这会导致与电源调谐器进行交互的用户体验不同,在可怕的Wiki中不同的设置说明以及取决于路径的知识分散。

Image for post

现在……电源调谐器用户界面 (Now … the power tuner UI)

I saw an opportunity within my organisation to centralise and improve the user experience for power tuning Lambda functions within AWS by creating an easy to use centralised UI. This solution abstracts away the implementation of the tuner through the simplicity of AWS CDK and lowers the barrier of entry to this essential activity.

我看到组织内部有机会通过创建易于使用的集中式UI来集中和改善用户体验,从而在AWS中对Lambda功能进行功率调整。 该解决方案通过AWS CDK的简单性简化了调谐器的实现,并降低了进入此基本活动的障碍。

The architecture is as follows:

架构如下:

  • Angular 9 website fronted via Amazon CloudFront & Amazon S3

    Angular 9网站通过Amazon CloudFront和Amazon S3领先
  • Amazon API Gateway using direct integrations to AWS Step functions

    使用与AWS Step函数的直接集成的Amazon API Gateway
  • Alex’s Power Tuning State Machine

    亚历克斯的功率调整状态机
Image for post

The website allows any developer to run the power tuner in their AWS account through simple CDK commands without worrying about IAM users, CLI commands, infrastructure etc.

该网站允许任何开发人员通过简单的CDK命令在其AWS账户中运行电源调谐器,而无需担心IAM用户,CLI命令,基础架构等。

Once deployed into your AWS account, developers need to know only the ARN of the lambda and tweak the various settings to their own liking and simply click Start power tuner.

一旦部署到您的AWS账户中,开发人员只需知道lambda的ARN,并根据自己的喜好调整各种设置,只需单击Start power tuner。

Image for post

The tuner will generate a visualisation of average cost and speed for each power configuration using Matteo’s tool and shows the recommended memory based on the selected strategy including average cost & duration.

调谐器将使用Matteo的工具生成每个电源配置的平均成本和速度的可视化,并根据所选策略(包括平均成本和持续时间)显示建议的内存。

Image for post

Developers can now tweak their lambda memory profiles not on a whim but using this data and knowledge to get the most out of their resources by improving performance or reducing cost of executions.

开发人员现在可以调整不会对他们的拉姆达内存配置文件的心血来潮,但是使用这一数据和知识,通过提高性能或减少死刑的成本获得了大部分的资源。

They can also bring back the results of a previous execution if the execution data is still available (based on AWS Step Function retention period) to prevent the need to run the tuner again (unnecessary cost) to show team members, demo to stakeholders and more:

如果执行数据仍然可用(基于AWS Step Function保留期),他们还可以带回上一次执行的结果,以防止需要再次运行调谐器(不必要的费用)来向团队成员展示,向利益相关者进行演示等:

Image for post

为什么首先要对Lambda函数进行功率调整? (Why power tune your Lambda functions in the first place?)

Whenever you create a lambda within AWS, the memory is defaulted to 128mb (lowest). Whilst this is a great start for simple tasks and keeps your Total Cost of Ownership (TCO) down, sometimes developers need, want & should update this value based on the type of task it is performing. By simply tweaking this value, your performance of your lambda can be drastically improved with little to no effect to the cost (even cheaper at times).

每当在AWS中创建lambda时,内存默认为128mb (最低)。 尽管这是完成简单任务的一个不错的开始,并且可以降低总体拥有成本(TCO),但有时开发人员需要,希望并应根据正在执行的任务类型来更新此值。 通过简单地调整此值,可以显着提高lambda的性能,而对成本几乎没有影响(有时甚至更便宜)。

And the best thing … developers are in control of the memory!

最好的事情是……开发人员可以控制内存!

Image for post

Below is a sample tuning result allowing 84% performance gain with little to no cost impact:

下面是一个示例调整结果,可在不影响成本的情况下实现84%的性能提升:

Image for post

… and to achieve this massive improvement, all I had to do was to add/update one line of code:

…为了实现这一巨大的改进,我要做的就是添加/更新一行代码:

Image for post
Lambda definition defaults to 128mb memory size
Lambda定义默认为128mb内存大小
Image for post
Simply update the memory size to the recommended size: 1024mb
只需将内存大小更新为建议大小:1024mb

Explaining to developers, your business or stakeholders those sort of gains with such little development effort … ludicrous.

向开发人员,您的企业或利益相关者解释这种无需付出太多开发工作就能获得的收益……可笑

为什么我建议使用这个项目? (Why would I recommend using this project?)

This project has one simple goal: lowering the barrier of entry to Lambda Power Tuning.

该项目有一个简单的目标:降低进入Lambda Power Tuning的门槛。

By deploying an easy to use website which is used to interact with the tuner, you can create a consistent user experience over tuning, promote usage as it requires less setup (once deployed in your account, any dev could use it), promote consistency across the org with less implementation paths and so on…

通过部署一个易于使用的网站来与调谐器进行交互,您可以在调优方面创建一致的用户体验,在需要较少设置的情况下提高使用率(一旦部署到您的帐户中,任何开发人员都可以使用它),在实现路径较少的组织,依此类推...

Image for post

I hope you can see the benefits of having this activity made easier which is often seen as an “extra” activity and often hear in an organisation …

我希望您能看到使此活动变得更容易的好处,这通常被视为“额外”活动,并且经常在组织中听到……

I am too busy to worry about tuning

我太忙了,不用担心调音

I will get to that during innovation time

我将在创新期间解决这个问题

The default memory will be fine … AWS defaulted it for a reason

默认内存会很好... AWS将其默认是有原因的

By lowering the barrier I hope every team using Lambda functions will utilise power tuning to help optimise their solutions using an easy to use and data driven consistent approach.

通过降低障碍,我希望每个使用Lambda函数的团队都将利用功率调整功能,以易用且数据驱动的一致方法帮助优化其解决方案。

如何在组织中部署它? (How do I deploy this in my organisation?)

This solution can be deployed to your organistion in only a few commands with the main ones being:

该解决方案仅需几个命令即可部署到您的组织,主要命令

  • npm run deploy-infra

    npm运行deploy-infra

This command will deploy a CDK infrastructure stack containing the resources needed to run the power tuner e.g. API Gateway, power tuner State machine & set up direct integrations via simply endpoints

该命令将部署一个CDK基础结构堆栈,其中包含运行电源调谐器所需的资源,例如API网关,电源调谐器状态机并通过简单的端点设置直接集成

  • npm run build

    npm运行构建

This command will build the angular website to allow the static files to be deployed to S3 for hosting pointing to the newly deployed API Gateway URL (needs updated in web prod environment props)

此命令将构建有角度的网站,以允许将静态文件部署到S3进行托管,以指向新部署的API网关URL(需要在Web产品环境props中更新)

  • npm run deploy-website

    npm运行deploy-website

This command will deploy a CDK infrastructure stack containing the resources to front a single page application using AWS CloudFront and S3 using anSPA Deploy package

此命令将部署包含资源的CDK基础架构堆栈,以使用SPA Deploy软件包使用AWS CloudFront和S3将单个页面应用程序置于前端

More in-depth instructions can be found on my GitHub here.

更深入的说明,可以在GitHub上我发现在这里

想要贡献? (Want to contribute?)

If you would like to contribute to this project and have ideas how we can improve this experience for all developers, please get in contact via Twitter or submit a Pull Request.

如果您想为这个项目做出贡献,并且对如何改善所有开发人员的经验有想法,请通过Twitter与我们联系或提交请求请求。

翻译自: https://medium.com/@matthewdorrian/save-money-and-improve-performance-with-the-lambda-power-tuner-ui-bad594176008

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值