Lab 5 – Resource Management in Posit Workbench

1 Learning Objectives

By the end of this lab, you will be able to:

  • Explain how cgroups-v2 enables CPU and memory enforcement in Workbench
  • Configure resource profiles to define session size options
  • Restrict resource profile access to specific users and groups
  • Verify resource profile configurations by testing with different user accounts
NoteTimings for this chapter
  • Reading time: 15 minutes
  • Documentation reading time: 10-20 minutes
  • Hands-on exercise time: 15-30 minutes

2 Introduction

Data science workloads can easily consume large amounts of both CPU and memory, sometimes unexpectedly. User and Group Profiles allow Workbench to both constrain user sessions to reasonable resource consumption and provide pre-defined session sizes to different users.

This concept applies similarly regardless of whether Workbench runs in a single VM or uses an entire Kubernetes cluster. All Posit Launcher integrations include the ability to limit these resources on a per-session basis.

3 Configuring Resource Profiles in a Single-Node Workbench Installation

On a single server, the first step in your configuration is to enable cgroups-v2. (Please note the extra steps required for Red Hat Enterprise Linux, which we do not need to worry about in this Ubuntu-based lab environment.) Configuring cgroups allows Workbench to enforce CPU and memory resource limits on user sessions.

To verify that cgroups-v2 is enabled on your system, run:

Terminal
mount | grep cgroup2

The output shows that cgroup2 is mounted. On Ubuntu 20.04 and later, cgroups-v2 is typically enabled by default.

Once you have confirmed that cgroups is enabled, you need to configure some resource profiles that will take advantage of these limits.

Using the documentation as a reference, create or edit the /etc/rstudio/launcher.local.resources.conf file to include the following:

/etc/rstudio/launcher.local.resources.conf
[default]
name=Default
cpus=1
mem-mb=4096

[small]
cpus=1
mem-mb=1024

[hugemem]
name=Huge Memory
cpus=4
mem-mb=8192

The name field is optional; if not provided, the profile name will be used as the display name.

Set these values based on the type of work your users do, in consultation with them. Also consider the number of users and the CPU and memory available on your instance.

With these profiles defined, all Workbench users will be able to select any of these profiles when launching a new session. In some cases, you might want to restrict access to certain profiles based on the user or the groups they belong to. This can be done using User and Group Profiles.

For instance, to restrict access to the hugemem profile to only users in the data-science-leadership group and to let users in this group use custom resources, you can create or edit the /etc/rstudio/launcher.local.profiles.conf file to include the following:

/etc/rstudio/launcher.local.profiles.conf
[*]
resource-profiles=default,small
allow-custom-resources=0

[@data-science-leadership]
resource-profiles=default,small,hugemem
allow-custom-resources=1

3.1 Testing the Configuration

Before testing these configurations, create the data-science-leadership group on the system and add the appropriate users to it. Workbench cannot automatically create groups when using Just-In-Time (JIT) provisioning. Run the following commands:

Terminal
# Create the data-science-leadership group
sudo groupadd data-science-leadership

# Add elena.rodriguez to the group
sudo usermod -aG data-science-leadership elena.rodriguez

# Verify group membership
getent group data-science-leadership

Restart Workbench, verify that it has started, log out1, and then log in as someone from the data-engineers team (for instance, olivia.clark). Attempt to launch a session and confirm that you can only see the default and small profiles.

Log out and log back in as someone in the data-science-leadership group (for instance, elena.rodriguez), and verify that you have access to the Huge Memory profile and can configure custom resources for this user.

TipWhy is it relevant to me?

Resource management affects system stability and user satisfaction. Without limits, a single user running memory-intensive analysis can crash the server for everyone. By implementing resource profiles, you can prevent such scenarios, ensuring fair resource distribution and optimal performance for all users.

4 Check Your Understanding

  1. What is the purpose of enabling cgroups-v2 before configuring resource profiles in Workbench?

  2. A user in the data-science-leadership group launches a session and does not see the Huge Memory profile. What are two likely causes?

  3. You need to give a new group, ml-engineers, access to the hugemem profile but not the ability to set custom resources. What entry would you add to launcher.local.profiles.conf?

  1. cgroups-v2 is the Linux kernel mechanism that allows Workbench to enforce CPU and memory limits on user sessions. Without it, resource profiles can be defined but the limits cannot be applied at the operating system level. Users can exceed their allocated resources.

    • The launcher.local.profiles.conf file may not have been saved correctly, or the [@data-science-leadership] section is missing or misspelled.
    • Workbench was not restarted after the configuration change — changes to launcher configuration files require a restart to take effect.
/etc/rstudio/launcher.local.profiles.conf
[@ml-engineers]
resource-profiles=default,small,hugemem
allow-custom-resources=0

This grants access to the hugemem profile while keeping custom resource configuration disabled for that group.