Multi-Threading Configuration in AAA: How Azeroth Auction Assassin Manages Concurrent API Requests
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 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 (lines 85-94).
# 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. 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:
- Alert Loop (lines 81-84): The continuous monitoring mode that periodically scans for auction deals.
- Fast Run (lines 89-92): A one-shot execution mode for immediate scans.
# 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 and 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:
{
"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:
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_THREADSconfiguration variable governs AAA’s multi-threading behavior, defaulting to 48 threads. - Configuration Hierarchy: Values are read from
mega_data.json, then environment variables, then the hardcoded default inutils/mega_data_setup.py. - Execution: The
ThreadPoolExecutorinmega_alerts.pyusesmax_workers=mega_data.THREADSto parallelize Blizzard API calls across realms. - UI Separation: PyQt5
QThreadworkers handle interface tasks independently and do not consume theMEGA_THREADSpool.
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 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 and 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 or as an environment variable, which MegaData.__set_mega_vars processes during initialization in utils/mega_data_setup.py.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →