Memory Configuration
The underlying Java runtime (SubstrateVM) manages memory with a garbage collector. You can control memory allocation using theGRAALVM_OPTIONS environment variable.
Setting Maximum Heap Size
By default, maximum memory is automatically determined based on your machine’s available memory. To set a specific limit:Verifying Memory Settings
Enable debug logging to see the configured heap size:Common Memory Configurations
Environment Variables
Setting in Different Environments
Linux/macOS Shell
Linux/macOS Shell
Temporary (current session):Permanent (add to
~/.bashrc or ~/.zshrc):Windows Command Prompt
Windows Command Prompt
Temporary:Permanent:
Windows PowerShell
Windows PowerShell
Temporary:Permanent:
Jupyter Notebook
Jupyter Notebook
Python Script
Python Script
Advanced GraalVM Options
Garbage Collection Tuning
Multiple Options
Combine multiple options:-Xmx: Maximum heap size-Xms: Initial heap size--gc: Garbage collector type
Performance Optimization Tips
Adjust as needed
If you see OutOfMemoryError or excessive garbage collection:
- Increase
-Xmxvalue - Set
-Xmscloser to-Xmxto reduce reallocation
Troubleshooting
OutOfMemoryError
OutOfMemoryError
Symptoms: Program crashes with memory errorSolutions:
-
Increase heap size:
- Process smaller chunks of data
-
Use network reduction to limit network size:
Slow Performance
Slow Performance
Symptoms: Operations take longer than expectedSolutions:
-
Increase initial heap size to reduce allocations:
-
For short scripts, consider epsilon GC:
- Enable debug logging to identify bottlenecks
Settings Not Taking Effect
Settings Not Taking Effect
Symptoms: Memory limits don’t seem to applySolutions:
- Ensure variable is set before importing pypowsybl
-
Verify the environment variable:
- Restart Python interpreter/kernel
Platform-Specific Considerations
Docker Containers
When running in Docker:Cluster/HPC Environments
For SLURM or similar:Cloud Notebooks (Google Colab, etc.)
Cloud platforms may have memory limits. Check your instance’s available memory.
Recommended Configurations
Development
Production
Batch Processing
Interactive Analysis
Monitoring Memory Usage
Track memory consumption in your scripts:Best Practices
Set limits proactively
Set limits proactively
Don’t wait for memory errors. Estimate your needs:
- Small network (< 1000 buses): 1-2 GB
- Medium network (1000-10000 buses): 4-8 GB
- Large network (> 10000 buses): 16+ GB
Leave headroom
Leave headroom
Set heap size to 70-80% of available system memory:
Test with realistic data
Test with realistic data
Use production-sized networks for testing memory requirements.
Document your configuration
Document your configuration
Include memory requirements in your project documentation:
Configuration Functions
PyPowSyBl provides utility functions for managing configuration settings.print_version()
Display version information for PyPowSyBl and its components:- PyPowSyBl Python package
- PowSyBl Core Java libraries
- Native library components
set_config_read()
Control whether PyPowSyBl reads the~/.itools/config.yml configuration file:
Whether to read the configuration file
is_config_read()
Check the current configuration file reading status:bool - True if config file is being read, False otherwise
Configuration File Format
The~/.itools/config.yml file allows system-wide configuration of PowSyBl parameters:
Configuration file settings can be overridden by explicitly passing parameters to functions.
Next Steps
Logging
Configure detailed logging
Network
Back to network basics
