Files
mongo/buildscripts/cost_model/README.md
Max Verbinnen 789e63f102 SERVER-117084 Calibrate CPU factor & sequential/random IO (#48257)
GitOrigin-RevId: 1a5d600246ffbd2ac0491b5ddda80fa0e85d4b02
2026-02-24 10:13:45 +00:00

99 lines
1.8 KiB
Markdown

# Cost Model Calibrator
## Getting Started
### 1) Setup Mongod
First, prepare the MongoDB server:
1. Activate the standard virtual environment:
```sh
source python3-venv/bin/activate
```
2. Build server with optimizations (makes doc insertion faster):
```sh
(python3-venv) bazel build --config=opt install-devcore
```
3. Run mongod instance (only for CBR calibration, because join_start.py manages mongod's lifecycle itself):
```sh
(python3-venv) bazel-bin/install-mongod/bin/mongod --setParameter internalMeasureQueryExecutionTimeInNanoseconds=true
```
### 2) Setup Cost Model Calibrator
In another terminal:
1. Navigate to the cost model directory:
```sh
cd buildscripts/cost_model
```
2. Set up Python alias to use MongoDB toolchain:
```sh
alias python=/opt/mongodbtoolchain/v4/bin/python3
```
3. Deactivate any existing Python environment (if needed):
```sh
deactivate
```
4. Create new virtual environment:
```sh
/opt/mongodbtoolchain/v4/bin/python3 -m venv cm
```
5. Activate the new environment:
```sh
source cm/bin/activate
```
6. Install required packages:
```sh
(cm) python -m pip install -r requirements.txt
```
7. Run the calibrator:
- For CBR cost model calibration:
```sh
(cm) python start.py
```
- For JOO cost model calibration:
```sh
(cm) python join_start.py
```
**Note:** For CBR calibration, the first time it will take a while since it has to generate the data. Afterwards, as long as you aren't modifying the collections, you can comment out `await generator.populate_collections()` in `start.py` - this will make it a lot faster.
8. When done, deactivate the environment:
```sh
(cm) deactivate
```
## Install New Packages
1. Install the package:
```sh
(cm) python -m pip install <package_name>
```
2. Update requirements.txt:
```sh
(cm) python -m pip freeze > requirements.txt
```