Memcached 叢集的擴展 - Amazon ElastiCache

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

Memcached 叢集的擴展

ElastiCache for Memcached 提供全受管的記憶體內快取服務,可在 AWS 雲端中部署、操作和垂直擴展 Memcached。

隨需垂直擴展

透過垂直擴展,ElastiCache for Memcached 提供高效能的分散式記憶體快取系統,廣泛用於透過減輕資料庫負載來加速動態應用程式。它將資料和物件存放在 RAM 中,減少從外部資料來源讀取的需求。

您可以使用 ElastiCache for Memcached 自行設計的叢集進行垂直擴展。您可以將垂直擴展套用至現有叢集以及新的叢集。這可以提供資源配置的彈性,讓使用者有效率地適應不斷變化的工作負載,而無需變更叢集架構。此擴展功能透過在高需求期間增加快取容量,以及縮減規模以在低需求期間最佳化成本來改善效能。這可簡化操作、消除建立新叢集以轉移資源需求的需求,並快速回應流量波動。整體而言,Memcached 自行設計快取的垂直擴展有助於提高成本效益、提高資源使用率,甚至允許使用者變更其 Memcached 執行個體類型。所有功能都讓使用者更輕鬆地將快取基礎設施與實際的應用程式需求保持一致。

注意
  • 自行設計的快取和節點類型修改僅適用於 Memcached 引擎 1.5 版或更新版本。

  • 必須啟用自動探索,才能使用垂直擴展。

設定 ElastiCache Memcached 叢集的隨需垂直擴展

您可以使用 為 Memcached 設定隨需垂直擴展scale-config,其中包含兩個參數:

  1. ScaleIntervalMinutes:Memcached 升級程序期間擴展批次之間的時間 (分鐘)

  2. ScalePercentage:在 Memcached 升級程序期間同時擴展的節點百分比

將現有的 Memcached 節點類型轉換為可透過 CLI 垂直擴展的快取

若要將現有的 Memcached 自行設計快取轉換為可垂直擴展的快取,您可以透過 elasticache modify-cache-cluster CLI 使用 。

aws elasticache modify-cache-cluster \ --cache-cluster-id <your-cluster-id> \ --cache-node-type <new-node-type> \ --scale-config <scale-config> \ --apply-immediately

使用 CLI 設定垂直擴展

若要透過 CLI 設定 Memcached 自行設計快取的垂直擴展,請使用 elasticache modify-cache-cluster搭配 scale-config及其參數 ScalePercentageScaleIntervalMinutes

  • scale-interval-minutes:這會定義擴展批次之間的時間 (分鐘)。此設定的範圍為 2-30 分鐘。如果未指定任何值,則會套用預設值 5 分鐘。

  • scale-percentage:這會指定在每個批次中同時擴展的節點百分比。此設定的範圍可以是 10-100。分割時設定會四捨五入,例如,如果結果為 49.5,則會套用 50 的設定。如果未指定值,則會套用預設值 20。

這些組態選項可讓您根據您的特定需求微調擴展程序,在將叢集中斷降至最低和最佳化擴展速度之間取得平衡。scale-config 參數僅適用於 Memcached 引擎類型,且會忽略其他快取引擎,確保與其他叢集現有 API 用量的回溯相容性。

API 呼叫

aws elasticache modify-cache-cluster \ --cache-cluster-id <your-cluster-id> \ --cache-node-type <new-node-type> \ --scale-config '{ "ScalePercentage": 30, "ScaleIntervalMinutes": 2 }' --apply-immediately

結果:

傳回快取叢集 ID 和待定變更。

{ "CacheCluster": { "CacheNodeType": "old_insance_type", ... ... "PendingModifiedValues": { "CacheNodeType": "new_instance_type" }, } }

列出您的 Memcached 快取垂直擴展設定

您可以擷取 Memcached 快取的擴展選項,並查看它們目前的垂直擴展選項。

API 呼叫

