Running Alluxio on EMR

Slack Docker Pulls GitHub edit source

This guide describes how to configure Alluxio to run on AWS EMR.

Overview

AWS EMR provides great options for running clusters on-demand to handle compute workloads. It manages the deployment of various Hadoop Services and allows for hooks into these services for customizations. Alluxio can run on EMR to provide functionality above what EMRFS currently provides. Aside from the added performance benefits of caching, Alluxio also enables users to run compute workloads against on-premise storage or even a different cloud provider’s storage i.e. GCS, Azure Blob Store.

Prerequisites

  • Account with AWS
  • IAM Account with the default EMR Roles
  • Key Pair for EC2
  • An S3 Bucket
  • AWS CLI: Make sure that the AWS CLI is set up and ready with the required AWS Access/Secret key

The majority of the pre-requisites can be found by going through the AWS EMR Getting Started guide. An S3 bucket is needed as Alluxio’s Root Under File System and to serve as the location for the bootstrap script. If required, the root UFS can be reconfigured to be HDFS.

Basic Setup

To begin with, download an Alluxio release and unzip it.

  1. Set up the required IAM roles for the account to be able to use the EMR service.

    1. aws emr create-default-roles
  2. The Alluxio bootstrap script is hosted in a publicly readable S3 bucket. This bucket can also be accessed using it’s S3 URI: s3://alluxio-public/emr/2.0.1/alluxio-emr.sh The bootstrap script only requires a root UFS URI as an argument. Additional options can be seen in the comments at the top of the bootstrap script.

    1. $ aws emr create-cluster \
    2. --release-label emr-5.25.0 \
    3. --instance-count <num-instances> \
    4. --instance-type <instance-type> \
    5. --applications Name=Presto Name=Hive Name=Spark \
    6. --name '<cluster-name>' \
    7. --bootstrap-actions \
    8. Path=s3://alluxio-public/emr/2.0.1/alluxio-emr.sh,\
    9. Args=[s3://test-bucket/path/to/mount/] \
    10. --configurations https://alluxio-public.s3.amazonaws.com/emr/2.0.1/alluxio-emr.json \
    11. --ec2-attributes KeyName=<ec2-keypair-name>
  3. On the EMR Console, you should be able to see the cluster going through the different stages of setup. Once the cluster is in the ‘Waiting’ stage, click on the cluster details to get the ‘Master public DNS’. SSH into this instance using the keypair provided in the previous command. If a security group isn’t specified via CLI, the default EMR security group will not allow inbound SSH. To SSH into the machine, a new rule will need to be added.

  4. Test that Alluxio is running as expected

    1. $ alluxio runTests

Alluxio is installed in /opt/alluxio/ by default. Hive and Presto are already configured to connect to Alluxio. The cluster also uses AWS Glue as the default metastore for both Presto and Hive. This will allow you to maintain table definitions between multiple runs of the Alluxio cluster.

See the below sample command for reference.

  1. $ aws emr create-cluster \
  2. --release-label emr-5.25.0 \
  3. --instance-count 3 \
  4. --instance-type m4.xlarge \
  5. --applications Name=Presto Name=Hive \
  6. --name 'Test Cluster' \
  7. --bootstrap-actions \
  8. Path=s3://alluxio-public/emr/2.0.1/alluxio-emr.sh,\
  9. Args=[s3://test-bucket/path/to/mount/] \
  10. --configurations https://alluxio-public.s3.amazonaws.com/emr/2.0.1/alluxio-emr.json \
  11. --ec2-attributes KeyName=admin-key

Notes: The default Alluxio Worker memory is set to 20GB. If the instance type has less than 20GB of memory, change the value in the alluxio-emr.sh script.

Creating a Table

The simplest step to using EMR with Alluxio is to create a table on Alluxio and query it using Presto/Hive.

  1. SSH into the ‘hadoop’ user in the master node.
  2. Create a directory in Alluxio to be the external location of your table.

    1. /opt/alluxio/bin/alluxio fs mkdir /testTable
  3. Start the hive CLI.

    1. $ hive
  4. Create a new database to see if AWS Glue is working as expected. Check the console to see if the database is created.

    1. CREATE DATABASE glue;
  5. Use the newly created database and define a table.

    1. USE glue;
    2. create external table test1 (userid INT,
    3. age INT,
    4. gender CHAR(1),
    5. occupation STRING,
    6. zipcode STRING)
    7. ROW FORMAT DELIMITED
    8. FIELDS TERMINATED BY '|'
    9. LOCATION 'alluxio:///testTable';
  6. Insert values into the table

    1. USE glue;
    2. INSERT INTO test1 VALUES (1, 24, 'F', 'Developer', '12345');
  7. Read back the values in the table

    1. SELECT * FROM test1;

Run a Spark Job

The Alluxio bootstrap also takes care of setting up EMR for you. Follow the steps in our Alluxio on Spark documentation to get started.

Customization

Tuning of Alluxio properties can be done in a few different locations. Depending on which service needs tuning, EMR offers different ways of modifying the service settings/environment variables.

Alluxio Service

Any server-side configuration changes must be made in the alluxio-emr.sh bootstrap script. In the section for generating the alluxio-site.properties, add a line with the configuration needed to append to the bottom of the file. Options can also be passed as the 3rd argument to the bootstrap script with a ‘;’ delimiter.

Alluxio Client

Generic client-side properties can also be edited via the bootstrap script as mentioned above. This is mostly for the native client (CLI). Property changes for a specific service like Presto/Hive should be done in the respective configuration file i.e. core-site.xml, hive.catalog.