Organizations depend on Amazon EMR on EC2 clusters to course of large-scale knowledge workloads utilizing frameworks like Apache Spark, Apache Hive, and Trino. Occasions reminiscent of TV ads or unplanned promotions would possibly result in a rise in demand of compute capability, making efficient capability planning essential to verify your workloads don’t hit capability limits or job failures.
A typical situation is to run each day Spark jobs on Amazon EMR utilizing constant Amazon Elastic Compute Cloud (Amazon EC2) occasion sorts (for instance, a single occasion dimension and household for the cluster). Though this would possibly work nicely to maintain the baseline, spikes can set off auto scaling, which narrows the probabilities of capability availability when making an attempt to cease and relaunch a bigger EMR cluster, as a result of the particular on-demand occasion pool would possibly lack capability to satisfy the demand.
On this publish, we present how you can optimize capability by analyzing EMR workloads and implementing methods tailor-made to your workload patterns. We stroll by means of assessing the historic compute utilization of a workload and use a mixture of methods to cut back the probability of InsufficientCapacityExceptions (ICE) when Amazon EMR launches particular EC2 occasion sorts. We implement versatile occasion fleet methods to cut back dependency on particular occasion sorts and use Amazon EC2 On-Demand Capability Reservation (ODCRs) for predictable, steady-state workloads. Following this strategy might help stop job failures attributable to capability limits whereas optimizing your cluster for value and efficiency.
Resolution overview
Occasion fleets in Amazon EMR provide a versatile and strong approach to handle EC2 situations inside your cluster. This characteristic means that you can specify goal capacities for On-Demand and Spot Situations, choose as much as 5 EC2 occasion sorts per fleet (or 30 when utilizing the AWS Command Line Interface [AWS CLI] and API with an allocation technique), and use a number of subnets throughout totally different Availability Zones. Importantly, occasion fleets assist using ODCRs, enabling you to align your EMR clusters with pre-purchased EC2 capability. You possibly can configure your occasion fleet to choose or require capability reservations, ensuring that your EMR clusters use your reserved capability effectively.
EMR workload patterns usually fall into two classes: steady and variable (spiky). Within the following sections, we discover how you can optimize for every sample utilizing numerous choices out there with occasion fleets, beginning with steady workloads after which addressing variable workloads.
Steady workloads are workloads with a predictable sample of useful resource utilization over time; for instance, a pharmaceutical supplier must course of 21 TB of analysis knowledge, affected person information, and different info each day. The workload is constant and must run reliably day-after-day on long-running persistent clusters. For essential enterprise operations requiring excessive reliability and assured capability, we advocate reserving the baseline capability as a part of your capability planning. We exhibit the next steps:
- Use AWS Price and Utilization Experiences (AWS CUR) to estimate the baseline of present workloads.
- Reserve the baseline capability utilizing ODCR.
- Configure Amazon EMR to make use of the focused ODCR.
Spiky workloads are outlined by unpredictable and sometimes important fluctuations in processing calls for. These surges could be triggered by numerous components (reminiscent of batch processing, real-time knowledge streaming, or seasonal enterprise fluctuations) that set off Amazon EMR to request extra capability to match the demand. We deal with the useful resource allocation by utilizing occasion and Availability Zone flexibility, with the next steps:
- Introduce EC2 occasion flexibility with EMR occasion fleets.
- Obtain resiliency by means of clever subnet choice with EMR occasion fleets.
- Use managed scaling to mechanically handle scaling out and in.
Steady workloads
On this part, we exhibit how you can outline your baseline, configure AWS Id and Entry Administration (IAM) permissions, create an ODCR, and affiliate your reservations to a capability group and configure Amazon EMR to make use of focused ODCRs. You possibly can go for a blended ODCR technique—for instance, one ODCR with a brief interval of length that helps the launch of your EMR cluster, and one other ODCR with an extended interval of length that helps your activity nodes based mostly on the baseline capability reservation.
Estimate the baseline
Ensure that to activate the AWS generated value allocation tag aws:elasticmapreduce:job-flow-id. This permits the sphere resource_tags_aws_elasticmapreduce_job_flow_id within the AWS CUR to be populated with the EMR cluster ID and is utilized by the SQL queries within the resolution. To activate the price allocation tag from the AWS Billing Console, full the next steps:
- On the AWS Billing and Price Administration console, select Price allocation tags within the navigation pane.
- Beneath AWS generated value allocation tags, select the
aws:elasticmapreduce:job-flow-idtag. - Select Activate.
It may possibly take as much as 24 hours for tags to activate. For extra info, see right here.

After the tags are activated, you should utilize AWS CUR and carry out the next question on Amazon Athena to search out the compute sources utilized by the EMR cluster ID vs. the timeline of utilization. For extra particulars, see Querying Price and Utilization Experiences utilizing Amazon Athena. Replace the next question along with your CUR desk title, EMR cluster ID, desired timestamps, and AWS account ID, and run the question on Athena:
For instance, the previous question filters situations utilization per hour for a given account and EMR cluster for the interval of 6 months, to generate the next determine. You possibly can export the leads to CSV format and analyze the info. Now that you’ve a visible illustration of your workloads’ baseline and bursts, you may outline the technique and configuration of your EMR cluster.

