Wednesday, July 22, 2026
HomeBig DataGreatest practices to optimize information entry efficiency from Amazon EMR and AWS...

Greatest practices to optimize information entry efficiency from Amazon EMR and AWS Glue to Amazon S3

[ad_1]

Clients are more and more constructing information lakes to retailer information at large scale within the cloud. It’s widespread to make use of distributed computing engines, cloud-native databases, and information warehouses once you need to course of and analyze your information in information lakes. Amazon EMR and AWS Glue are two key companies you need to use for such use circumstances. Amazon EMR is a managed large information framework that helps a number of totally different functions, together with Apache Spark, Apache Hive, Presto, Trino, and Apache HBase. AWS Glue Spark jobs run on prime of Apache Spark, and distribute information processing workloads in parallel to carry out extract, remodel, and cargo (ETL) jobs to complement, denormalize, masks, and tokenize information on an enormous scale.

For information lake storage, prospects usually use Amazon Easy Storage Service (Amazon S3) as a result of it’s safe, scalable, sturdy, and extremely obtainable. Amazon S3 is designed for 11 9’s of sturdiness and shops over 200 trillion objects for thousands and thousands of functions around the globe, making it the perfect storage vacation spot in your information lake. Amazon S3 averages over 100 million operations per second, so your functions can simply obtain excessive request charges when utilizing Amazon S3 as your information lake.

This submit describes finest practices to attain the efficiency scaling you want when analyzing information in Amazon S3 utilizing Amazon EMR and AWS Glue. We particularly give attention to optimizing for Apache Spark on Amazon EMR and AWS Glue Spark jobs.

Optimizing Amazon S3 efficiency for giant Amazon EMR and AWS Glue jobs

Amazon S3 is a really massive distributed system, and you’ll scale to 1000’s of transactions per second in request efficiency when your functions learn and write information to Amazon S3. Amazon S3 efficiency isn’t outlined per bucket, however per prefix in a bucket. Your functions can obtain not less than 3,500 PUT/COPY/POST/DELETE or 5,500 GET/HEAD requests per second per prefix in a bucket. Moreover, there are not any limits to the variety of prefixes in a bucket, so you possibly can horizontally scale your learn or write efficiency utilizing parallelization. For instance, if you happen to create 10 prefixes in an S3 bucket to parallelize reads, you can scale your learn efficiency to 55,000 learn requests per second. You possibly can equally scale writes by writing information throughout a number of prefixes.

You possibly can scale efficiency by using computerized scaling in Amazon S3 and scan thousands and thousands of objects for queries run over petabytes of information. Amazon S3 routinely scales in response to sustained new request charges, dynamically optimizing efficiency. Whereas Amazon S3 is internally optimizing for a brand new request charge, you obtain HTTP 503 request responses briefly till the optimization completes:

AmazonS3Exception: Please cut back your request charge. (Service: Amazon S3; Standing Code: 503; Error Code: SlowDown)

Such conditions require the applying to retry momentarily, however after Amazon S3 internally optimizes efficiency for the brand new request charge, all requests are typically served with out retries. One such state of affairs is when a number of staff in distributed compute engines akin to Amazon EMR and AWS Glue momentarily generate a excessive variety of requests to entry information beneath the identical prefix.

When utilizing Amazon EMR and AWS Glue to course of information in Amazon S3, you possibly can make use of sure finest practices to handle request site visitors and keep away from HTTP Sluggish Down errors. Let’s have a look at a few of these methods.

Greatest practices to handle HTTP Sluggish Down responses

You should utilize the next approaches to reap the benefits of the horizontal scaling functionality in Amazon S3 and enhance the success charge of your requests when accessing Amazon S3 information utilizing Amazon EMR and AWS Glue:

  • Modify the retry technique for Amazon S3 requests
  • Modify the variety of Amazon S3 objects processed
  • Modify the variety of concurrent Amazon S3 requests

We suggest selecting and making use of the choices that match finest in your use case to optimize information processing on Amazon S3. Within the following sections, we describe finest practices of every method.

Modify the retry technique for Amazon S3 requests

