Skip to main content

CPU Quotas (soma login nodes)

The soma login nodes are shared resources. The total CPU resources are soft-limited in order to support multiple users. This is done using systemd quotas.

Unfortunately, Python libraries and command line utilities like nproc don't know about the soft limits and provide inaccurate user CPU core values, leading to oversubscribe processes when running custom parallel scripts.

Workaround

In this repository you will find some useful scripts that get the user CPU qouta values for soma login nodes:

1. python (get_available_cpus.py)

This script supports multiple usage modes and options:

Features:

  • Reads systemd CPU quota from /run/systemd/system/user-$UID.slice.d/50-CPUQuota.conf
  • Handles both percentage format (e.g., "200%") and decimal format (e.g., "2.0")
  • Provides a conservative mode that reserves CPU for system overhead
  • Can be imported as a module in other Python scripts
  • Includes a quiet mode ideal for scripting

Usage:

# Make executable
chmod +x get_available_cpus.py

# Basic usage
./get_available_cpus.py

# Conservative mode (reserves some CPU for system)
./get_available_cpus.py --conservative

# Quiet mode (just the number)
./get_available_cpus.py --quiet

In python scripts:

from get_available_cpus import get_parallel_workers

# Use in multiprocessing
import multiprocessing as mp
num_workers = get_parallel_workers()
with mp.Pool(num_workers) as pool:
    # your parallel code here

2. bash (get_available_cpus.sh)

This is a bash version of the script above for command-line usage:

Usage:

# Make executable
chmod +x get_available_cpus.sh

# Basic usage
./get_available_cpus.sh

# Use in other scripts
NUM_CPUS=$(./get_available_cpus.sh --quiet)

3. pip installing cpu_quota

How to install:

python -m pip install cpu_quota

Usage:

from cpu_quota import get_parallel_workers
num_workers = get_parallel_workers()

Features:

  • Systemd Integration: Reads actual CPU quota limits rather than just hardware CPU count
  • Fallback: Falls back to nproc if no systemd limits are found
  • Conservative Mode: Optionally reserves CPU capacity for system overhead
  • Error Handling: Gracefully handles missing files or parsing errors
  • Flexible Output: Quiet mode for scripting, verbose mode for debugging

Metadata

Release files for cpu-quota 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cpu-quota 0.1.0
File Size Uploaded
cpu_quota-0.1.0.tar.gz 7.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for cpu-quota 0.1.0
File Interpreter ABI Platform
cpu_quota-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 13.0 kB

Release files / cpu_quota-0.1.0.tar.gz

Download URL cpu_quota-0.1.0.tar.gz
Size 7.4 kB
Tags Source
SHA-256 checksum
How to use checksums
affe53ccc78f65974dbc1f3bc90711b89d5f343e790996e345af88254fe732ef
BLAKE2b-256 checksum
How to use checksums
f23575899b4012cef115cfbc9e1ec3b977b204ad2d2284ec4c72577c13285c1f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 29, 2025.

Transparency log

Release files / cpu_quota-0.1.0-py3-none-any.whl

Download URL cpu_quota-0.1.0-py3-none-any.whl
Size 5.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bbe5e7ae165fb8b9ad1f8d0923a41b1e285eaec13a0138fbb717cc3774a80734
BLAKE2b-256 checksum
How to use checksums
ec5423e9d5c801a52d82afeb66a0c232cd01861f190aadb6c70c811f5ca1c8e7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 29, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page