Good programmers don’t just write well. They optimize code so that their software runs as quickly as possible, while consuming the fewest system resources necessary to complete a given task. If you want to be a good programmer who writes optimized software, however, the cloud may be throwing you for a loop. That’s because the migration of many workloads to the cloud has changed the calculus regarding what matters most when it comes to optimization.
Traditional Software Optimization
Before the advent of the cloud--and software for the cloud--software optimization was a relatively simple affair. The goal of optimization was to allow a given program to do more with fewer resources so that the software ran quickly and did not require end users to purchase expensive hardware to support it. The resources that mattered most in this context were typically CPU time, memory and persistent storage space, all of which were usually limited in the workstations or servers on which the software ran.
Thus, in order to optimize a program, developers would try to reduce the number of calls the program had to make to perform a given task, reduce the data it stored in memory, and shorten or compress program data to save disk space.
How Software for the Cloud Changes Optimization
In the cloud, however, these three types of resources--CPU, memory and storage--matter less than they do in local environments. Optimizing the way software consumes them is less critical for delivering a high-performing application that will please end users. This is true for two main reasons.
- Unlimited resources: In the cloud, your programs can usually consume as many CPU, memory or storage resources as they need without impacting other workloads or the end user experience. If your software has memory leaks that lead to inefficient use of RAM, you can always allocate more memory to it. If it stores data inefficiently, there’s always more storage space available. This makes the cloud different from local environments, where an unoptimized application might simply exhaust all of the system’s resources and stop working.
- Cheap resources: CPU, memory and storage are relatively cheap in the cloud, especially if they are consumed in high volumes only temporarily. An application that has to be hosted on a more expensive EC2 instance because it has not been optimized might end up costing only $10 or $20 more per month than one that can run on a cheaper instance thanks to optimization. And in a world where cloud storage costs pennies per gigabyte, the cost between efficient and inefficient file structures or formats is often negligible.
Optimization Matters--Just Not as Much
Lest I be accused of encouraging you to write bloated applications, or implying that you can consume infinite resources in the cloud at no cost, let me make clear that optimization of CPU, memory and storage usage for cloud-based workloads is certainly beneficial. It will reduce your cloud computing bill, especially if you make massive use of cloud resources.
Optimization can also help to guarantee a better end user experience. Although more resources can always be allocated to cloud workloads, it’s not always possible to guarantee that they can be added without disruption. A workload that runs properly with the resources originally allocated to it will always be preferable performance-wise to one that needs to be scaled to maintain the same level of performance due to a lack of optimization.
New Optimization Challenges for the Cloud
Also worth noting is the fact that, in the cloud, other types of resources tend to matter more than they did in local environments.
Network bandwidth is the most obvious example. For the most part, bandwidth is not something that you can instantly scale up when an application needs more of it. In fact, in most cases it’s hard even to know or control how much bandwidth will be available to deliver to a cloud-based app because you have no way of guaranteeing that the end users who connect to your cloud app will have a certain level of bandwidth available to them.
Plus, although bandwidth at high-end data centers is growing, there is still only so much bandwidth to go around for all of the apps hosted in a given data center. You can’t simply migrate part of your workload to another data center to get more bandwidth.
For these reasons, optimizing the way a cloud app consumes bandwidth is critical. You want to make sure that data exchanged over the network is as small as it can be, and that potential bottlenecks that could slow network performance (like an API call that requires unnecessary back-and-forth between two endpoints) are mitigated.
Another software optimization consideration for the cloud centers on how your cloud-based apps consume resources, rather than how much they consume. By this, I mean that it’s important to think about which types or tiers of cloud services your application uses.
For example, an application that doesn’t require the performance level of “hot” cloud storage services and uses “cool” storage tiers instead might perform just as well, but cost less money to run than one that uses hot storage unnecessarily--regardless of whether the application code itself is designed to optimize storage usage. Similarly, making use of reserved virtual server instances can cut your cloud computing bill significantly without impacting performance or requiring you to spend time optimizing code.
To a large extent, this type of optimization--figuring out which cloud services to use or how to configure them--is the job of IT operations teams who deploy apps, not developers who write them. But programmers can help by being aware of the different types of cloud services available and their impact on application performance and efficiency.
The cloud computing revolution and software for the cloud has changed the nature of optimization. Gone are the days when making the most efficient use of CPUs, memory and local storage was the primary task of developers who wanted to optimize code. Today, optimization requires more attention to the way applications use the network, as well as how cloud apps are configured and deployed.