Skip to content
advanced Phase 98 · Cloud

Cloud Scaling and Performance

Cloud scaling including auto-scaling, resource management, performance optimization, and monitoring in Adobe Commerce Cloud

45m
0 problems
Topic Progress 0%

Auto-Scaling Configuration

Cloud Scaling Architecture

Internet
  |
  +-- CDN (Fastly)
  |
  +-- Load Balancer
  |
  +-- Web Nodes (Auto-scaled)
  |     +-- Node 1
  |     +-- Node 2
  |     +-- Node N (scales based on traffic)
  |
  +-- Services (Managed)
        +-- MySQL (read replicas)
        +-- Redis (cluster)
        +-- Elasticsearch

Scaling Rules

# .magento.service.yaml (conceptual)
web:
    type: php:8.1
    size: S
    scaling:
        min: 2
        max: 8
        metrics:
            cpu: 70%
            memory: 80%
            requests_per_second: 1000

Horizontal Scaling

# Check current nodes
magento-cloud environment:info

# Scale web nodes
magento-cloud environment:info --property web_nodes

# Monitor node count
watch -n 5 'magento-cloud environment:info --property web_nodes'

Vertical Scaling

# Upgrade service plan
magento-cloud service:plan:update mysql --size L

# Check current plan
magento-cloud service:plan:list

# Upgrade web node size
magento-cloud environment:info --property web_size

Key Takeaway

Cloud auto-scales web nodes based on traffic. Monitor node count and resource usage. Upgrade service plans for vertical scaling.

Resource Management

Redis Resource Management

# .magento/services.yaml
redis:
    type: redis:6.0
    configuration:
        maxmemory: 2147483648  # 2GB
        maxmemory_policy: allkeys-lru

MySQL Resource Management

mysql:
    type: mysql:10.6
    disk: 4096  # 4GB disk
    configuration:
        max_connections: 200
        innodb_buffer_pool_size: 1073741824  # 1GB

Elasticsearch Resource Management

elasticsearch:
    type: elasticsearch:7.17
    disk: 2048  # 2GB disk
    configuration:
        heap_size: 512m
        cluster_name: magento

Shared Storage Management

# Check storage usage
magento-cloud mount:list

# Resize shared storage
magento-cloud mount:resize pub/media --size 10240

# Check disk usage
magento-cloud ssh
df -h /mnt/pub/media

Resource Monitoring

# Monitor resource usage
magento-cloud environments:info

# Check service status
magento-cloud service:list

# View resource limits
magento-cloud service:plan:list

Key Takeaway

Manage Redis memory, MySQL connections, Elasticsearch heap, and shared storage. Monitor resource usage and upgrade plans as needed.

Performance Optimization

CDN Optimization

# Fastly configuration
fastly:
    enabled: true
    ttl: 60
    stale_ttl: 86400

Varnish Optimization

# Enable Varnish
magento-cloud variable:create \
    --name env:HTTP_CACHE_HOSTS \
    --value 'varnish:6081'

# Check Varnish status
magento-cloud ssh
varnishstat -f MAIN.cache_hit

Redis Optimization

# Check Redis stats
magento-cloud ssh
redis-cli info stats

# Optimize Redis memory
redis-cli config set maxmemory 2147483648
redis-cli config set maxmemory-policy allkeys-lru

PHP-FPM Optimization

; /etc/php/8.1/fpm/pool.d/www.conf
pm = dynamic
pm.max_children = 50
pm.start_servers = 10
pm.min_spare_servers = 5
pm.max_spare_servers = 20
pm.max_requests = 500

; OPcache
opcache.enable=1
opcache.memory_consumption=256
opcache.max_accelerated_files=20000

Database Optimization

-- Enable query cache
SET GLOBAL query_cache_type = 1;
SET GLOBAL query_cache_size = 67108864;  -- 64MB

