Close

Operating Strategies for Cost Optimization

To identify and optimize operating costs when testing with parallel instances in the cloud, it’s helpful, in the first step, to understand the levers at play.

The Optimal EC2 Instance

Anticipate Instead of Reacting

This is where having a solid test planning and organization comes into play.
With thorough advance planning, instances can be utilized optimally, and unnecessary costs can be avoided.

Alternative Cost Models to On-Demand

Utilization of Long-term Rentals

At many cloud providers, in addition to On-Demand, it’s possible to rent computing resources on a long-term basis. There are several payment models depending on the desired period of commitment.

Hybrid models are also possible: for example, by covering the base load with long-term rentals and using On-Demand for additional instances as needed. The cost savings compared to Spot Instances are of course much lower, but the setup is less complex.

Utilizing Spot Instances

What are Spot Instances?

AWS offers Spot Instances as a solution for unused computing capacity, as data centers are rarely fully utilized. Spot Instances are offered with a discount of 80 percent or more. However, there is a risk that these instances may be terminated in favor of paying customers. Depending on the EC2 type, the probability of this happening is around 20 percent.

How does the use of Spot Instances affect the overall costs?

For a better assessment, let’s compare the costs of Spot Instances with On-Demand Instances using the following assumptions:

Additional Demand Instances

A shutdown risk of approximately 20 percent increases the number of necessary instances for a test run.

Lower Costs

80 percent discount on Spot Instances compared to equivalent On-Demand Instances.

Calculation of Total Costs
Spot vs. On-Demand

The total costs for using Spot Instances TC_Spot can be calculated using the following formula:

Calculation of the
Percentage Increase in Instances Needed

If instances are subject to automatic shutdown, you won’t have test results and you’ll need to restart those instances.

With a shutdown risk of Risk_Shutdown > 0%, when testing with Spot Instances, you always have an additional demand for instances (PAI) compared to testing with On-Demand Instances.

This percentage of additional demand for instances (PAI) describes the ratio of the number of Spot Instances to the number of On-Demand Instances for a complete test run and can be sufficiently approximated with the following formula:

Since the number n (necessary repetitions of failed Spot Instances) depends on the number of instances and the shutdown risk, we approximate the PAI with a mathematical trick. We calculate with an infinite number of repetitions. This allows us to determine the theoretically maximum PAI.

Calculation Example for ADI with Shutdown Risk = 20%
PAI = (20%)^0 + (20%)^1 + (20%)^2 + … + (20%)^n
PAI = 100% + 20% + 4% + 0.8% + … => 125%

More concrete? Now with specific numbers.
With 100 instances, you have to expect 20 instance shutdowns. These 20 instances are restarted. Of the 20 instances, 20 percent are shut down again, so 4 instances. These are restarted again. And so on.
In total, you need 125 instances.

Calculation of the
Percentage Costs for a Spot Instance

The number of necessary instances for a test run will increase. However, the cost of a Spot Instance is lower than that of an On-Demand Instance.

The percentage savings are:

With an assumed discount of 80%, the percentage cost savings is 20%. In other words, operating a Spot Instance costs only one-fifth of the operating cost of an On-Demand Instance.

Conclusion: Total Costs Spot vs. On-Demand

In our example calculation, you only have 1/4 of the costs.

In other words: you save 75% of the costs. Spot Instances are worth it!

The cost savings when testing with Spot Instances also means that the duration of a test run is increased due to interruptions and restarts. How much longer it takes mainly depends on the initial number of instances. This can be calculated again using percentage calculations and exponential growth.

Cost Calculator for Spot Instances

For simplified calculation, we have created a Spot Instances Calculator.

Please note that using Spot Instances comes with specific risks and benefits. It’s important to consider the individual requirements and resources of the application before implementing the strategy.

Duration and Iterations

The duration of using Spot Instances depends on the number of initial instances started. Additional iterations can arise from repeated restarts. The exact timing of instance terminations is uncertain, whether it happens right at the beginning or only towards the end. Continuous monitoring and automated restarting are very beneficial in this scenario.

Combining Spot and On-Demand

This model can be cost-effective even if the exact duration is uncertain. If you don’t need the test results immediately, a recommended strategy is to combine Spot and On-Demand instances.

To do this, you need to know when valid results should be available, for example, Monday at 8:00 AM. With this time in mind, you can calculate backwards to determine when multiple parallel On-Demand instances need to be started to obtain all test results. The time from test start to this latest possible deadline can be used for execution with Spot Instances. Instances that have already run in Spot mode do not need to be counted with On-Demand instances. The setup for planning and monitoring is a bit more complex, but in this hybrid model, you have the necessary security and cost efficiency for your test execution.

Considerations for Using Spot Instances

Payment models may change

It is advisable to keep track of changes in the payment terms.

Shutdown rates may vary

The rate of instance shutdowns can vary depending on the country and time.

Optimizing instance duration

The likelihood of termination increases with the duration of the instance. It is advisable to adjust the cost-benefit optimum accordingly.

Automation requires expertise

Implementing automation requires a deep understanding to avoid costly mistakes.

Controlling the execution

Adjustment of Test Strategy & Methods

New test strategies or adapted methods have the potential to reduce the cost and duration of test execution.

Test model or code?

A Simulink model is to be tested? First in MiL and then in SiL. At first glance, this sounds like a good idea. But why should the model be tested once and then the generated code?

Our recommendation: do without the MiL run and test only the code.

This saves the execution of the model and the costs for licenses and still has meaningful results.

Customized test strategies: Free consulting for your product

There is no such thing as a single, optimal test strategy. It is too strongly linked to the product, the requirements and the goals.

We would be happy to help you develop a suitable strategy in an individual, free strategy discussion.