That is the best option to keep away from HTTP 503 Sluggish Down responses and enhance the success charge of your requests. To entry Amazon S3 information, each Amazon EMR and AWS Glue use the EMR File System (EMRFS), which retries Amazon S3 requests with jitters when it receives 503 Sluggish Down responses. To enhance the success charge of your Amazon S3 requests, you possibly can regulate your retry technique by configuring sure properties. In Amazon EMR, you possibly can configure parameters in your emrfs-site configuration. In AWS Glue, you possibly can configure the parameters in job parameters. You possibly can regulate your retry technique within the following methods:

  • Enhance the EMRFS default retry restrict – By default, EMRFS makes use of an exponential backoff technique to retry requests to Amazon S3. The default EMRFS retry restrict is 15. Nonetheless, you possibly can enhance this restrict once you create a brand new cluster, on a operating cluster, or at software runtime. To extend the retry restrict, you possibly can change the worth of the fs.s3.maxRetries parameter. Be aware that you could be expertise longer job period if you happen to set the next worth for this parameter. We suggest experimenting with totally different values, akin to 20 as a place to begin, verify the period overhead of the roles for every worth, after which regulate this parameter primarily based in your requirement.
  • For Amazon EMR, use the AIMD retry technique – With Amazon EMR variations 6.4.0 and later, EMRFS helps another retry technique primarily based on an additive-increase/multiplicative-decrease (AIMD) mannequin. This technique will be helpful in shaping the request charge from massive clusters. As an alternative of treating every request in isolation, this mode retains monitor of the speed of latest profitable and throttled requests. Requests are restricted to a charge decided from the speed of latest profitable requests. This decreases the variety of throttled requests, and due to this fact the variety of makes an attempt wanted per request. To allow the AIMD retry technique, you possibly can set the fs.s3.aimd.enabled property to true. You possibly can additional refine the AIMD retry technique utilizing the superior AIMD retry settings.

Modify the variety of Amazon S3 objects processed

One other method is to regulate the variety of Amazon S3 objects processed so you’ve fewer requests made concurrently. While you decrease the variety of objects to be processed in a job, you employ fewer Amazon S3 requests, thereby decreasing the request charge or transactions per second (TPS) required for every job. Be aware the next issues:

  • Preprocess the info by aggregating a number of smaller information into fewer, bigger chunks – For instance, use s3-dist-cp or an AWS Glue compaction blueprint to merge numerous small information (typically lower than 64 MB) right into a smaller variety of optimally sized information (akin to 128–512 MB). This method reduces the variety of requests required, whereas concurrently enhancing the mixture throughput to learn and course of information in Amazon S3. You could must experiment to reach on the optimum dimension in your workload, as a result of creating extraordinarily massive information can cut back the parallelism of the job.
  • Use partition pruning to scan information beneath particular partitions – In Apache Hive and Hive Metastore-compatible functions akin to Apache Spark or Presto, one desk can have a number of partition folders. Partition pruning is a method to scan solely the required information in a selected partition folder of a desk. It’s helpful once you need to learn a selected portion from all the desk. To reap the benefits of predicate pushdown, you need to use partition columns within the WHERE clause in Spark SQL or the filter expression in a DataFrame. In AWS Glue, it’s also possible to use a partition pushdown predicate when creating DynamicFrames.
  • For AWS Glue, allow job bookmarks – You should utilize AWS Glue job bookmarks to course of repeatedly ingested information repeatedly. It solely picks unprocessed information from the earlier job run, thereby lowering the variety of objects learn or retrieved from Amazon S3.
  • For AWS Glue, allow bounded executions – AWS Glue bounded execution is a method to solely decide unprocessed information, with an higher certain on the dataset dimension or the variety of information to be processed. That is one other option to cut back the variety of requests made to Amazon S3.

Modify the variety of concurrent Amazon S3 requests

To regulate the variety of Amazon S3 requests to have fewer concurrent reads per prefix, you possibly can configure Spark parameters. By default, Spark populates 10,000 duties to checklist prefixes when creating Spark DataFrames. You could expertise Sluggish Down responses, particularly once you learn from a desk with extremely nested prefix constructions. On this case, it’s a good suggestion to configure Spark to restrict the variety of most itemizing parallelism by lowering the parameter spark.sql.sources.parallelPartitionDiscovery.parallelism (the default is 10000).

