Amazon EFS with Posit Team
Before continuing, review the Storage documentation as it likely supersedes the content on this page.
This page explains how to set up Amazon Elastic File System (EFS) with Posit Team and details best practices for ongoing usage of EFS. Additionally, this document covers how we came up with these recommendations.
Amazon EFS has unique design characteristics that can make it challenging to use with Posit Team. To be successful with EFS, read this entire page and adhere to its guidance.
Amazon EFS is a managed shared file system that scales elastically with the amount of storage you use. Since it supports Network File System (NFS), it is possible to use EFS as the shared file system with Posit products. However, in some situations relevant to Posit Professional Products, EFS can suffer from slower performance relative to Elastic Block Store (EBS).
This slower performance is particularly prevalent in workloads that are sensitive to latency (as opposed to throughput). Specifically, EFS is not performant when reading and writing thousands of small files. When managing R workloads on a server, this can be problematic because some R packages that contain C++ code can contain a great many C++ header files. For example, the BH package on CRAN contains ~12K header files, so installation of BH can be slow on EFS.
On some rare occasions, this can also affect direct data science work in cases where the workflow requires reading many files. For example, performance might be poor when training a deep neural network that processes image files in bulk.
- Users interacting with EFS might experience slowness in certain operations. For additional information, see the Testing and benchmarking your configuration with
fsbenchsection below. - Configure EFS with specific settings, as described below.
Product-specific limitations and recommendations
This section is relevant to Posit Workbench, Posit Connect, and Posit Package Manager usage. We only have a few product-specific limitations and recommendations.
The default lock type of link-based does not work. Use the advisory type instead.
Use RStudio Workbench 1.4 or later, including all versions of Workbench.
NoteUpgrade to version 2021-09.0We highly recommend upgrading to version 2021-09.0 because this release includes several performance improvements for EFS.
- If you choose to configure
Database.Dir, this also must point to the same shared location.
- Use the
lookupcache=posmount option (see Recommended EFS configuration settings). For Package Manager specifics, see the NFS documentation.
Recommended EFS configuration settings
When using and configuring EFS:
- Use the general purpose performance mode, rather than Max I/O mode.
- For most cases, use bursting behavior rather than provisioned throughput.
- Single-zone EFS performs much faster than multiple availability zone, but choose it carefully.
- Install and use the Amazon package
efs-utilsto mount the file system, since this can sometimes have a significant positive impact. - Use the
lookupcache=posmount option for any multi-server deployment where products share the file system. It caches positive lookups, but does not cache negative ones, so a stale not-found entry does not mask a file created on another node. While this might cause poorer lookup-cache performance, it prevents difficult-to-diagnose intermittent file-consistency errors. - If mounting with EFS Access Points, be cautious, because this can mount all files with the same user ID (UID) and group ID (GID). Most deployments do not want this.
- Your choice of Amazon Elastic Compute Cloud (EC2) instance type can also affect performance. We recommend provisioning instances that are memory or compute optimized (do not choose general-purpose instances), and choose the network-enhanced options, e.g.,
r5n.2xlarge. - Use CloudWatch to monitor usage and identify system performance bottlenecks. In particular, watch out for situations where your burst credits run out, because performance is much worse without bursting.
- The AWS EFS Container Storage Interface (CSI) driver simplifies provisioning EFS volumes for workloads that run in Kubernetes. You can install it on an Amazon Elastic Kubernetes Service (EKS) cluster. There are two main methods of volume provisioning, dynamic and static provisioning. Workbench and Connect do not support dynamic provisioning because it has a user-identity enforcement requirement.
Special considerations
- Operations that write many small files (thousands or more) do not perform well in most EFS settings.
- To prevent users from having to repeatedly install R packages, Posit recommends preinstalling the R packages.
- Consider adopting code patterns that prefer reading large files over splitting data between many small files.
- When using an EFS file system for many users, we recommend segmenting data files into user-specific directories as much as is possible. Writing large files blocks metadata operations in that directory until the write completes. Separate user directories limit the impact on other users.
Since EFS performance is largely based on individual usage patterns, this document serves as a starting point rather than an absolute directive. Tune your EFS configuration after you monitor user behavior. You might need to adjust the configuration over time to keep performance high.
Details on recommended EFS configuration settings
Max I/O vs. general purpose
When creating a file system, you must choose a performance mode which is permanent.
We strongly recommend using the GeneralPurpose mode.
File systems in the Max I/O mode can scale to higher levels of aggregate throughput and operations per second. This scaling comes with a tradeoff of slightly higher latencies for file metadata operations. Highly parallelized applications and workloads, such as big data analysis, media processing, and genomic analysis, can benefit from this mode.
However, in Posit testing, we have found Max IO mode to offer significantly worse performance because of the increased latency, especially in the “many small files” scenario.
Bursting vs. provisioned throughput
EFS supports two throughput modes:
- Bursting
- Provisioned
From the AWS documentation page:
With Bursting Throughput mode, throughput on Amazon EFS scales as the size of your file system in the EFS Standard or One Zone storage class grows. With Provisioned Throughput mode, you can instantly provision the throughput of your file system (in MiB/s) independent of the amount of data stored.
We recommend that most deployments start with the default bursting behavior until you understand your file access patterns and the costs they incur.
Monitor your Burst Credit balance and permitted throughput via CloudWatch so that throttling does not surprise you if you run out of burst credits. We highly recommend setting alarms based on these metrics.
Remedy throttling by generating more Burst Credits or by converting to Provisioned Throughput mode. To generate Burst Credits, write files to the file system or wait for the credits to refresh. Large file systems (> 1TB) can burst for up to 50% of the time. For smaller file systems, set Provisioned Throughput to maintain a constant performance level.
Generating large files to bump into a larger tier of burst performance is both time consuming and expensive. Ensure that you consider these options. For example, creating 1TB of data might cost hundreds of dollars per month in storage costs.
If migrating to EFS, Provisioned Throughput can help save time to move a lot of data. In testing, moving from Bursting to 500MiB Provisioned improved speed by 5x and preserved Burst Credits.
In testing with One Zone storage (see below), differences between bursting and provisioned performance were minimal.
Multiple Availability Zone (default) vs. One Zone storage classes
AWS offers Single Availability Zone (AZ) EFS with a different service level agreement (SLA) than Multiple AZ instances. Multiple AZ EFS instances support 99.99% uptime, and Single AZ instances support 99.9% uptime. The Single AZ EFS is still durable, but there is no failover if the entire availability zone goes down. Most organizations adopting EFS to load balance Posit professional products prefer the Multiple AZ SLA. However, the Single AZ EFS performance is substantially better than Multiple AZ EFS, such that in testing, its performance was comparable to a custom-configured NFS server.
This makes the Single AZ EFS server a strong option when configuring development environments.
Read more about storage classes.
Use efs-utils when mounting the file system
We strongly recommend using efs-utils to mount the EFS file system. If this is not feasible, standard NFS client connections are possible, but follow the mounting instructions and review the additional considerations.
Setting the read_ahead_kb size to 15 MB
From the AWS performance tips page:
Linux kernels (5.4.*) use a
read_ahead_kbof 128 KB, however the AWS docs recommend 15 MB
The efs-utils package usually sets read_ahead_kb to 15 MB. Check this value to make sure. If you use only standard NFS utilities, you must set read_ahead_kb to 15 MB yourself.
EC2 instance types
In general for EFS, AWS recommends preferring instance types with more CPU or memory depending on the workload. Prefer memory-optimized or compute-optimized over general-purpose instance types.
In Posit benchmarking, we have observed performance gains by using memory-optimized instance types, e.g., r5. For UI-related tasks like installing the BH package, this might provide a better user experience.
For server installations that use many NFS client connections (e.g., Launcher), the enhanced networking might prove to be noticeably better. Consider using the n variants, e.g., r5n.
EC2 instance sizes
We have observed significant gains in going from large to xlarge instance sizes, primarily in parallelized load. For servers with many users, Posit recommends increasing the instance size.
Do not attempt to use smaller instance types, e.g., c5.large with 4GB memory.
Monitoring usage
The best way to monitor EFS performance is to configure AWS CloudWatch. Please refer to the available CloudWatch metrics and metric math for EFS resources for more information.
If using Bursting mode:
- Be sure to monitor the
BurstCreditBalancemetric. If this metric decreases substantially over time, you can add data to move the file system into a larger tier with more burst credits. Or, you can move to Provisioned Throughput for a consistent baseline. This is likely to incur extra cost, so please consider the tradeoffs before proceeding. - Using metric math, you can compare
MeteredIOBytestoPermittedThroughputto know if you are using all your available throughput. If you are, consider moving to Provisioned Throughput.
If using Provisioned Throughput:
- Use
PermittedThroughputto determine whether your storage volume has bumped you above your designated throughput setting.
Testing and benchmarking your configuration with fsbench
If you want to collect data about file system performance on your own EFS installation, use the Posit benchmarking tool. The benchmarking tool runs a suite of file operations to help characterize system behavior and compare it against other known configurations.
For information on how to configure and run benchmark testing, please refer to the fsbench package documentation.