How to manage memory allocations for a Niagara 4 Web Supervisor
Proper memory allocation is crucial for Niagara 4 Web Supervisor performance. This guide covers how to configure, monitor, and optimise memory settings to ensure reliable operation and prevent out-of-memory errors.
Overview
Memory management for Niagara 4 Web Supervisor involves:
- Java Heap Memory: Primary memory for Java Virtual Machine (JVM)
- Native Memory: Memory for native libraries and system resources
- Garbage Collection: Automatic memory management and cleanup
- Memory Monitoring: Tracking memory usage and performance
Understanding Memory Architecture
Memory Components
Niagara Web Supervisor uses:
- Heap Memory: Where Java objects are stored
- Non-Heap Memory: Metaspace, code cache, native memory
- System Memory: Operating system memory usage
- Reserved Memory: Memory reserved but not yet used
Memory Limits
Default memory allocations:
- Initial Heap: Typically 256MB or 512MB
- Maximum Heap: Typically 1GB or 2GB
- Metaspace: Grows as needed (Java 8+)
- Native Memory: Varies based on system resources
Step-by-Step Configuration
Step 1: Locate Supervisor Configuration
- Identify Supervisor Installation: Locate Niagara Web Supervisor installation directory
- Configuration Files: Find supervisor configuration files:
supervisor.conforsupervisor.iniwrapper.conf(if using Java Service Wrapper)niagara.envor environment configuration files
Common locations:
C:\Niagara\(Windows)/opt/niagara/(Linux)- Installation-specific directories
Step 2: Access Configuration Files
- Stop Supervisor: Stop the Niagara Web Supervisor service before editing
- Backup Configuration: Create backup of configuration files
- Open Configuration: Open configuration file in text editor with administrator privileges
Step 3: Configure Initial Heap Size
Set the initial Java heap size:
For wrapper.conf (Java Service Wrapper):
wrapper.java.initmemory=512
For supervisor.conf:
java.initmemory=512
For command-line or environment:
-Xms512m
Where 512 is the initial heap size in megabytes.
Step 4: Configure Maximum Heap Size
Set the maximum Java heap size:
For wrapper.conf:
wrapper.java.maxmemory=2048
For supervisor.conf:
java.maxmemory=2048
For command-line:
-Xmx2048m
Where 2048 is the maximum heap size in megabytes.
Step 5: Configure Garbage Collection
Configure garbage collection settings for optimal performance:
For wrapper.conf or command-line:
wrapper.java.additional.1=-XX:+UseG1GC
wrapper.java.additional.2=-XX:MaxGCPauseMillis=200
wrapper.java.additional.3=-XX:G1HeapRegionSize=16m
Or for older Java versions:
wrapper.java.additional.1=-XX:+UseParallelGC
wrapper.java.additional.2=-XX:ParallelGCThreads=4
Step 6: Configure Metaspace (Java 8+)
For Java 8 and later, configure Metaspace:
wrapper.java.additional.4=-XX:MetaspaceSize=256m
wrapper.java.additional.5=-XX:MaxMetaspaceSize=512m
Step 7: Configure Native Memory
Set native memory limits if needed:
wrapper.java.additional.6=-XX:MaxDirectMemorySize=512m
Step 8: Save and Restart
- Save Configuration: Save all configuration file changes
- Restart Supervisor: Restart the Niagara Web Supervisor service
- Verify Startup: Check supervisor starts successfully
- Monitor Memory: Monitor memory usage after restart
Memory Configuration Examples
Small Installation (< 1000 points)
wrapper.java.initmemory=256
wrapper.java.maxmemory=1024
wrapper.java.additional.1=-XX:+UseG1GC
wrapper.java.additional.2=-XX:MaxGCPauseMillis=200
Medium Installation (1000-5000 points)
wrapper.java.initmemory=512
wrapper.java.maxmemory=2048
wrapper.java.additional.1=-XX:+UseG1GC
wrapper.java.additional.2=-XX:MaxGCPauseMillis=200
wrapper.java.additional.3=-XX:G1HeapRegionSize=16m
Large Installation (> 5000 points)
wrapper.java.initmemory=1024
wrapper.java.maxmemory=4096
wrapper.java.additional.1=-XX:+UseG1GC
wrapper.java.additional.2=-XX:MaxGCPauseMillis=200
wrapper.java.additional.3=-XX:G1HeapRegionSize=32m
wrapper.java.additional.4=-XX:MetaspaceSize=512m
wrapper.java.additional.5=-XX:MaxMetaspaceSize=1024m
Monitoring Memory Usage
Using Workbench
- Connect to Supervisor: Connect Workbench to Supervisor
- System Monitor: Navigate to System Monitor or Performance Monitor
- Memory Metrics: View memory usage metrics:
- Heap memory used/available
- Non-heap memory usage
- Garbage collection statistics
- Memory pool details
Using Platform Services
- Platform Services: Access Platform Services in Workbench
- JVM Monitor: Use JVM monitoring tools
- Memory Statistics: Review memory statistics and trends
Using Operating System Tools
Windows:
tasklist /FI "IMAGENAME eq java.exe" /FO TABLE
Or use Task Manager to monitor Java process memory.
Linux:
ps aux | grep java
top -p <java_pid>
Or use jstat for detailed JVM statistics:
jstat -gc <pid> 1000
Troubleshooting
Out of Memory Errors
If experiencing out-of-memory errors:
- Increase Maximum Heap: Increase
-Xmxvalue - Check System Memory: Ensure system has sufficient RAM
- Review Memory Usage: Identify memory-intensive operations
- Optimise Code: Review and optimise custom code
- Garbage Collection: Tune garbage collection settings
High Memory Usage
If memory usage is consistently high:
- Monitor Trends: Track memory usage over time
- Identify Leaks: Look for memory leaks in applications
- Review Configuration: Check for unnecessary services
- Optimise Applications: Optimise custom applications
- Increase Allocation: Consider increasing maximum heap if needed
Garbage Collection Issues
If experiencing GC problems:
- GC Logging: Enable GC logging to analyse patterns
- GC Tuning: Adjust GC algorithm and parameters
- Heap Size: Ensure heap size is appropriate
- GC Frequency: Monitor GC frequency and duration
- Professional Tuning: Consider professional JVM tuning
Performance Degradation
If performance degrades:
- Memory Pressure: Check for memory pressure
- GC Overhead: Monitor garbage collection overhead
- Heap Fragmentation: Check for heap fragmentation
- Native Memory: Monitor native memory usage
- System Resources: Check overall system resources
Best Practices
Memory Sizing
- Start Conservative: Begin with conservative memory settings
- Monitor and Adjust: Monitor usage and adjust as needed
- Leave Headroom: Don't allocate all available memory
- System Resources: Reserve memory for operating system
Garbage Collection
- Choose Appropriate GC: Select GC algorithm for your workload
- Monitor GC Performance: Regularly monitor GC statistics
- Tune Gradually: Make incremental GC tuning changes
- Test Changes: Test GC changes in development first
Monitoring
- Regular Monitoring: Monitor memory usage regularly
- Set Alerts: Configure alerts for high memory usage
- Trend Analysis: Analyse memory usage trends
- Documentation: Document memory configuration and changes
Maintenance
- Regular Reviews: Periodically review memory configuration
- Update Settings: Update settings as system grows
- Optimise Applications: Optimise applications to reduce memory usage
- Keep Current: Stay current with Niagara and Java updates
Advanced Configuration
Custom JVM Arguments
Add custom JVM arguments for specific needs:
wrapper.java.additional.7=-XX:+HeapDumpOnOutOfMemoryError
wrapper.java.additional.8=-XX:HeapDumpPath=/var/log/niagara/
wrapper.java.additional.9=-XX:+PrintGCDetails
wrapper.java.additional.10=-Xlog:gc*:file=/var/log/niagara/gc.log
Memory Profiling
Enable memory profiling for analysis:
- Enable Profiling: Configure JVM for profiling
- Use Profiling Tools: Use tools like VisualVM, JProfiler
- Analyse Results: Analyse profiling results
- Optimise Based on Results: Make optimisations based on analysis
Related Topics
- How to calculate the quantity of Global Capacity Points consumed in a Station
- What to do when a Platform login is failing
Additional Resources
- Niagara 4 System Administration Guide
- Java Virtual Machine Tuning Guide
- Garbage Collection Tuning Documentation
- Memory Management Best Practices