【发布时间】:2022-04-02 02:07:23
【问题描述】:
信息:
- 我创建了一个烧瓶应用程序并在我的 Dockerfile 上最后一个命令
CMD gunicorn -b 0.0.0.0:5000 --access-logfile - "app:create_app()" - 我在 ECR 上构建、标记和上传图像
- 我使用这个 docker 镜像创建了一个 ECS Fargate 实例,其配置如下(仅发布问题所需的配置):
ECSTaskDefinition:
Type: AWS::ECS::TaskDefinition
Properties:
Cpu: "256"
Memory: "1024"
RequiresCompatibilities:
- FARGATE
ContainerDefinitions:
- Name: contained_above
.
.
.
ECSService:
Type: AWS::ECS::Service
DependsOn: ListenerRule
Properties:
Cluster: !Sub "${EnvName}-ECScluster"
DesiredCount: 1
LaunchType: FARGATE
DeploymentConfiguration:
MaximumPercent: 200
MinimumHealthyPercent: 50
NetworkConfiguration:
AwsvpcConfiguration:
AssignPublicIp: ENABLED
Subnets:
- Fn::ImportValue: !Sub "${EnvName}-PUBLIC-SUBNET-1"
- Fn::ImportValue: !Sub "${EnvName}-PUBLIC-SUBNET-2"
SecurityGroups:
- Fn::ImportValue: !Sub "${EnvName}-CONTAINER-SECURITY-GROUP"
ServiceName: !Sub "${EnvName}-ECS-SERVICE"
TaskDefinition: !Ref ECSTaskDefinition
LoadBalancers:
- ContainerName: contained_above
ContainerPort: 5000
TargetGroupArn: !Ref TargetGroup
(应用正常运行)
问题
现在我的问题是 gunicorn 命令(我在 dockerfile 中的最后一个命令)上的工作人员应该是多少?
在gunicorn design 上声明使用Generally we recommend (2 x $num_cores) + 1 as the number of workers to start off with.
那么,fargate 上的核心数是多少?像上述过程一样将 gunicorn 与 Fargate 结合起来真的有意义吗?负载均衡器和 gunicorn 工作者之间是否存在“兼容性”? ECS服务的DesiredCount和gunicorn-w工人价值观有什么联系?我是否遗漏或误解了什么?
可能的解决方案(?)
我可以这样称呼它:
CMD gunicorn -b 0.0.0.0:5000 -w $(( 2 * `cat /proc/cpuinfo | grep 'core id' | wc -l` + 1 )) --access-logfile - "app:create_app()"
但我不确定这是否是一个好的解决方案。 有什么见解吗?谢谢
【问题讨论】:
-
你有什么发现吗?
-
虽然这不一定能回答您关于 Gunicorn 的问题,但这里有一个可能会有所帮助的 SO 答案:stackoverflow.com/a/52137239/2602267
标签: flask gunicorn amazon-ecs aws-fargate