AWSSagemakerPySparkProcessor能够管理自动扩缩容吗?
创始人
2024-09-27 01:30:57
0

AWS Sagemaker PySparkProcessor 可以通过指定实例计数和实例类型来控制处理集群的大小。但是,它目前没有默认的自动扩缩容功能。但是,可以使用AWS Autoscaling 来进行自动扩缩容操作。

以下是一个使用 AWS Sagemaker PySparkProcessor 和 AWS Autoscaling 的示例代码:

import boto3
import sagemaker
from sagemaker import get_execution_role
from sagemaker.spark.processing import PySparkProcessor
from sagemaker.autoscaling import CronJobScheduler

# 获取角色
role = get_execution_role()

# 获取Sagemaker session 和 s3 bucket
sagemaker_session = sagemaker.Session()
bucket = sagemaker_session.default_bucket()

# 创建 S3 input 和 output路径
input_prefix = 'input'
input_uri = f's3://{bucket}/{input_prefix}/'

output_prefix = 'output'
output_uri = f's3://{bucket}/{output_prefix}/'

# 将 PySpark 脚本上传到s3
code_path = 'scripts'
code_uri = f's3://{bucket}/code/'

sagemaker_session.upload_data(path=code_path, bucket=bucket, key_prefix='code')
code_uri = sagemaker_session.upload_data(path=code_path, bucket=bucket, key_prefix='code')

# 配置自动扩缩容
autoscaling = boto3.client('autoscaling')
desired_size = 1
autoscaling_params = {'AutoScalingGroupName': 'processing-group',
                      'ScheduledActionName': 'scale-out',
                      'DesiredCapacity': desired_size}

# 每分钟进行自动扩容一次
scheduler = CronJobScheduler(
    scheduled_action_name='scale-out',
    target_min_capacity=1,
    target_max_capacity=4,
    role_arn=role,
    scheduled_expression='* * * * ? *'
)

with scheduler:
    # 创建 PySparkProcessor
    processor = PySparkProcessor(base_job_name='processing-jobs', 
                                 framework_version='2.4', 
                                 role=role,
                                 instance_count=1,
                                 instance_type='ml.m5.xlarge',
                                 max_runtime_in_seconds=1200) # 20 minutes
    
    # 开始处理任务
    processor.run(spark_event_logs_uri=input_uri,
                  logs=True,
                  arguments=['--output', output_uri, '--job-id', '6690', '--model-version', 'v1'])

此代码创建了一个名为 processing-group 的 Auto Scaling Group 对象,并使用 ScheduledAction 扩展这个组的实

相关内容

热门资讯

透视智能!hhpoker辅助(... 透视智能!hhpoker辅助(透视)开挂辅助技巧(一直真的有挂)-哔哩哔哩1、让任何用户在无需hhp...
透视有挂!如何下载德普之星辅助... 透视有挂!如何下载德普之星辅助软件,wejoker开挂,绝活教程(都是真的有挂)-哔哩哔哩运如何下载...
透视输赢!wejoker黑侠辅... 透视输赢!wejoker黑侠辅助器(透视)开挂辅助神器(一贯有挂)-哔哩哔哩wejoker黑侠辅助器...
透视能赢!约局吧能不能开挂,w... 透视能赢!约局吧能不能开挂,wepokerplus透视脚本免费,指南书教程(原来真的有挂)-哔哩哔哩...
透视开发!模拟器打开hhpok... 透视开发!模拟器打开hhpoker(透视)开挂辅助软件(原来是真的挂)-哔哩哔哩1、玩家可以在模拟器...
透视总结!wepoker祈福有... 透视总结!wepoker祈福有用吗,xpoker辅助助手,项目教程(一直真的是有挂)-哔哩哔哩1、每...
透视打法!聚星ai辅助工具收费... 透视打法!聚星ai辅助工具收费多少(透视)开挂辅助工具(本来有挂)-哔哩哔哩1、聚星ai辅助工具收费...
透视好友!佛手在线大菠萝为什么... 透视好友!佛手在线大菠萝为什么都输,德州hhpoker脚本,学习教程(真是有挂)-哔哩哔哩1、每一步...
透视辅助!德州透视是真的吗,p... 透视辅助!德州透视是真的吗,pokemmo手机版脚本,阶段教程(果然存在有挂)-哔哩哔哩透视辅助!德...
透视辅助器!aapoker辅助... 透视辅助器!aapoker辅助器是真的吗(透视)开挂辅助app(都是真的是有挂)-哔哩哔哩1、玩家可...