AWS Compute Blog
Retaining Optimize CPUs configuration during Amazon EC2 scaling to save on licensing costs
Introduction
Amazon Elastic Compute Cloud (Amazon EC2) now lets you modify CPU configurations after an instance has launched. With this new feature, users can change instance CPU settings either by directly modifying the CPU configuration, or when changing instance size or type. You can now specify a custom number of CPUs and/or disable simultaneous multithreading (SMT) also known as hyper-threading (HT), for workloads where HT doesn’t provide performance improvement. These capabilities help Bring Your Own license (BYOL) users to optimize their CPU-based licensing costs. For more details on supported instance types, core count, and threads per core values available for each instance type, refer to the supported CPU options for Amazon EC2 instance type documentation.
Why CPU configuration matters for different workloads?
One of our users recently faced a significant challenge when their SQL Server licensing costs unexpectedly increased after scaling their EC2 instances to the next size up. This increase occurred because the Optimized CPUs feature, which can be configured to enable a custom number of CPUs to disable HT so that they can save on SQL Server BYOL licensing costs, was reset during scaling. As a result, this user quadrupled (as opposed to doubled) their licensing requirements when scaling from r7i.xlarge to r7i.2xlarge. Initially, we recommended creating a new Amazon Machine Image (AMI) and launching a new instance with the desired CPU configurations. But this approach introduced complications such as creating new AMIs, moving Amazon Elastic Block Store (Amazon EBS) volumes, and managing security groups. The user wanted a solution that would allow them to scale their workloads seamlessly without these complexities. After working backward from this and other user requirements, we are excited to bring the capability to retain the Optimized CPU configuration during scaling. This reassures you that your licensing costs are as you would expect (for example increase or decrease linearly with your instance size).
An Optimized CPU can reduce your per-CPU licensing costs by 50% by disabling HT, as long as doing so doesn’t affect application performance. You can save more by selectively disabling additional cores based on your specific workloads. Example workloads include, but are not limited to the following:
- Compute-intensive workloads (for example scientific computing, simulations), which often perform better with one thread per core rather than two threads per core.
- Database workloads (for example SQL Server) where reducing the thread count to one per core typically does not impact performance, because these workloads need more memory and storage but are less dependent on a high number of CPUs. For more details, refer to Optimize CPU best practices for SQL Server workloads.
- High-performance computing (HPC) workloads, which sometimes perform better without HT because it can cause performance degradation because of context switching.
Three ways to set or modify CPU configurations
First, you can modify the EC2 instance configuration on an instance that is stopped after launch by modifying CPU Options:
- Go to the EC2 Dashboard: Log in to your AWS Management Console and go to the EC2 dashboard.
- Choose the Instance: Choose the EC2 instance that you want to modify from the list.
- Stop the Instance: In the Instance State dropdown, choose Stop Instance.
- Change CPU Options: In the Actions dropdown, choose Instance Settings, and choose Change CPU Options. You should observe the box shown in Figure 1.
- Configure CPU Settings:
a. Adjust the number of CPU cores (for example the dropdown box to the left of core(s))
b. Set the number of threads per core to 1 so that you disable HT (for example the dropdown box to the left of thread(s) per CPU core)
- Apply the Changes: When your desired CPU configuration is set, choose Apply to save the settings.
Figure 1: Changing CPU options after instance launch
Second, you can also modify the CPU configuration during an instance size or type change:
- Select the Instance: From the EC2 dashboard, choose the instance to modify.
- Stop the Instance: In the Instance State dropdown, choose Stop Instance.
- Change Instance Type: In Actions, choose Instance Settings, then choose Change Instance Type. You should observe the box shown in Figure 2.
- Configure CPU Options: While changing the instance type, you can also:
a. Adjust the number of CPU cores (for example the dropdown box to the left of core(s))
b. Set the number of threads per core to 1 so that you disable HT (for example the dropdown box to the left of thread(s) per CPU core)
- Apply Changes: When configured, apply the changes.
Figure 2: Specifying CPU options during instance size or type change
Finally, you can use the CLI, API, or SDK method to configure the core count and threads per core for your instance using the new command modify-instance-cpu-options
:
aws ec2 modify-instance-cpu-options --core-count "2" --threads-per-core "1" --instance-id "i-<your-instance-id>"
License tracking with optimized CPUs in AWS License Manager
You can effectively track your license usage by enabling the vCPU Optimization feature for self-managed license configuration within AWS License Manager. This feature integrates with Amazon EC2 CPU optimization, which lets you track the number of vCPUs on an instance. When the vCPU Optimization rule is set to True, License Manager counts vCPUs based on your customized core and thread count. Otherwise, it counts the default number of vCPUs for the instance type, which may not reflect your optimized CPU settings.
Conclusion
The ability to modify CPU configurations after an EC2 instance launch offers flexibility and efficiency for managing your workloads. You can adjust CPU cores, threads per core, and change instance types or sizes while retaining custom CPU settings without creating a new instance. This feature helps optimize performance, reduce licensing costs, and streamline operations.
Start using this new functionality today to improve the efficiency and scalability of your EC2 instances!
To learn more about CPU options on Amazon EC2, check out this guide, and Optimize CPU best practices for SQL Server workloads.
Author Bio
Rafet Ducic
Rafet Ducic is a Senior Solutions Architect at Amazon Web Services (AWS). He applies his more than 20 years of technical experience to help Global Industrial and Automotive users transition their workloads to the cloud cost-efficiently and with optimal performance. With domain expertise in Database Technologies and Microsoft licensing, Rafet is adept at guiding companies of all sizes toward reduced operational costs and top performance standards.