Appearance
Memory Settings Guide
Optimize BrowserStack Code Quality memory allocation for efficient analysis of large codebases.
Two Analysis Modes — Where to Configure
BrowserStack Code Quality supports two distinct analysis modes, and memory must be tuned at the right place for each:
| Analysis Mode | Where Analysis Runs | Where to Set Memory |
|---|---|---|
| Server (UI / Docker) | Inside the Docker container on the server | Docker environment variables (-e ANALYSER_XMX=...) |
| Remote / CLI | On the machine running the embold-scanner CLI (your laptop or CI/CD agent) | Shell environment variables on that machine (e.g., export ANALYSER_XMX=...) |
The environment variable names are the same in both modes — the difference is only where you set them.
Overview
For repositories with 2+ million lines of code, proper memory configuration is essential for successful analysis. Two key settings control memory usage:
- Container / Process Memory: Total memory available to the analysis process
- Analyzer Heap (
ANALYSER_XMX): Memory specifically for the analysis engine (JVM heap)
Memory Recommendations
Size-Based Configuration
| Lines of Code | ANALYSER_XMX | Container Memory (-m) | Recommended RAM |
|---|---|---|---|
| Up to 1 Million | -Xmx6g | 12GB | 16 GB |
| 2-10 Million | -Xmx15g | 30GB | 32 GB |
| 10+ Million | -Xmx30g | 60GB | 64 GB |
Memory Allocation Rules
- Keep
ANALYSER_XMX≤ 70% of container memory ANALYSER_XMXscales with lines of code (LOC)ANALYSER_XMXandRISK_XMXare independent settings
Configuration Examples
Server Mode — Docker Compose
yaml
version: '3.8'
services:
app:
image: "browserstack/code-quality:1.9.36.0"
environment:
- ANALYSER_XMX=-Xmx15g
- RISK_XMX=-Xmx1024m
deploy:
resources:
limits:
memory: 30GServer Mode — Docker Run
bash
docker run -m 30GB -d \
-e ANALYSER_XMX=-Xmx15360m \
-e RISK_XMX=-Xmx1024m \
-p 3000:3000 \
--name BrowserStackCodeQuality \
[other options] \
browserstack/code-quality:1.9.36.0CLI / Remote Analysis Mode
When running the embold-scanner CLI directly (on your machine or a CI/CD agent), set the environment variable in your shell before executing the scan:
bash
# Set analyzer heap size for CLI analysis
export ANALYSER_XMX=-Xmx8g
# Then run the scanner as usual
./browserstack-codequality-scanner/bin/embold-scanner analyse \
-u https://demo.embold.io \
-t $EMBOLD_TOKEN \
-r {YOUR_REPO_UID} \
-c ./repository-configuration.jsonIn a CI/CD pipeline (e.g., GitHub Actions, Jenkins, GitLab CI), set it as a pipeline environment variable:
yaml
# GitHub Actions / GitLab CI example
env:
ANALYSER_XMX: "-Xmx8g"groovy
// Jenkinsfile example
environment {
ANALYSER_XMX = '-Xmx8g'
}Note: For CLI mode there is no container memory limit (
-m). Ensure the machine or CI/CD agent has enough physical RAM to accommodate the heap size you configure.
Memory Distribution Guidelines
Analyzer Memory as % of Container Memory
| Repository Size | Analyzer Memory % |
|---|---|
| < 1M LOC | 35-37% |
| 1-3M LOC | 40-42% |
| 3-5M LOC | 50-55% |
Memory Consumers
Primary consumers of container memory:
- Analysis Engine: 50-70% (configured via
ANALYSER_XMX) - UI Services: 15-20%
- Controller Processes: 10-15%
- Database Operations: 5-10%
Optimization Strategies
For Complex Codebases
High code duplication or mixed languages may require:
- 20-30% more memory than standard recommendations
- Additional monitoring during initial scans
- Iterative tuning based on actual performance
Performance Monitoring
bash
# Monitor container memory usage
docker stats BrowserStackCodeQuality
# Check for memory pressure in logs
docker logs BrowserStackCodeQuality | grep -i "memory\|heap\|gc"Troubleshooting
Out of Memory Errors
Symptoms:
- Analysis fails with heap space errors
- Container restarts during analysis
- Slow performance or timeouts
Solutions:
- Increase
ANALYSER_XMX(ensure < 70% of container memory) - Increase container memory limit (
-mparameter) - Enable multi-threaded execution with appropriate memory
- Use remote scanning for very large repositories
Memory Optimization Tips
- Start with recommendations and adjust based on performance
- Monitor first scan closely and tune accordingly
- Use SSD storage to reduce memory pressure from I/O
- Consider remote scanning for repositories > 10M LOC
- Enable garbage collection logging for detailed analysis
Advanced Configuration
Remote Scanning for Large Repositories
For repositories exceeding memory capacity:
bash
# Enable remote scan mode
-e EMB_REMOTE_SCAN=true
-e EMB_REMOTE_SCAN_STRICT=true # For C++ accuracyMonitoring and Alerts
bash
# Set memory usage alerts
docker run --memory=30g --oom-kill-disable=false \
[other options]Environment Variables Reference
| Variable | Where It Applies | Purpose | Example |
|---|---|---|---|
ANALYSER_XMX | Server (Docker) & CLI | Analysis engine heap size | -Xmx15g |
RISK_XMX | Server (Docker) | Risk calculation heap size | -Xmx1024m |
EMB_ANALYSER_THREADS | Server (Docker) & CLI | Analysis thread count | 8 |
EMB_PARSER_THREADS | Server (Docker) & CLI | Java parser thread count | 4 |
EMB_REMOTE_SCAN | Server (Docker) | Enable remote scanning | true |
Related Topics
- Multi-Threaded Execution - How to tune thread count for both Server and CLI modes
- BrowserStack Code Quality CLI - Running remote analysis from the CLI
- CI/CD Integration - Setting memory and thread variables in your pipeline
- Docker Deployment - Full container setup guide