aws elasticache list-allowed-node-type-modifications --cache-cluster-id <your-cluster-id>

結果:

{ "ScaleUpModifications": [ "cache.x.xxxx", "cache.x.xxxx" ], "ScaleDownModifications": [ "cache.x.xxxx", "cache.x.xxxx", "cache.x.xxxx" ] }

使用 進行 Memcached 的垂直擴展 AWS Management Console

若要將現有的 Memcached 自行設計快取轉換為可透過 https://console.aws.amazon.com/elasticache/ 垂直擴展的快取,請遵循下列步驟。

  1. 登入 AWS Management Console 並開啟位於 https://https://console.aws.amazon.com/elasticache/ 的 ElastiCache 主控台。

  2. 選取要轉換的 Memcached 快取。

  3. 選取修改索引標籤。

  4. 前往快取設定區段,然後選取所需的節點類型

  5. 選取預覽變更,然後檢閱變更。

  6. 選擇 Modify (修改)

Memcached 的自動化水平擴展

ElastiCache 現在與 AWS Application Auto Scaling (AAS) 服務整合,以包含 Memcached 叢集的自動水平擴展。您可以透過 AWS Application Auto Scaling 服務定義擴展政策,並根據預先定義的指標或排程,視需要自動調整 Memcached 叢集中的節點數量。

注意

北京和寧夏區域目前不提供自動水平擴展。

這些是自動水平擴展自行設計快取的可用方法。

  • 排程擴展:根據排程擴展可讓您為可預測的負載變更設定自己的擴展排程。例如,您的 Web 應用程式傳入流量會在每週的星期三開始增加,到星期四維持高峰,然後在星期五開始下降。您可以設定 Auto Scaling 在星期三增加容量,並在星期五減少容量。

  • 目標追蹤:使用目標追蹤擴展政策,您可以選擇擴展指標並設定目標值。Application Auto Scaling 會建立和管理可觸發擴展政策的 CloudWatch 警示,並根據指標和目標值來計算擴展調整。擴展政策會視需要新增或移除容量,讓指標保持在等於或接近指定目標值。

如何透過 CLI 設定 ElastiCache for Memcached 自行設計快取的水平擴展

