Running Alluxio on EMR
This guide describes how to configure Alluxio to run on AWS EMR.
- Basic Setup
- Creating a Table
- Run a Spark Job
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.
- Account with AWS
- IAM Account with the default EMR Roles
- Key Pair for EC2
- An S3 Bucket
- AWS CLI
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.
To begin with, download the
alluxio-emr.json files from
Github. These files will serve as the main
mechanisms to change the Alluxio configuration in the future. Make sure that the AWS CLI is also set up and ready
with the required AWS Access/Secret key.
aws emr create-default-roles. This will set up the required IAM roles for the account to be able to use the EMR service.
- Make sure that the
alluxio-emr.shscript is uploaded to a location in S3 and
alluxio-presto.jsonis saved somewhere on your local filesystem.
- Configure the below command with the required parameters. The root-ufs-uri should be an
hdfs://URI designating the root mount of the Alluxio file system.
aws emr create-cluster --release-label emr-5.23.0 --instance-count <num-instances> --instance-type <instance-type> --applications Name=Presto Name=Hive Name=Spark --name '<cluster-name>' --bootstrap-actions Path=s3://bucket/path/to/alluxio-emr.sh,Args=<web-download-url>,<root-ufs-uri>,<additional-properties> --configurations file:///path/to/file/alluxio-emr.json --ec2-attributes KeyName=<ec2-keypair-name>
- 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.
- Test that Alluxio is running as expected by running
sudo runuser -l alluxio -c "/opt/alluxio/bin/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.
Creating a Table
The simplest step to using EMR with Alluxio is to create a table on Alluxio and query it using Presto/Hive.
- SSH into the ‘hadoop’ user in the master node. Then switch to the ‘alluxio’ user.
- Create a directory in Alluxio to be the external location of your table.
/opt/alluxio/bin/alluxio fs mkdir /testTable
- Set the ‘hadoop’ user to be the owner of the directory
/opt/alluxio/bin/alluxio fs chown hadoop:hadoop /testTable
- Exit to switch back into the ‘hadoop’ user and start the hive CLI.
- Create a new database to see if AWS Glue is working as expected. Check the console
to see if the database is created.
CREATE DATABASE glue;
- Use the newly created database and define a table.
USE glue; create external table test1 (userid INT, age INT, gender CHAR(1), occupation STRING, zipcode STRING) ROW FORMAT DELIMITED FIELDS TERMINATED BY '|' LOCATION 'alluxio:///testTable';
- Create the Presto /tmp directory
#Create Presto temp directory sudo runuser -l alluxio -c "/opt/alluxio/bin/alluxio fs mkdir /tmp" sudo runuser -l alluxio -c "/opt/alluxio/bin/alluxio fs chmod 777 /tmp" presto-cli --catalog hive
- Insert values into the table
USE glue; INSERT INTO test1 VALUES (1, 24, 'F', 'Developer', '12345');
- Read back the values in the table
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.
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.
Any server-side configuration changes must be made in the
alluxio-emr.sh bootstrap script. In the section for generating
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.
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