DaaS / Products / Deploy Production Stack and Optimize Full-Stack Performance

Deploy Production Stack and Optimize Full-Stack Performance

A DevOps team provisions a complete production web application stack using Terraform (VPC, ECS cluster, RDS, OSS, SLB with SSL), then when the deployed application experiences performance degradation, they diagnose system-level and database bottlenecks end-to-end and apply targeted database optimization using RDS diagnostic tools.

Products involved

Scenario

Use this workflow when provisioning a production web stack via Terraform and subsequently troubleshooting end-to-end latency. It bridges infrastructure-as-code deployment with real-time system diagnostics on Alibaba Cloud Linux and targeted query optimization in ApsaraDB RDS to resolve performance degradation under load.

Integration steps

  1. Provision Stack: Run terraform apply. Ensure resource "alicloud_slb_listener" sets ssl_certificate_id = alicloud_cas_certificate.cert.id and backend_protocol = "https".
  2. Enable Diagnostics: Run aliyun rds ModifyDBInstanceAttribute --DBInstanceId <id> --SlowLogRetention 30. On ALinux ECS, install tools: yum install -y sysstat perf.
  3. Capture Host Metrics: During latency spikes, run top -p $(pgrep -d, -f app) and iostat -x 1 5 on ECS. Use sar -n DEV 1 10 to isolate network bottlenecks.
  4. Correlate DB Load: Cross-reference ECS iowait with RDS via aliyun rds DescribeDBInstancePerformance --DBInstanceId <id> --Key GroupValue:CPUUsage,GroupValue:IOPSUsage.
  5. Diagnose Queries: Fetch slow logs: aliyun rds DescribeSlowLogRecords --DBInstanceId <id> --StartTime <ts> --EndTime <ts>. Filter AvgExecutionTime > 1000ms.
  6. Apply Optimizations: Run EXPLAIN on flagged SQL. Create indexes via CREATE INDEX idx_status ON orders(status);. Use RDS SQL Advisor to rewrite inefficient joins.
  7. Tune Network Stack: If latency persists, apply sysctl -w net.core.somaxconn=65535 net.ipv4.tcp_tw_reuse=1. Persist in /etc/sysctl.conf and run sysctl -p.
  8. Validate: Run wrk -t4 -c100 -d30s https://<slb-ip>. Monitor DescribeDBInstancePerformance and ALinux pidstat to confirm reduced latency.

Architecture

Traffic enters SLB, where CAS-issued SSL terminates HTTPS. Requests route to ALinux ECS instances serving app logic, with static assets offloaded to OSS. Database queries traverse the VPC to RDS. During optimization, ALinux tools (perf, iostat) isolate host bottlenecks, while RDS APIs (DescribeSlowLogRecords) pinpoint query inefficiencies. Terraform maintains declarative state across all components.

Prerequisites

Common pitfalls

Typical questions

FAQ

Q: How do I deploy a production stack and optimize its performance? A: You deploy and optimize the stack by provisioning a complete production web application with Terraform and applying targeted database optimization using RDS diagnostic tools after diagnosing end-to-end bottlenecks. The process involves setting up infrastructure components such as VPC, ECS clusters, RDS, OSS, and SLB with SSL, then troubleshooting system-level and database slowdowns to resolve performance degradation.