当前位置:网站首页>Quickly build an e-commerce platform based on Amazon cloud technology serverless service - performance
Quickly build an e-commerce platform based on Amazon cloud technology serverless service - performance
2022-07-30 18:00:00 【Amazon Cloud Developer】
概览
上一篇我们介绍了WordPresse-commerce pluginWooCommerceAnd how to quickly build a serverless service in the Amazon cloudAmazon Lambda的方案,In this article, we will introduce the advantages of this scheme,and load test.
使用ServerlessThe advantages of building a stand-alone station
in traditional architecture mode,If you need to carry out e-commerce promotion, you need to pre-set computing resources in advance to support high concurrent access,It will cause waste of computing resources and increase the workload of operation and maintenance.
This article introduces a new way of deployment,将WordPress和WooCommerce部署在https://www.apple.com/careers/cn/work-at-apple.html中.LambdaIt's serverless computing,Code can be run without provisioning resources,Automatically respond to code execution requests of any size,From a dozen events per day to hundreds of thousands of events per second,Pay for computing time(以毫秒为单位),真正做到按使用量计费,In this way, the provisioning resources and operation and maintenance costs can be saved.
Amazon Lambda的这种特性,让Lambda越来越受欢迎,越来越多的客户选择Lambda来部署应用,其中也包含web应用.了解Lambdacustomers may know,LambdaIt is based on an event-triggered method,对于web应用,需要使用API Gateway,接收HTTP请求,把HTTP请求转化为Lambda事件触发Lambda运行.
在以前,对于已有的Web应用,A lightweight modification of the application code is required to handle thisLambda事件.For many use likeWordPress和WooCommerceFor e-commerce customers of such mature components,Code modifications are unlikely,Is it not possible to use itLambdaadvantage?答案是否定的.利用Lambda的新功能Lambda container imagesand open source componentsAmazon Lambda adapter可以让WordPress在Lambdarun without any code modification.
This solution passes willLambda Adapter,WordPress,WooCommerceAnd other necessary plugins are packaged into containers,部署到Lambda.At the same time this solution also utilizesLambda的新功能,Function URL,来代替API Gateway,可以直接通过Function URL来通过HTTP(s)访问Lambda,从而节省API Gateway带来的成本.Dynamic requests from users,通过CloudFront回源到Lambda URL触发Lambda运行,在Lambda内部,Lambda Adapter接收到Lambda事件并将其转换成WordPress能处理的HTTP请求.This makes it possible to use it without modifying the codeLambda中运行WordPress.
本文着重介绍Lambda container image和Lambda Function URL,关于Lambda AdapterFor the implementation details, please refer to this blog.
Lambda container image
To run the container onLamabda,The container image needs to contain the runtimeAPI的runtime interface clients,用于管理 Lambda and function code.Customers can make their ownruntime interface clientIncluded in your own image to support the Lambda运行.亚马逊云科技 Provides a set of open source that can be used to create container images基础映像.These base images include runtime interface clients .Lambda映像是只读的,But function code can access has 512 MB The storage space is writable /tmp 目录.本方案使用Docker来创建映像.DockerfileUse the base image provided by Amazon Cloud TechnologyAmazon Linux 2,并使用bedrock来管理WordPress和插件的安装.Some necessary plugins are preconfigured in this scenario,Customer can modifybedrockconfig to add the required plugins.
runtime interface clients:
https://docs.aws.amazon.com/lambda/latest/dg/runtimes-images.html#runtimes-api-client
基础映像:
https://docs.aws.amazon.com/zh_cn/lambda/latest/dg/runtimes-images.html#runtimes-images-lp
runtime interface clients :
https://docs.aws.amazon.com/lambda/latest/dg/runtimes-images.html#runtimes-api-client
Lambda Function URL
现在可以通过创建Function URL,支持使用HTTP(s)来访问这个URL来触发Lambda运行.在Function URLwhen this feature was not released,基于Lambda构建WebApplications need to be combinedAPI Gateway来接收HTTP(s)请求.但是在Lambda上部署WooCommerce的场景下,因为是把WordPressPacked into a container,So only a single one is neededLambda Function,API gatewayThe role is just to putHTTP请求转化为Lambda事件,而API Gateway提供的高级功能,例如API管理,请求验证等,并不需要.因此有了Function URL的功能,can be replacedAPI Gatewayrole in this scenario,并且不会增加Lambda的费用,同时也节省了API Gateway的费用.
负载测试
在上一篇博客的基础上,我们使用WordPress的插件Blocksy快速构建一个Starter Site,并使用这个Site来作为测试对象.
This program has been open sourcedGithub,访问此Repo(https://github.com/aws-samples/serverless-WooCommerce-workshop)Full code available.
在test/k6文件夹内,This program also provides performance testingk6脚本.Simulates the user entering the home page,选择商品,并加入购物车,更新地址,The complete process to submit an order.具体说明参考test/readme.md文件.
main.jsas the entry file for the test,before simulating5分钟100个用户在线,中间10分钟1000个用户在线,后5分钟100A scenario where a user is online.Readers can modify according to test needsmain.js文件.
因为默认CDKTemplate presetRDS Aurora mysql实例和Elasticahe Redis cluster规模过小,Not suitable for testing.这里修改CDK代码cdk/lib/woocommerce-stack.ts,将RDS Aurora mysql 的r5.4xlarge.Elasticahe Redis cluster修改为r5.xlarge.Customers can also change their own scale to conduct larger-scale testing.
Update the resource with the following command.
make diff
make deploy
Here we use onec5.xlarge的Amazon Linux 2 EC2来进行测试.并安装CloudWatch Agent,将k6The generated metrics are uploaded to CloudWatch进行可视化.注意EC2Requires permission to writeCloudWatch Metrics,这里我们使用EC2 Role来赋予权限.
通过创建Role,Select the managed policy in the image belowCloudWatchAgentAdminPolicy,并且把这个Role绑定给EC2.
通过以下命令安装、配置k6和CloudWatch Agent,并运行k6进行测试.
sudo yum -y install https://dl.k6.io/rpm/repo.rpm
sudo yum -y install --nogpgcheck k6
sudo yum -y install git
git clone https://github.com/aws-samples/serverless-woocommerce-workshop.git
cd ~/serverless-woocommerce-workshop/test/k6
sudo yum install -y amazon-cloudwatch-agent
cat << EOF > cw-statsd.json
{
"metrics": {
"namespace": "k6",
"metrics_collected": {
"statsd": {
"service_address": ":8125",
"metrics_collection_interval": 1,
"metrics_aggregation_interval": 0
}
}
}
}
EOF
sudo amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -s -c file:./cw-statsd.json
K6_STATSD_ENABLE_TAGS=true k6 run --out statsd -e HOSTNAME=<your WooCommerce website domain name> main.js
*左滑查看更多
下图是k6Statistical results of the test run.
在CloudWatch的k6 metricsYou can see the sum of orders completed per secondLambda的并发量.可以看出,As with the request/Increase in order volume,Lambdawill automatically expand.可以看出,LambdaAble to cope with peaks and lows in traffic,No running action is required.
附录
Quickly build an e-commerce platform based on Amazon cloud technology serverless service——部署篇
Serverless Standalone Workshop:
https://catalog.workshops.aws/serverless-woocommerce/zh-CN
Github code:
https://github.com/aws-samples/serverless-woocommerce-workshop
总结
This blog post builds on the previous one,介绍了ServerlessThe advantages of the website plan,并对基于Serverless服务的WordPress进行负载测试,能够看出Amazon LambdaIt can automatically deal with traffic peaks and lows without any operation and maintenance operations,大大节省运维成本.Readers can also according to their own needs,修改测试脚本,Do a larger scale performance test.
本篇作者
汪其香
亚马逊云科技解决方案架构师,负责基于亚马逊云科技云计算方案的架构咨询和设计实现,具有丰富的解决客户实际问题的经验,同时热衷于深度学习的研究与应用.
许昌月
亚马逊云科技解决方案架构师,负责基于亚马逊云科技的云计算方案架构咨询和设计,实施和推广,擅长软件开发,具有丰富的解决客户实际问题的经验.
听说,点完下面4个按钮
就不会碰到bug了!
边栏推荐
- Mo Team - Elegant Violence
- 18.支持向量机(SVM)的介绍
- LayaBox---TypeScript---类型兼容性
- 如何让 JOIN 跑得更快?
- 【Cloud Store Announcement】Notice of Help Center Update on July 30
- This year..I sincerely recommend the professional engineer to upgrade to the book!
- Metaverse Web 3.0 和 DeFi大师班
- 数据库系统原理与应用教程(068)—— MySQL 练习题:操作题 90-94(十二):DML 语句练习
- fast shell porting
- 5 个开源的 Rust Web 开发框架,你选择哪个?
猜你喜欢
Mathematical Principles of Graph Convolutional Neural Networks——A Preliminary Study on Spectral Graph Theory and Fourier Transform
基础架构之Redis
「Redis应用与深度实践笔记」,深得行业人的心,这还不来看看?
Promise entry to proficient (1.5w word detailed explanation)
时序数据库在船舶风险管理领域的应用
【HarmonyOS】【FAQ】鸿蒙问题合集4
想要写出好的测试用例,先要学会测试设计
5分钟搞懂MySQL - 行转列
5 个开源的 Rust Web 开发框架,你选择哪个?
2022年杭电多校第2场 1001 Static Query on Tree(树链剖分+哈希表差分
随机推荐
C陷阱与缺陷 第7章 可移植性缺陷 7.3 整数的大小
【HMS core】【FAQ】Account Kit、MDM能力、push Kit典型问题合集6
What is an ultrasonic flaw detector used for?
如何让 JOIN 跑得更快?
What is NDT equipment?
Shell implementation based on stm32
This year..I sincerely recommend the professional engineer to upgrade to the book!
【HarmonyOS】【ARK UI】HarmonyOS ets语言怎么实现双击返回键退出
18.支持向量机(SVM)的介绍
宽带射频放大器OA4SMM4(1)
Dodging ice cream assassins?Crawling ice cream prices through crawlers
C陷阱与缺陷 第7章 可移植性缺陷 7.2 标识符名称的限制
宝塔搭建PHP自适应懒人网址导航源码实测
linux 安装mysql8.0 超详细教程(实战多次)
【HMS core】【FAQ】HMS Toolkit典型问题合集1
C陷阱与缺陷 第6章 预处理器 6.1 不能忽视宏定义中的空格
fast shell porting
[OC学习笔记]属性关键字
开源盛宴ApacheCon Asia 2022即将开幕,精彩不容错过!
MySQL【单行函数】