如何配置AutoScale实现白天Scale OUT、夜间Scale IN以优化服务器成本?
Got it, let’s walk through how to set up this cost-saving auto-scaling plan step by step—this is a super common use case for balancing performance during peak hours and trimming unnecessary compute costs after hours. I’ll cover core steps that work across major cloud providers, with specific examples where helpful.
1. Lock in Your Time Windows First
Start by confirming exactly when your "daytime" and "nighttime" traffic patterns kick in using your website’s analytics tools (like Google Analytics or cloud provider monitoring). For example:
- Daytime: 7 AM to 7 PM local time (aligns with your peak user activity)
- Nighttime: 7 PM to 7 AM local time (lowest traffic period)
Don’t just guess these windows—using real traffic data ensures you’re scaling at the right times.
2. Set Up Scheduled Scaling Rules
Nearly all cloud auto-scaling services let you create scheduled rules that override default min/max instance counts at specific times. Here’s how to configure this for the big three providers:
For AWS Auto Scaling
Head to your Auto Scaling Group (ASG) console, then:
- Go to Scheduled actions
- Create two separate scheduled actions:
- Daytime scale-up:
- Action: Set min capacity to 2, desired capacity to 2
- Recurrence: Daily at 7 AM local time
- Nighttime scale-down:
- Action: Set min capacity to 1, desired capacity to 1
- Recurrence: Daily at 7 PM local time
- Daytime scale-up:
If you prefer infrastructure-as-code, use the AWS CLI:
# Create daytime scheduled action aws autoscaling put-scheduled-update-group-action \ --auto-scaling-group-name your-asg-name \ --scheduled-action-name daytime-scale-up \ --recurrence "0 7 * * *" \ --min-size 2 \ --desired-capacity 2 # Create nighttime scheduled action aws autoscaling put-scheduled-update-group-action \ --auto-scaling-group-name your-asg-name \ --scheduled-action-name nighttime-scale-down \ --recurrence "0 19 * * *" \ --min-size 1 \ --desired-capacity 1
For Azure Autoscale
Navigate to your Virtual Machine Scale Set (VMSS) or App Service plan, then:
- Go to Autoscale
- Create two custom profiles:
- Daytime profile:
- Trigger: Daily recurrence starting at 7 AM
- Scale settings: Min instances = 2, Desired = 2 (keep your existing max if you want to scale beyond 2 during spikes)
- Nighttime profile:
- Trigger: Daily recurrence starting at 7 PM
- Scale settings: Min instances = 1, Max = 1, Desired = 1
- Daytime profile:
For GCP Autoscaler
Go to your Managed Instance Group (MIG), then:
- Navigate to Autoscaling
- Under Scheduled policies, add two schedules:
- Daytime:
- Time window: Daily 7 AM to 7 PM
- Target instance count: 2 (set min to 2 here to enforce the floor)
- Nighttime:
- Time window: Daily 7 PM to 7 AM
- Target instance count: 1
- Daytime:
3. Add a Backup Traffic-Based Policy (Optional)
If your daytime traffic sometimes surges beyond what 2 instances can handle, pair the scheduled rules with a target-tracking scaling policy. For example:
- Target average CPU utilization at 70%
- Set max instances to 4 (adjust based on your traffic spikes)
This way, you’ll still have a safety net to scale up during unexpected daytime traffic, but the scheduled rule ensures you never drop below 2 instances during peak hours. At night, the scheduled lock to 1 instance takes priority, so even if CPU is low, you won’t scale further down.
4. Test the Transitions
Don’t just set it and forget it! Validate the setup:
- Manually trigger the daytime rule to confirm instances scale up to 2 without downtime
- Trigger the nighttime rule to check it scales down to 1 smoothly
- Verify health checks are working (so the cloud provider replaces instances gracefully if needed)
5. Monitor and Tweak Over Time
After launching, keep an eye on:
- Instance utilization during daytime (if CPU is consistently high, you might need to bump the min count to 3)
- Cost savings (you should see a noticeable drop since you’re running one instance half the time)
- Traffic patterns (if your user base shifts, update the scheduled times accordingly)
内容的提问来源于stack exchange,提问作者mohammed shajahan