若要使用 ElastiCache Memcached 水平擴展,您可以擁有目標追蹤政策、排程政策或兩者。

  1. 將資源註冊為可擴展的目標

    在 AWS Application Auto Scaling 中呼叫 RegisterScalableTarget API,以註冊可擴展維度 的目標elasticache:cache-cluster:Nodes

    API:ApplicationAutoScaling.RegisterScalableTarget

    輸入:

    { "ScalableDimension": "elasticache:cache-cluster:Nodes", "ResourceId": "cache-cluster/test-cluster-1", "ServiceNamespace": "elasticache", "MinCapacity": 20, "MaxCapacity": 50 }
  2. 建立目標追蹤擴展政策

    接下來,您可以透過呼叫 put 擴展政策 API 來建立資源的目標追蹤擴展政策。

  3. 預先定義的指標

    以下是使用預先定義的指標 沿著快取節點維度擴展的政策 ElastiCacheCPUUtilization,將快取叢集 test-cluster-1 設為 50。刪除縮減的節點時,將會移除最後 n 個節點。

    API:ApplicationAutoScaling.PutScalingPolicy

    輸入:

    { "PolicyName": "cpu50-target-tracking-scaling-policy", "PolicyType": "TargetTrackingScaling", "TargetTrackingScalingPolicyConfiguration": { "TargetValue": 50, "PredefinedMetricSpecification": { "PredefinedMetricType": "ElastiCacheCPUUtilization" }, "ScaleOutCooldown": 600, "ScaleInCooldown": 600 }, "ServiceNamespace": "elasticache", "ScalableDimension": "elasticache:cache-cluster:Nodes", "ResourceId": "cache-cluster/test-cluster-1" }

    輸出:

    { "PolicyARN": "arn:aws:autoscaling:us-west-2:012345678910:scalingPolicy:6d8972f3-efc8-437c-92d1-6270f29a66e7:resource/elasticache/cache-cluster/test-cluster-1:policyName/cpu50-target-tracking-scaling-policy", "Alarms": [ { "AlarmARN": "arn:aws:cloudwatch:us-west-2:012345678910:alarm:TargetTracking-elasticache/cache-cluster/test-cluster-1-AlarmHigh-d4f0770c-b46e-434a-a60f-3b36d653feca", "AlarmName": "TargetTracking-elasticache/cache-cluster/test-cluster-1-AlarmHigh-d4f0770c-b46e-434a-a60f-3b36d653feca" }, { "AlarmARN": "arn:aws:cloudwatch:us-west-2:012345678910:alarm:TargetTracking-elasticache/cache-cluster/test-cluster-1-AlarmLow-1b437334-d19b-4a63-a812-6c67aaf2910d", "AlarmName": "TargetTracking-elasticache/cache-cluster/test-cluster-1-AlarmLow-1b437334-d19b-4a63-a812-6c67aaf2910d" } ] }
  4. 自訂指標

    您也可以使用以 Cloudwatch 指標為基礎的自訂百分比,在維度上設定擴展政策。

    輸入:

    { "PolicyName": "cpu50-target-tracking-scaling-policy", "PolicyType": "TargetTrackingScaling", "TargetTrackingScalingPolicyConfiguration": { "CustomizedMetricSpecification": { "Dimensions": [ { "Name": "MyMetricDimension", "Value": "DimensionValue" } ], "MetricName": "MyCustomMetric", "Namespace": "MyNamespace", "Statistic": "Average", "Unit": "Percent" }, "TargetValue": 40, "ScaleOutCooldown": 600, "ScaleInCooldown": 600 }, "ServiceNamespace": "elasticache", "ScalableDimension": "elasticache:cache-cluster:Nodes", "ResourceId": "cache-cluster/test-cluster-1" }
  5. 排定的動作

    當您需要向外擴展特定事件,然後在事件之後向內擴展時,您可以透過呼叫 PutScheduledAction API 來建立兩個排程動作。

    政策 1:向外擴展

    中的 at命令會將動作--schedule排程在未來指定的日期和時間執行一次。排程欄位也支援速率 (分鐘、小時、日等) 和 Cron (Cron 表達式)。

    在指定的日期和時間,Application Auto Scaling 會更新 MinCapacityMaxCapacity 值。Application Auto Scaling 向外擴展至 MinCapacity,將快取節點設為 70。

    API:ApplicationAutoScaling.PutScheduledAction

    輸入:

    { "ResourceId": "elasticache:ache-cluster:test-cluster-1", "ScalableDimension": "elasticache:cache-cluster:Nodes", "ScalableTargetAction": { "MaxCapacity": 100, "MinCapacity": 70 }, "Schedule": "at(2020-05-20T17:05:00)", "ScheduledActionName": "ScalingOutScheduledAction", "ServiceNamespace": "elasticache", }

    政策 2:縮減

    在指定的日期和時間,Application Auto Scaling 會更新資料表的 MinCapacityMaxCapacity,並縮減為 MaxCapacity 以將快取節點傳回至 60。

    API:ApplicationAutoScaling.PutScheduledAction

    輸入:

    { "ResourceId": "elasticache:cache-cluster:test-cluster-1", "ScalableDimension": "elasticache:cache-cluster:Nodes", "ScalableTargetAction": { "MaxCapacity": 60, "MinCapacity": 40 }, "Schedule": "at(2020-05-21T17:05:00)", "ScheduledActionName": "ScalingInScheduledAction", "ServiceNamespace": "elasticache", }
  6. 檢視擴展活動

    您可以使用 DescribeScalingActivities API 檢視擴展活動。

    API:ApplicationAutoScaling.DescribeScalingActivities

    輸出:

    { "ScalingActivities": [ { "ScalableDimension": "elasticache:elasticache:DesiredCount", "Description": "Setting desired count to 30.", "ResourceId": "elasticache/cache-cluster/test-cluster-1", "ActivityId": "4d759079-a31f-4d0c-8468-504c56e2eecf", "StartTime": 1462574194.658, "elasticacheNamespace": "elasticache", "EndTime": 1462574276.686, "Cause": "monitor alarm TargetTracking-elasticache/cache-cluster/test-cluster-1-AlarmHigh-d4f0770c-b46e-434a-a60f-3b36d653feca in state ALARM triggered policy cpu50-target-tracking-scaling-policy", "StatusMessage": "Failed to set desired count to 30", "StatusCode": "Failed" }, { "ScalableDimension": "elasticache:elasticache:DesiredCount", "Description": "Setting desired count to 25.", "ResourceId": "elasticache/cache-cluster/test-cluster-1", "ActivityId": "90aff0eb-dd6a-443c-889b-b809e78061c1", "StartTime": 1462574254.223, "elasticacheNamespace": "elasticache", "EndTime": 1462574333.492, "Cause": "monitor alarm TargetTracking-elasticache/cache-cluster/test-cluster-1-AlarmHigh-d4f0770c-b46e-434a-a60f-3b36d653feca in state ALARM triggered policy cpu50-target-tracking-scaling-policy", "StatusMessage": "Successfully set desired count to 25. Change successfully fulfilled by elasticache.", "StatusCode": "Successful" } ] }
  7. 編輯/刪除擴展政策

    您可以再次呼叫 PutScalingPolicy API,或呼叫 DeleteScalingPolicyDeleteScheduled 動作來編輯或刪除政策。

  8. 取消註冊可擴展性目標

    您可以透過 DeregisterScalableTarget API 取消註冊可擴展的目標。取消註冊可擴展的目標會刪除擴展政策和與其相關聯的排程動作。

    API:ApplicationAutoScaling.DeregisterScalableTarget

    輸入:

    { "ResourceId": "elasticache/cache-cluster/test-cluster-1", "ServiceNamespace": "elasticache", "ScalableDimension": "elasticache:cache-cluster:Nodes" }
  9. 擴展政策清除

  10. 多個擴展政策

    您可以建立多個擴展政策。以下是自動擴展目標追蹤中行為的關鍵標註。

    • 任一個可擴展性目標均能有多個目標追蹤擴展政策,但前提是各政策使用不同的指標。

    • Application Auto Scaling 的用意一律以可用性為優先,因此其行為視目標追蹤政策是準備水平擴展或縮減而有所不同。如果任何目標追蹤政策已準備好擴展,此服務就會擴展可擴展目標,但只有在所有目標追蹤政策 (已啟用縮減部分) 已準備好縮減,才會進行縮減。

    • 如果多個政策同一時間指示可擴展的目標水平擴展或縮減,Application Auto Scaling 會根據縮減和水平擴展都可達最大容量的政策來擴展。如此能夠更靈活地涵蓋多種情況,確保始終有足夠的容量可處理您的應用程式工作負載。

    注意

    AWS Application Auto Scaling 不會將擴展政策排入佇列。Application Auto Scaling 會等待第一個擴展完成,然後冷卻,然後重複上述演算法。

透過 自動水平擴展 Memcached 快取 AWS Management Console

若要將現有的 Memcached 自行設計快取轉換為可透過 https://console.aws.amazon.com/elasticache/ 水平擴展的快取,請遵循下列步驟。

  1. 登入 AWS Management Console ,並在 https://https://console.aws.amazon.com/elasticache/ 開啟 ElastiCache 主控台。

  2. 選取要轉換的 Memcached 快取。

  3. 前往 Autoscaling 索引標籤。

  4. 透過選取新增動態擴展新增排程擴展,選取要套用的擴展政策。

  5. 視需要填寫所選政策的詳細資訊。

  6. 按一下 Create (建立)