Create an ODCR to order the baseline capability
ODCRs could be both open or focused:
- With an open ODCR, new situations and present situations which have matching attributes (reminiscent of working system or occasion sort) will run utilizing the capability reservation attributes first.
- With a focused ODCR, situations should match the attributes of the ODCR specification and the ODCR is particularly focused at launch. This strategy is advisable you probably have a number of concurrent EMR clusters consuming capability from the shared On-Demand pool of EC2 situations. EMR clusters bigger than the focused ODCR amount will fall again to On-Demand Situations which are in the identical Availability Zone.
On this instance, we use a focused ODCR with an EMR occasion fleet within the us-east-1a Availability Zone. The next diagram illustrates the workflow.

Full the next steps:
- Use the create-capacity-reservation AWS CLI command to create the ODCR and make a remark of the
CapacityReservationArnworth within the output:
We get the next output:
You should use Amazon CloudWatch to observe ODCR utilization and set off an alert for unused capability. For extra particulars, see Monitor Capability Reservations utilization with CloudWatch metrics.
- Create a useful resource group named
EMRSparkSteadyStateGroupand make a remark ofGroupArnvalues within the output:
We get the next output:
- Use the next code to affiliate the capability reservation to the useful resource group. You possibly can have a number of capability reservations related to a useful resource group.
- As a greatest follow for efficient administration and cleanup, Create a tag
Function=EMR-Spark-Regular-Statefor the newly created ODCR and the useful resource group.
Implement Amazon EMR with ODCR
Full the next steps to create an EMR cluster tagged with the particular focused ODCR:
- Add required permissions to the EMR service function earlier than utilizing capability reservations. With these permissions, you may lock down the useful resource with the particular Amazon Useful resource Title (ARN) of the group title to be created with the next code:
- Configure the EMR cluster to make use of ODCR with occasion fleets. We use the
CapacityReservationOptionsparameter to configure the EMR cluster, as proven within the following instance:
The next step-by-step breakdown illustrates the Amazon EMR decision-making course of when prioritizing focused capability reservations, from core node provisioning by means of activity node allocation:
- Cluster provisioning initiation:
- The consumer chooses to override the lowest-price allocation technique.
- The consumer specifies focused capability reservations within the launch request.
- Core node provisioning:
- Amazon EMR evaluates all EC2 occasion capability swimming pools with focused capability reservations, and selects the pool with the bottom worth that has adequate capability for all requested core nodes.
- If no pool with focused reservations has adequate capability, Amazon EMR reevaluates all specified EC2 occasion capability swimming pools and selects the lowest-priced pool with adequate capability for core nodes. Accessible open capability reservations are utilized mechanically.
- Availability Zone choice:
- After the core capability is acquired, Amazon EMR locks within the Availability Zone on your cluster.
- Main and activity node provisioning:
- Amazon EMR evaluates EC2 occasion capability swimming pools inside that Availability Zone for major and activity fleets. First, Amazon EMR evaluates all of the swimming pools with focused ODCRs specified within the request, ordered by lowest worth by default.
- From the ordered record, Amazon EMR launches as a lot capability as potential from the unused focused ODCRs of every occasion pool till the request is fulfilled.
- If the unused focused ODCRs don’t fulfill the request but, Amazon EMR continues to launch the remaining capability into On-Demand swimming pools, within the lowest-price order by default.
For extra particulars concerning the allocation technique, discuss with Allocation technique for example fleets or Amazon EMR Help for Focused ODCR.
Spiky workloads
Spiky workloads are outlined by unpredictable and sometimes important fluctuations in processing calls for, triggered by components reminiscent of rare however resource-intensive periodic batch processing jobs. For instance, a geographic info system processes location knowledge from hundreds of thousands of customers in actual time to offer up-to-date site visitors info, calculate routes, and counsel factors of curiosity. Consumer location knowledge is consistently being generated, however the quantity can spike dramatically throughout rush hour or particular occasions, as illustrated within the following determine. This graph exhibits the variety of used sources (Amazon EC2) by hour; it varies from 1 when the cluster scales in, ready for jobs, to spikes of 1,000 nodes.