-- Optimize tables
OPTIMIZE TABLE catalog_product_entity;
OPTIMIZE TABLE sales_order;

Key Takeaway

Optimize with CDN, Varnish, Redis, PHP-FPM, and database tuning. Monitor cache hit ratios and query performance.

Monitoring and Alerting

Cloud Monitoring

# Monitor environment
magento-cloud environments:info

# Check service status
magento-cloud service:list

# View resource usage
magento-cloud ssh
top -bn1 | head -20

Custom Metrics

<?php
// Track scaling metrics
class ScalingMetrics
{
    private $prometheus;
    
    public function recordWebNodes(int $count): void
    {
        $this->prometheus->gauge(
            'magento_cloud_web_nodes',
            'Number of web nodes',
            $count
        );
    }
    
    public function recordRequestRate(float $rps): void
    {
        $this->prometheus->gauge(
            'magento_cloud_requests_per_second',
            'Requests per second',
            $rps
        );
    }
}

Alert Configuration

# Prometheus alerts
groups:
  - name: scaling-alerts
    rules:
      - alert: HighCPU
        expr: cpu_usage_percent > 80
        for: 5m
        labels:
          severity: warning
        annotations:
          summary: "High CPU usage detected"
      
      - alert: HighMemory
        expr: memory_usage_percent > 85
        for: 5m
        labels:
          severity: warning
        annotations:
          summary: "High memory usage detected"
      
      - alert: ScalingRequired
        expr: requests_per_second > 1000
        for: 10m
        labels:
          severity: info
        annotations:
          summary: "Consider scaling up"

Cost Optimization

# Monitor costs
magento-cloud environments:info --property size

# Downscale during low traffic
magento-cloud environment:info --property web_nodes

# Use appropriate service plans
magento-cloud service:plan:list

# Clean up unused environments
magento-cloud environment:deactivate <branch>

Key Takeaway

Monitor CPU, memory, request rates, and costs. Set up alerts for high usage. Downscale during low traffic to optimize costs.

Quiz

1. What triggers auto-scaling in cloud?

Question 1 options

2. What is horizontal scaling?

Question 2 options

3. What is vertical scaling?

Question 3 options

4. Why monitor Redis memory?

Question 4 options

5. How to optimize costs?

Question 5 options

Flashcards

Question

What triggers auto-scaling?

Answer

CPU, memory thresholds or request rate limits

Question

Horizontal vs vertical scaling?

Answer

Horizontal: add nodes. Vertical: upgrade node size.

Question

How to monitor cloud resources?

Answer

magento-cloud environments:info, service:list

Question

Why optimize Redis memory?

Answer

Prevent data eviction and maintain cache hit ratio

Question

How to reduce cloud costs?

Answer

Downscale during low traffic, use appropriate service plans

Question

What is CDN optimization?

Answer

Fastly caching for static content delivery

Revision Notes

Key Takeaways

  • 1. Auto-scaling triggers on CPU, memory, or request rate
  • 2. Horizontal scaling adds nodes, vertical upgrades node size
  • 3. Monitor Redis, MySQL, Elasticsearch resources
  • 4. Optimize with CDN, Varnish, Redis, PHP-FPM
  • 5. Downscale during low traffic to reduce costs

Interview Tips

  • Explain auto-scaling triggers and configuration
  • Compare horizontal vs vertical scaling
  • Discuss resource management strategies
  • Explain cost optimization approaches

Cheat Sheet

Cloud Scaling

Auto-Scaling:
Triggers: CPU, memory, request rate
Min/Max nodes configured

Scaling Types:
Horizontal: Add nodes
Vertical: Upgrade node size

Resources:
Redis: maxmemory, maxmemory_policy
MySQL: connections, buffer pool
Elasticsearch: heap_size

Optimization:
CDN: Fastly
Varnish: HTTP cache
Redis: cache layer
PHP-FPM: worker tuning

Monitoring:
magento-cloud environments:info
magento-cloud service:list