Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
115 commits
Select commit Hold shift + click to select a range
9f9f7ce
Added `initial_size` + Added user/pass to connect + NItz
mdashti Feb 21, 2024
f811314
Added autovac.
mdashti Feb 21, 2024
bf9e806
pid_demo
smihaylov-crystal Mar 6, 2024
9127153
rl initial commit
smihaylov-crystal Mar 7, 2024
acf6e7a
numerious fixes, incl transition to discrete control of autovacuum
smihaylov-crystal Mar 12, 2024
3780894
Wait until initial data is populated
smihaylov-crystal Mar 12, 2024
7cd0c5d
tweaks
smihaylov-crystal Mar 13, 2024
6c29005
support passing user, password, url and dbname as args
smihaylov-crystal Mar 13, 2024
ff5c7a3
fixes to set benchmarking options correctly, and tweaks to reward fun…
smihaylov-crystal Mar 13, 2024
86e8e70
specify number of episodes from command line
smihaylov-crystal Mar 13, 2024
0c30ad4
Add support for testing a previously learned model
smihaylov-crystal Mar 15, 2024
f10ab60
Make autovacuum penalty smaller
smihaylov-crystal Mar 15, 2024
172db18
Update reward. Do not penalize for a lot of data being read
smihaylov-crystal Mar 18, 2024
d91384b
Ignore updating stats when the table hasnt been created yet.
smihaylov-crystal Mar 18, 2024
d854264
Refactor RL code to better support custom workloads
smihaylov-crystal Mar 18, 2024
9d49d7b
tweaks
smihaylov-crystal Mar 19, 2024
c51b5b7
tweaks and formatting
smihaylov-crystal Mar 20, 2024
d79b92f
restore statement and small refactor for testability
smihaylov-crystal Mar 20, 2024
da9d792
fix import
smihaylov-crystal Mar 20, 2024
2f3138e
Make sure each action has at least a small chance of being selected w…
smihaylov-crystal Mar 21, 2024
7cfa77a
1. Update to reward function.
smihaylov-crystal Mar 22, 2024
65af791
Use pow() instead of exp2()
smihaylov-crystal Mar 22, 2024
e83a06d
Use smaller transaction size
smihaylov-crystal Mar 22, 2024
f1501d1
comment out action randomizing code
smihaylov-crystal Mar 22, 2024
41276ea
Refactor PG-specific logic outside of RL
smihaylov-crystal Mar 24, 2024
a5d5df9
Make sure autovacuum is disabled
smihaylov-crystal Mar 25, 2024
4e6562b
Tweaks
smihaylov-crystal Mar 25, 2024
a601c1d
Initial version of simulated autovacuum
smihaylov-crystal Mar 26, 2024
71d587d
tweaks and formatting
smihaylov-crystal Mar 26, 2024
9543084
autovac demo
smihaylov-crystal Mar 9, 2024
3cd3f1c
tweaks
smihaylov-crystal Mar 27, 2024
5be9dd1
Fix potential deadlock, tweaks to formatting
smihaylov-crystal Mar 27, 2024
833ef94
Log actions and stats
smihaylov-crystal Mar 27, 2024
be80391
Specify model name via command line
smihaylov-crystal Mar 27, 2024
3a899cd
During learning, apply vacuum before generating state and reward. Twe…
smihaylov-crystal Mar 28, 2024
00650da
Bump up rows_per_commit to 10000
smihaylov-crystal Mar 28, 2024
48d2a1d
Add ability to specify model file from command line
smihaylov-crystal Mar 28, 2024
f0f7c0c
Tweak to simulated tuples read
smihaylov-crystal Mar 30, 2024
07661a8
autovacuum CDF plots
jssmith Mar 11, 2024
5a93dd6
extend notebook to print multiple graphs
smihaylov-crystal Mar 31, 2024
aef10a5
Extend notebook to print vacuuming actions
smihaylov-crystal Mar 31, 2024
9988b9a
Use an input box to read results directory
smihaylov-crystal Mar 31, 2024
f964e22
Update with latest result
smihaylov-crystal Apr 1, 2024
8da1095
Add ability to specify experiment duration from command line
smihaylov-crystal Apr 1, 2024
fc8a10f
Tweak
smihaylov-crystal Apr 2, 2024
8a01767
Extend model tester
smihaylov-crystal Apr 3, 2024
6919d1d
Add ability to replay stats in order to re-train a new model quickly
smihaylov-crystal Apr 3, 2024
33aa1a8
Tweaks to environment state generation
smihaylov-crystal Apr 4, 2024
bd4b8f4
Refactoring to allow new workloads. (#1)
mdashti Apr 4, 2024
792ef36
Fixes
smihaylov-crystal Apr 4, 2024
f83e5a3
Fixes for simulated vacuum. Make more robust to reordering the queryi…
smihaylov-crystal Apr 5, 2024
50ef5ae
Tweaks
smihaylov-crystal Apr 5, 2024
6d937f9
Report every 10s. This avoids stalling the benchmark for too long wai…
smihaylov-crystal Apr 5, 2024
818d13d
Log time to complete experiment
smihaylov-crystal Apr 5, 2024
2c634b7
Update with latest experiment
smihaylov-crystal Apr 6, 2024
d40c916
Fix state during benchmarking
smihaylov-crystal Apr 6, 2024
517ede0
Tweak simulated perf. Fix comment. Reset stats before run.
smihaylov-crystal Apr 7, 2024
19ed450
Tweaks to simulated vacuum. Allow marginal unused space reclamation.
smihaylov-crystal Apr 7, 2024
c2ba4af
Rationalize internal percentage representation. Tweaks to state gener…
smihaylov-crystal Apr 8, 2024
4252b1d
Test basic cases as we are learning.
smihaylov-crystal Apr 8, 2024
33c0277
Undo changes, were not improving model
smihaylov-crystal Apr 9, 2024
472b68d
Update with latest result
smihaylov-crystal Apr 10, 2024
d92a671
Small tweaks. Slightly reduce vacuum penalty. Use 60s for vanilla aut…
smihaylov-crystal Apr 10, 2024
7db4bd4
Add a new graph to show number of completed queries
smihaylov-crystal Apr 10, 2024
a303792
Add support for deleting a fraction of the inserted tuples before beg…
smihaylov-crystal Apr 10, 2024
348e4ff
Allow testing for vacuum_buffer_usage_limit
smihaylov-crystal Apr 12, 2024
5ff1a69
Best results so far
smihaylov-crystal Apr 14, 2024
e43e332
Add animation
smihaylov-crystal Apr 16, 2024
096bda0
Extend model tester with real data.
smihaylov-crystal Apr 16, 2024
47ba5f6
Tweaks to animation
smihaylov-crystal Apr 16, 2024
01ecf28
Extend animation to display internal model state as text
smihaylov-crystal Apr 16, 2024
8de25a4
Extend animation to display internal model state as pixels
smihaylov-crystal Apr 17, 2024
f16ba55
Extend animation: better visualization for NN
smihaylov-crystal Apr 17, 2024
de717e1
Extend animation: add gauge
smihaylov-crystal Apr 18, 2024
2931275
Tweaks
smihaylov-crystal Apr 18, 2024
dc6da44
Add pruned notebook
smihaylov-crystal Apr 18, 2024
960d192
Improvements to model parameters, state, and simulated vacuum.
smihaylov-crystal Apr 26, 2024
9984b22
Factor out state representation
smihaylov-crystal Apr 26, 2024
8171f9e
Summarize history for step representation
smihaylov-crystal Apr 26, 2024
c09b90f
Make final rewards depend on duration of experiment.
smihaylov-crystal Apr 26, 2024
9610df8
Tweaks
smihaylov-crystal Apr 27, 2024
5d9feb6
Drop learning rate.
smihaylov-crystal Apr 27, 2024
cdc7c97
Tweaks
smihaylov-crystal Apr 27, 2024
7cbccba
1. Linear perf representation. 2. Asyc call to vacuuming.
smihaylov-crystal Apr 28, 2024
18ea28e
Change format for temp model saves
smihaylov-crystal Apr 28, 2024
c21be01
Record action in replay files.
smihaylov-crystal Apr 28, 2024
95a8dc1
Separate connection for vacuuming to support async
smihaylov-crystal Apr 28, 2024
c2d8222
Disable separate vacuum thread for now
smihaylov-crystal Apr 28, 2024
cd85bc0
Add connection lock
smihaylov-crystal Apr 28, 2024
50d18fc
Dedicated connection for vacuuming
smihaylov-crystal Apr 28, 2024
3f432dd
Disable
smihaylov-crystal Apr 28, 2024
3685fb2
Vacuuming in separate thread.
smihaylov-crystal Apr 28, 2024
25493b1
Restore checkpoint format. Needs more than the state dict.
smihaylov-crystal Apr 28, 2024
509ec73
Tweak rewards
smihaylov-crystal Apr 28, 2024
e39e271
Flush stdout
smihaylov-crystal Apr 28, 2024
d001ebf
Record vacuuming history in state instead of query perf
smihaylov-crystal Apr 28, 2024
34e7a4c
Tweak replay buffer sizes
smihaylov-crystal Apr 28, 2024
59786f7
* add ability to resume a model (finetune)
smihaylov-crystal Apr 29, 2024
8a0f620
Set correct experiment_id when finetuning a model
smihaylov-crystal Apr 30, 2024
f906063
Increment experiment_id via environment instead of via executors
smihaylov-crystal Apr 30, 2024
8a9cc09
* Make performance-based reward relative to 90th percentile
smihaylov-crystal May 2, 2024
426731a
Avoid NAN. Tweak learning params.
smihaylov-crystal May 2, 2024
db7bc06
Small refactor
smihaylov-crystal May 3, 2024
5cbd9a6
Refactor move finetuning logic inside agent
smihaylov-crystal May 3, 2024
f094a09
Make training optional
smihaylov-crystal May 3, 2024
ac930b3
Small refactor
smihaylov-crystal May 3, 2024
3d1f120
More appropriate class names
smihaylov-crystal May 3, 2024
462f625
Add PID agent
smihaylov-crystal May 3, 2024
6d5618d
Small fix for simulated free space
smihaylov-crystal May 4, 2024
00ead73
Fix asserts
smihaylov-crystal May 4, 2024
63a045c
Implement no-op agent with selectable default action.
smihaylov-crystal May 4, 2024
f837331
Decouple learning and benchmarking code from iibench.py
smihaylov-crystal May 4, 2024
a022c08
More work to decouple workload from pg_stat_and_vacuum.
smihaylov-crystal May 5, 2024
d55be79
Remove barrier from ibench code. Instead, use a query to establish wo…
smihaylov-crystal May 5, 2024
f636009
Remove unused script
smihaylov-crystal May 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 106 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
*.DS_Store

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
85 changes: 85 additions & 0 deletions bench/ibench/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# AutoDBA - Vacuum Reinforcement Learning Project

## Overview
This project aims to enhance the PostgreSQL AutoVacuum feature using reinforcement learning (RL) techniques. By integrating a custom RL model with PostgreSQL, we seek to optimize vacuuming decisions dynamically based on database activity, improving performance and resource utilization.

## Components
- `autovac_driver.py`: Main script for the reinforcement learning driver that interacts with the PostgreSQL AutoVacuum feature.
- `iibench_driver.py`: iibench workload to simulate database load and test the RL model's effectiveness.
- `learning/`: Directory containing the reinforcement learning model and training scripts.

## Requirements
- Python 3.8+
- PyTorch
- PostgreSQL

## Installation
Provide step-by-step instructions to set up the project:

1. Clone the repository:
```
git clone https://github.com/crystalcld/mytools
```
2. Navigate to the project directory:
```
cd bench/ibench
```
3. Install dependencies:
```
pip install -r requirements.txt
```

## Usage

The `autovac_driver.py` script is used to run the AutoVacuum reinforcement learning process. It supports various command-line arguments to control its behavior:

```bash
python autovac_driver.py - `--cmd [command] \
--max-episodes [max_episodes] \
--resume-id [resume_id] \
--experiment-duration [duration] \
--model-type [type] \
--model1-filename [filename1] \
--model2-filename [filename2] \
--instance-url [url] \
--instance-user [user] \
--instance-password [password] \
--instance-dbname [dbname]
```

Where:

- `--cmd`: The command to execute (benchmark or learn).
- `--max-episodes`: Maximum number of episodes for the experiment.
- `--resume-id`: Identifier to resume from a previous state.
- `--experiment-duration`: Duration of the experiment in seconds.
- `--model-type`: Type of the model (simulated or real).
- `--model1-filename`: Filename for the first model.
- `--model2-filename`: Filename for the second model.
- `--instance-url`: URL of the database instance.
- `--instance-user`: Database user.
- `--instance-password`: Database password.
- `--instance-dbname`: Database name.

Replace the bracketed terms with your actual values. For example, to start a learning session, you might use:

To run the `autovac_driver.py` script, you need to provide command line arguments for the mode and parameters. Here are the command structures for each mode:

### Learn Mode
```bash
python autovac_driver.py --cmd learn --max-episodes 100 --resume-id 0 --experiment-duration 120 --model-type simulated --model1-filename model1.pt --model2-filename model2.pt --instance-url localhost --instance-user user --instance-password pass --instance-dbname mydb
```

### Benchmark Mode
```bash
python autovac_driver.py --cmd benchmark --max-episodes 100 --resume-id 0 --experiment-duration 120 --model-type simulated --model1-filename model1.pt --model2-filename model2.pt --instance-url localhost --instance-user user --instance-password pass --instance-dbname mydb
```

Replace the bracketed terms with your actual values.

## Configuration
TODO

## License

This project is licensed under the MIT License.
Loading