For those who’re working spiky workloads with restricted flexibility in occasion sort, household, and Availability Zone, you would possibly face ICE errors when the out there capability can’t meet the cluster’s scaling necessities. To deal with this, we discover a set of greatest practices for EMR cluster creation to maximise availability and steadiness price-performance. Though spiky workloads current a novel problem in useful resource administration, configuring EMR occasion fleets gives a strong resolution. By utilizing various occasion sorts, prioritized allocation methods, Availability Zone flexibility, and managed scaling, organizations can create a strong, cost-effective infrastructure able to dealing with unpredictable workload patterns. This configuration gives the next advantages:
- Improved availability – By diversifying occasion sorts and utilizing a number of Availability Zones, the cluster mitigates inadequate capability points
- Price financial savings – Allocation methods scale back prices whereas minimizing interruptions
- Resilience for spiky workloads – Prioritizing occasion generations gives seamless scaling beneath various calls for
- Optimized efficiency – Managed scaling dynamically adjusts sources to satisfy workload calls for effectively
Introduce EC2 occasion flexibility and occasion fleets with a prioritized allocation technique
Amazon EMR helps occasion flexibility with occasion fleet deployment. Occasion fleets provide you with a greater variety of choices and intelligence round occasion provisioning. Now you can present a listing of as much as 30 occasion sorts with corresponding weighted capacities and spot bid costs (together with spot blocks) utilizing the AWS CLI or AWS CloudFormation. Amazon EMR will mechanically provision On-Demand and Spot capability throughout these occasion sorts when creating your cluster. This will make it extra easy and more cost effective to rapidly acquire and keep your required capability on your clusters. In August 2024, Amazon EMR launched the prioritized allocation technique to boost occasion flexibility with occasion fleets. This characteristic means that you can specify precedence ranges on your occasion sorts, enabling Amazon EMR to allocate capability to the highest-priority situations first. This technique helps enhance value financial savings and reduces the time required to launch clusters, even in situations with restricted capability. For extra particulars, see Amazon EMR assist prioritized and capacity-optimized-prioritized allocation methods for EC2 situations. To maximise cost-efficiency and availability for spiky workloads, mix the price-performance benefits of new-generation situations with the broader availability of previous-generation situations. For workloads with strict latency necessities, repair the occasion dimension to keep up constant efficiency. This strategy takes benefit of the strengths of each occasion generations, offering flexibility and reliability lowering the probability of capability constraints. For On-Demand nodes, select the prioritized allocation technique, so the cluster tries to make use of newer-generation situations first. Whereas configuring the occasion fleet, organize situations in a prioritized order reflecting price-performance and availability trade-offs, for instance:
- Main node – m8g.12xlarge > m8g.16xlarge > m7g.12xlarge > m7g.16xlarge
- Core node – r8g.8xlarge > r8g.12xlarge > r7g.8xlarge > r6g.16xlarge > r5.16xlarge
- Activity Node – r8g.8xlarge > r8g.12xlarge > r7g.8xlarge > r6g.16xlarge > r5.16xlarge
For Spot Situations, ensure that the capacity-optimized prioritized allocation technique is chosen to cut back interruptions. See the next CloudFormation template snippet for example:
Select subnets with EMR instance fleets
When creating a cluster, specify multiple EC2 subnets within a virtual private cloud (VPC), each corresponding to a different Availability Zone. Amazon EMR provides multiple subnet (Availability Zone) options by employing subnet filtering at cluster launch, and selects one of the subnets that has adequate available IP addresses to successfully launch all instance fleets. If Amazon EMR can’t find a subnet with sufficient IP addresses to launch the whole cluster, it will prioritize the subnet that can at least launch the core and primary instance fleets.
Use managed scaling
Managed scaling is another powerful feature of Amazon EMR that automatically adjusts the number of instances in your cluster based on workload demands. This makes sure that your cluster scales up during periods of high demand to meet processing requirements and scales down during idle times to save costs. With managed scaling, you can set minimum and maximum scaling limits, giving you control over costs while benefiting from an optimized and efficient cluster performance.
The following workflow illustrates Amazon EMR configured with instance fleets and managed scaling.

The workflow consists of the following steps:
- The user defines the EMR instance configurations and instance types, along with their launch priority.
- The user selects subnets for the Amazon EMR configuration to provide Availability Zone flexibility.
- Amazon EMR calls the Amazon EC2 Fleet API to provision instances based on the allocation strategy.
- The EMR instance fleet is launched.
- The cycle is repeated for scaling operations within the launched Availability Zone, providing optimized performance and scalability.
Conclusion
In this post, we demonstrated how to optimize capacity by analyzing EMR workloads and implementing strategies tailored to your workload patterns. As you implement any of the preceding strategies, remember to continuously monitor your cluster’s performance and adjust configurations based on your specific workload patterns and business needs. With the right approach, the challenges of spiky workloads can be transformed into opportunities for optimized performance and cost savings.
To effectively manage workloads with both baseline demands and unexpected spikes, consider implementing a hybrid approach in Amazon EMR. Use ODCRs for consistent baseline capacity and configure instance fleets with a strategic mix of ODCR, On-Demand, and Spot Instances prioritizing ODCR usage.
Try these strategies with your own use case, and leave your questions in the comments.
About the Authors
Deepmala Agarwal works as an AWS Data Specialist Solutions Architect. She is passionate about helping customers build out scalable, distributed, and data-driven solutions on AWS. When not at work, Deepmala likes spending time with family, walking, listening to music, watching movies, and cooking!
Suba Palanisamy is a Senior Technical Account Manager, helping customers achieve operational excellence on AWS. Suba is passionate about all things data and analytics. She enjoys traveling with her family and playing board games.
Flavio Torres is a Principal Technical Account Manager at AWS. Flavio helps Enterprise Support customers design, deploy, and scale resilient cloud applications. Outside of work, he enjoys hiking and barbecuing.
