# Multi-Threading Configuration in AAA: How Azeroth Auction Assassin Manages Concurrent API Requests

> Discover Azeroth Auction Assassin's multi threading configuration. Learn how MEGA_THREADS manages concurrent API requests for optimized performance with the ThreadPoolExecutor.

- Repository: [FF14 Advanced Market Search/azerothauctionassassin](https://github.com/ff14-advanced-market-search/azerothauctionassassin)
- Tags: how-to-guide
- Published: 2026-03-01

---

**Azeroth Auction Assassin (AAA) controls its multi-threading behavior through the `MEGA_THREADS` configuration variable, which defaults to 48 threads and sets the size of the `ThreadPoolExecutor` used for parallel Blizzard API calls.**

The multi-threading configuration in AAA directly impacts how quickly the application can scan auction house data across multiple World of Warcraft realms. By adjusting the `MEGA_THREADS` value, users can optimize API throughput based on their system resources and network capacity.

## How MEGA_THREADS Controls the Multi-Threading Configuration in AAA

The `MEGA_THREADS` setting determines the maximum number of concurrent API requests AAA can execute simultaneously. This value propagates through the application’s configuration layer and directly instantiates the `ThreadPoolExecutor` in the alert loop.

### Configuration Sources and Priority

AAA reads the thread count from [`mega_data.json`](https://github.com/ff14-advanced-market-search/azerothauctionassassin/blob/main/mega_data.json) using the `"MEGA_THREADS"` key. If the key is absent, the application falls back to the environment variable `MEGA_THREADS`. If neither source provides a value, AAA uses a hardcoded default. This logic resides in `MegaData.__set_mega_vars` within [`utils/mega_data_setup.py`](https://github.com/ff14-advanced-market-search/azerothauctionassassin/blob/main/utils/mega_data_setup.py) (lines 85-94).

```python

# From utils/mega_data_setup.py (simplified)

self.THREADS = self.__set_mega_vars("MEGA_THREADS", raw_mega_data)

```

The resolved value is stored in `mega_data.THREADS` when the `MegaData` instance initializes (lines 39-44).

### Default Thread Pool Size

If no configuration override exists, **AAA defaults to 48 threads**. This default balances API rate limit compliance with reasonable throughput for most consumer hardware.

## ThreadPoolExecutor Implementation in mega_alerts.py

The core scanning logic consumes the `MEGA_THREADS` configuration in [`mega_alerts.py`](https://github.com/ff14-advanced-market-search/azerothauctionassassin/blob/main/mega_alerts.py). Here, AAA creates a `ThreadPoolExecutor` using `max_workers=mega_data.THREADS` to parallelize realm data fetching.

The pool instantiation appears in two primary execution paths:

1. **Alert Loop** (lines 81-84): The continuous monitoring mode that periodically scans for auction deals.
2. **Fast Run** (lines 89-92): A one-shot execution mode for immediate scans.

```python

# From mega_alerts.py (conceptual)

from concurrent.futures import ThreadPoolExecutor

# mega_data.THREADS contains the MEGA_THREADS value

with ThreadPoolExecutor(max_workers=mega_data.THREADS) as pool:
    for connected_id in matching_realms:
        pool.submit(pull_single_realm_data, connected_id)

```

Each worker thread executes `pull_single_realm_data()` to fetch auction house JSON from Blizzard’s API, enabling simultaneous requests across multiple realm connections.

## UI Background Workers vs. API Thread Pool

AAA employs two distinct threading models. While `MEGA_THREADS` governs API concurrency, the PyQt5 interface uses `QThread` subclasses for UI responsiveness. These background workers—defined in [`AzerothAuctionAssassin.py`](https://github.com/ff14-advanced-market-search/azerothauctionassassin/blob/main/AzerothAuctionAssassin.py) and [`AzerothAuctionTarget.py`](https://github.com/ff14-advanced-market-search/azerothauctionassassin/blob/main/AzerothAuctionTarget.py)—handle tasks like `Alerts`, `RecommendationsRequest`, and `Item_Statistics`.

**Critical distinction:** The Qt worker threads operate independently of the `MEGA_THREADS` configuration. They manage GUI updates and single-shot data fetching for the interface, not the high-volume realm scanning that saturates the ThreadPoolExecutor.

## Configuring Multi-Threading for Your Deployment

Adjust the `MEGA_THREADS` value based on your hardware capabilities and API rate limits. Higher values increase throughput but may trigger Blizzard API throttling or exhaust local network sockets.

### Via mega_data.json

Create or edit the configuration file to set a custom thread count:

```json
{
  "MEGA_THREADS": 64,
  "SCAN_TIME_MIN": 5,
  "SCAN_TIME_MAX": 10,
  "WOW_CLIENT_ID": "your_client_id_here",
  "WOW_CLIENT_SECRET": "your_client_secret_here"
}

```

### Via Environment Variable

For containerized deployments or CI pipelines, export the variable before launching AAA:

```bash
export MEGA_THREADS=32
python main/AzerothAuctionAssassin.py

```

### Verification

Confirm the active configuration by checking the logs or inspecting the `mega_data.THREADS` attribute at runtime. The value should match your configured `MEGA_THREADS` setting or the default of 48.

## Summary

- **Primary Control:** The `MEGA_THREADS` configuration variable governs AAA’s multi-threading behavior, defaulting to **48 threads**.
- **Configuration Hierarchy:** Values are read from [`mega_data.json`](https://github.com/ff14-advanced-market-search/azerothauctionassassin/blob/main/mega_data.json), then environment variables, then the hardcoded default in [`utils/mega_data_setup.py`](https://github.com/ff14-advanced-market-search/azerothauctionassassin/blob/main/utils/mega_data_setup.py).
- **Execution:** The `ThreadPoolExecutor` in [`mega_alerts.py`](https://github.com/ff14-advanced-market-search/azerothauctionassassin/blob/main/mega_alerts.py) uses `max_workers=mega_data.THREADS` to parallelize Blizzard API calls across realms.
- **UI Separation:** PyQt5 `QThread` workers handle interface tasks independently and do not consume the `MEGA_THREADS` pool.

## Frequently Asked Questions

### How do I change the number of threads AAA uses for API calls?

Modify the `MEGA_THREADS` value in your [`mega_data.json`](https://github.com/ff14-advanced-market-search/azerothauctionassassin/blob/main/mega_data.json) file or set the `MEGA_THREADS` environment variable before starting the application. The new value will instantiate the `ThreadPoolExecutor` on the next scan cycle.

### What is the maximum number of threads I should configure?

While AAA defaults to 48 threads, optimal values depend on your system’s CPU cores, network bandwidth, and Blizzard’s API rate limits. Values above 64 may trigger throttling or connection timeouts without linear performance gains.

### Do the UI background workers use the MEGA_THREADS setting?

No. The `QThread` subclasses defined in [`AzerothAuctionAssassin.py`](https://github.com/ff14-advanced-market-search/azerothauctionassassin/blob/main/AzerothAuctionAssassin.py) and [`AzerothAuctionTarget.py`](https://github.com/ff14-advanced-market-search/azerothauctionassassin/blob/main/AzerothAuctionTarget.py) manage GUI responsiveness independently. They do not read from `mega_data.THREADS` and are not constrained by the `MEGA_THREADS` configuration.

### Can I set MEGA_THREADS via command-line arguments?

AAA does not expose `MEGA_THREADS` as a command-line argument. You must define it in [`mega_data.json`](https://github.com/ff14-advanced-market-search/azerothauctionassassin/blob/main/mega_data.json) or as an environment variable, which `MegaData.__set_mega_vars` processes during initialization in [`utils/mega_data_setup.py`](https://github.com/ff14-advanced-market-search/azerothauctionassassin/blob/main/utils/mega_data_setup.py).