To have fewer concurrent write requests per prefix, you need to use the next strategies:

  • Scale back the variety of Spark RDD partitions earlier than writes – You are able to do this through the use of df.repartition(n) or df.coalesce(n) in DataFrames. For Spark SQL, it’s also possible to use question hints like REPARTITION or COALESCE. You possibly can see the variety of duties (=RDD partitions) on the Spark UI.
  • For AWS Glue, group the enter information – If the datasets are made up of small information, we suggest grouping the enter information as a result of it reduces the variety of RDD partitions, and reduces the variety of Amazon S3 requests to jot down the information.
  • Use the EMRFS S3-optimized committer – The EMRFS S3-optimized committer is utilized by default in Amazon EMR 5.19.0 and later, and AWS Glue 3.0. In AWS Glue 2.0, you possibly can configure it within the job parameter --enable-s3-parquet-optimized-committer. The committer makes use of Amazon S3 multipart uploads as a substitute of renaming information, and it often reduces the variety of HEAD/LIST requests considerably.

The next are different strategies to regulate the Amazon S3 request charge in Amazon EMR and AWS Glue. These choices have the web impact of lowering parallelism of the Spark job, thereby lowering the chance of Amazon S3 Sluggish Down responses, though it may result in longer job period. We suggest testing and adjusting these values in your use case.

  • Scale back the variety of concurrent jobs – Begin with probably the most learn/write heavy jobs. In case you configured cross-account entry for Amazon S3, remember the fact that different accounts may additionally be submitting jobs to the prefix.
  • Scale back the variety of concurrent Spark duties – You will have a number of choices:
    • For Amazon EMR, set the variety of Spark executors (for instance, the spark-submit choice --num-executors and Spark parameter spark.executor.occasion).
    • For AWS Glue, set the variety of staff within the NumberOfWorkers parameter.
    • For AWS Glue, change the WorkerType parameter to a smaller one (for instance, G.2X to G.1X).
    • Configure Spark parameters:
      • Lower the variety of spark.default.parallelism.
      • Lower the variety of spark.sql.shuffle.partitions.
      • Enhance the variety of spark.job.cpus (the default is 1) to allocate extra CPU cores per Spark job.

Conclusion

On this submit, we described one of the best practices to optimize information entry from Amazon EMR and AWS Glue to Amazon S3. With these finest practices, you possibly can simply run Amazon EMR and AWS Glue jobs by benefiting from Amazon S3 horizontal scaling, and course of information in a extremely distributed method at an enormous scale.

For additional steering, please attain out to AWS Premium Help.

Appendix A: Configure CloudWatch request metrics

To watch Amazon S3 requests, you possibly can allow request metrics in Amazon CloudWatch for the bucket. Then, outline a filter for the prefix. For an inventory of helpful metrics to watch, see Monitoring metrics with Amazon CloudWatch. After you allow metrics, use the info within the metrics to find out which of the aforementioned choices is finest in your use case.

Appendix B: Configure Spark parameters

To configure Spark parameters in Amazon EMR, there are a number of choices:

  • spark-submit command – You possibly can move Spark parameters by way of the --conf choice.
  • Job script – You possibly can set Spark parameters within the SparkConf object within the job script codes.
  • Amazon EMR configurations – You possibly can configure Spark parameters by way of API utilizing Amazon EMR configurations. For extra info, see Configure Spark.

To configure Spark parameters in AWS Glue, you possibly can configure AWS Glue job parameters utilizing key --conf with worth like spark.hadoop.fs.s3.maxRetries=50.

To set a number of configs, configure your job parameters utilizing key --conf with worth like spark.hadoop.fs.s3.maxRetries=50 --conf spark.job.cpus=2.


In regards to the Authors

Noritaka Sekiyama is a Principal Large Knowledge Architect on the AWS Glue staff. He’s captivated with releasing AWS Glue connector customized blueprints and different software program artifacts to assist prospects construct their information lakes. In his spare time, he enjoys watching hermit crabs together with his kids.

Aditya Kalyanakrishnan is a Senior Product Supervisor on the Amazon S3 staff at AWS. He enjoys studying from prospects about how they use Amazon S3 and serving to them scale efficiency. Adi’s primarily based in Seattle, and in his spare time enjoys mountaineering and infrequently brewing beer.

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments