Skip to content

Multi-Threaded Execution Guide

Optimize BrowserStack Code Quality performance by configuring multi-threaded execution for faster code analysis.

Overview

Multi-threaded execution significantly reduces analysis time by utilizing multiple CPU cores for parallel processing. Different components support different threading configurations.

Configuration Options

Analyzer Threading

Default: 4 threads
Environment Variable: EMB_ANALYSER_THREADS

bash
# Docker Compose - add to environment section
- EMB_ANALYSER_THREADS=8

# Docker run command
docker run -e EMB_ANALYSER_THREADS=8 [other options]

Recommendations:

  • Small projects (<1M LOC): 4-6 threads
  • Medium projects (1-5M LOC): 6-8 threads
  • Large projects (>5M LOC): 8-12 threads

Java Parser Threading

Default: 2 threads
Environment Variable: EMB_PARSER_THREADS

bash
# Docker Compose configuration
- EMB_PARSER_THREADS=4

# For Java-heavy codebases, increase to match CPU cores
- EMB_PARSER_THREADS=8

C++ Multi-Threading Setup

Default: Single thread
Configuration: Via scan settings

Method 1: Web Interface

  1. Go to ProjectsRepository List
  2. Click repository context menu (⋯) → Scan Configuration
  3. Add --jobs=4 under Additional Options
  4. Save configuration

Method 2: Repository Configuration File

  1. Download repository configuration file
  2. Edit the JSON to include:
json
{
  "settings": {
    "additionalOptions": [
      "--jobs=4"
    ],
    "includePaths": []
  }
}
  1. Upload the modified configuration

Performance Guidelines

Thread Count Recommendations

CPU CoresEMB_ANALYSER_THREADSEMB_PARSER_THREADSC++ --jobs
4 cores422
8 cores6-844
16 cores8-126-88

Memory Considerations

Higher thread counts require more memory:

  • Each analyzer thread: ~1-2 GB RAM
  • Each parser thread: ~512 MB - 1 GB RAM
  • Monitor memory usage and adjust threads accordingly

Configuration by Analysis Mode

Thread environment variables work in both analysis modes — set them wherever analysis runs.

Server Mode — Docker Compose

yaml
app:
  image: "browserstack/code-quality:1.9.36.0"
  environment:
    - EMB_ANALYSER_THREADS=8
    - EMB_PARSER_THREADS=4
    - EMB_CHECKER_THREADS=4
    - ANALYSER_XMX=-Xmx12g

Server Mode — Docker Run

bash
docker run -d \
  -e EMB_ANALYSER_THREADS=8 \
  -e EMB_PARSER_THREADS=4 \
  [other options] \
  browserstack/code-quality:1.9.36.0

CLI / Remote Analysis Mode

When running the embold-scanner CLI on your machine or a CI/CD agent, export the variables in the shell before the scan:

bash
# Set thread counts for local CLI analysis
export EMB_ANALYSER_THREADS=6
export EMB_PARSER_THREADS=4

./browserstack-codequality-scanner/bin/embold-scanner analyse \
  -u https://demo.embold.io \
  -t $EMBOLD_TOKEN \
  -r {YOUR_REPO_UID} \
  -c ./repository-configuration.json

In a CI/CD pipeline, declare them as pipeline environment variables:

yaml
# GitHub Actions / GitLab CI
env:
  EMB_ANALYSER_THREADS: "6"
  EMB_PARSER_THREADS: "4"
groovy
// Jenkinsfile
environment {
    EMB_ANALYSER_THREADS = '6'
    EMB_PARSER_THREADS   = '4'
}

Match thread count to the number of CPU cores available on the agent/machine running the CLI — do not exceed available cores.

Docker Run Example (legacy)

bash
docker run -d \
  -e EMB_ANALYSER_THREADS=8 \
  -e EMB_PARSER_THREADS=4 \
  -e EMB_CHECKER_THREADS=4 \
  -e ANALYSER_XMX=-Xmx12g \
  [other options] \
  browserstack/code-quality:1.9.36.0

Monitoring Performance

Check Thread Usage

bash
# Monitor container CPU usage
docker stats BrowserStackCodeQuality

# Check analysis logs for threading info
docker logs BrowserStackCodeQuality | grep -i thread

Performance Metrics

  • Reduced scan time: 30-70% improvement typical
  • CPU utilization: Should reach 70-90% during analysis
  • Memory usage: Monitor for memory pressure

Best Practices

  1. Start Conservative: Begin with 4-6 threads and monitor performance
  2. Match Hardware: Don't exceed available CPU cores
  3. Monitor Memory: Ensure sufficient RAM for selected thread counts
  4. Test Incrementally: Increase threads gradually while monitoring
  5. Language-Specific: C++ benefits most from threading, followed by Java

Troubleshooting

High CPU, Low Performance:

  • Reduce thread count if context switching overhead is high
  • Check for I/O bottlenecks (use SSD storage)

Out of Memory Errors:

Inconsistent Performance:

  • Ensure consistent thread settings across scans
  • Monitor system load during analysis