My Sagemaker Asynchronous Endpoint goes down to zero instances after 10 minutes

I’m creating an Asynchronous Endpoint because for a model that takes up to 40 minutes to process the input. I want to configure it so it can scale-in to zero instances, and once it recieves an input, then scale-out from zero instances. I’ve been testing and looking for some policies, but I can’t solve my problem. Everytime I launch the endpoint and I ask for processing an input, it starts as it is supposed to do, but, after 10 minutes, the instances is shutted down, and then another one is raised but just waiting for an input.

I’ve used some policies to control the CPU usage, the number of invocations, etc., but I’m always getting the same problem. When I was testing the use of the CPU, I got some weird behavior, the instances stopped after 5-10 minutes of processing the input, and then, after an hour, another instace appeared with all the job done, as if I have done another invocation to the endpoint (but I didn’t).

I want the endpoint to scale-in, i.e., shutting down instances when is not processing any instance for X minutes (that’s why I tried to check de %CPU that was being used), and to scale-out from zero, i.e., raise a new instance if an invocation to the endpoint is done and there is no instance already up.

Here is some code for the policies that I’ve been using.

Scale-In policies:

response = asg_client.register_scalable_target(
        ServiceNamespace="sagemaker",
        ResourceId=resource_id,
        ScalableDimension="sagemaker:variant:DesiredInstanceCount",
        MinCapacity=0,
        MaxCapacity=5,
    )
response_scale_in = asg_client.put_scaling_policy(
        PolicyName = f'scaleinpolicy-{endpoint_name}',
        ServiceNamespace="sagemaker",  # The namespace of the service that provides the resource.
        ResourceId=resource_id,  # Endpoint name
        ScalableDimension="sagemaker:variant:DesiredInstanceCount",  # SageMaker supports only Instance Count
        PolicyType="StepScaling",  # 'StepScaling' or 'TargetTrackingScaling'
        StepScalingPolicyConfiguration={
            "AdjustmentType": "ChangeInCapacity", # Specifies whether the ScalingAdjustment value in the StepAdjustment property is an absolute number or a percentage of the current capacity. 
            "MetricAggregationType": "Average", # The aggregation type for the CloudWatch metrics.
            "Cooldown": 2400, # The amount of time, in seconds, to wait for a previous scaling activity to take effect. 
            "StepAdjustments": # A set of adjustments that enable you to scale based on the size of the alarm breach.
            [ 
                {
                "MetricIntervalUpperBound": 0,
                "ScalingAdjustment": -1
                }
            ]
        },    
    )

CPU Utilization:

response = asg_client.put_scaling_policy(
        PolicyName=policy_name,
        ServiceNamespace='sagemaker',
        ResourceId=resource_id,
        ScalableDimension='sagemaker:variant:DesiredInstanceCount',
        PolicyType='TargetTrackingScaling',
        TargetTrackingScalingPolicyConfiguration={
            'TargetValue': 50.0,
            'CustomizedMetricSpecification':
            {
                'MetricName': 'CPUUtilization',
                'Namespace': '/aws/sagemaker/Endpoints',
                'Dimensions': [
                    {'Name': 'EndpointName', 'Value': endpoint_name},
                    {'Name': 'VariantName', 'Value': "AllTraffic"}
                ],
                'Statistic': 'Average',
                # 'Statistic': 'Maximum',
                'Unit': 'Percent'
            },
            'ScaleOutCooldown': scale_out_cool_down,
            'ScaleInCooldown': scale_in_cool_down,
            'DisableScaleIn': False
        }
    )

Scale out (from zero):

    response = asg_client.put_scaling_policy(
        PolicyName = f'HasBacklogWithoutCapacity-ScalingPolicy-{endpoint_name}',
        ServiceNamespace="sagemaker",  # The namespace of the service that provides the resource.
        ResourceId=resource_id,  # Endpoint name
        ScalableDimension="sagemaker:variant:DesiredInstanceCount",  # SageMaker supports only Instance Count
        PolicyType="StepScaling",  # 'StepScaling' or 'TargetTrackingScaling'
        StepScalingPolicyConfiguration={
            "AdjustmentType": "ChangeInCapacity", # Specifies whether the ScalingAdjustment value in the StepAdjustment property is an absolute number or a percentage of the current capacity. 
            "MetricAggregationType": "Average", # The aggregation type for the CloudWatch metrics.
            "Cooldown": 300, # The amount of time, in seconds, to wait for a previous scaling activity to take effect. 
            "StepAdjustments": # A set of adjustments that enable you to scale based on the size of the alarm breach.
            [ 
                {
                "MetricIntervalLowerBound": 0.0,
                "ScalingAdjustment": 1
                }
            ]
        },    
    )

I’m invoking the endpoint as follows:

    response = sm_client.invoke_endpoint_async(
        EndpointName=endpoint_name,
        ContentType="application/octet-stream", # File to be processed
        InputLocation="s3://path_to_s3_file", 
        Accept="application/xml",
        InvocationTimeoutSeconds=3600,
        CustomAttributes='some_atribs',
        InferenceId='gened_id'
    )

I’m not using GPU, so I didn’t test any GPU instance. In addition, the docker image is custom, one of the official Python docker images repository.

Thank you very much in advance!!

I’ve being seraching in the rePost, but any configuration is working for me, and I don’t understand what is happening with the alarms or the policies.

I have tried to change more things, like the AI comment said that was to using the ‘Maximum’ for the CPU instead of the ‘Average’, and setting it to 800% of CPU use, and what I get is the following: First, it creates an instance, 10 minutes later it shutdown the instance and raise a new one. If I make another invocation, the new instance get the invocation, process it, and then process the other petition which processing was “killed” with the first instance. If I try to make more invocations, the instances get shutdown after 10 mins. I don’t get any error file in the s3 path for error logs, but when the input is processed as it is supposed to do, it is correct. I don’t know whats happening or if this can help. I have uploaded an image that can help to understand better what I’m trying to explain.

%CPU Use

I’d like to add that I’ve been using multiples instances in order to check if it could be the problem, I keep getting the same behaviour with the following instances:

  • ml.m5.xlarge, ml.m5.2xlarge
  • ml.r5.xlarge, ml.r5.2xlarge
  • ml.c6g.xlarge: As it uses ARM processors, I cant use it.
  • ml.c4.2xlarge: Got memory error.

New contributor

Alberto Argente is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật