Skip to content

Commit

Permalink
Merge pull request #345 from codeforIATI/readme-profiling
Browse files Browse the repository at this point in the history
Vagrant: Add Python Profiling & Postgres logging instructions
  • Loading branch information
odscjames authored Mar 15, 2022
2 parents 1ed31d0 + 74e6784 commit 90c15e0
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
59 changes: 59 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,65 @@ iati crawler status
# A local API is available at: http://127.0.0.1:5000
```

### Python Profiling

If you want to profile some of the code, follow these additional instructions:

Edit `iati_datastore/iatilib/frontend/app.py`, and add an import and change the return of `create_app` (Do not check these changes in!):

```
from werkzeug.middleware.profiler import ProfilerMiddleware
def create_app(config_object='iatilib.config.Config'):
... as usual ....
return ProfilerMiddleware(app, profile_dir='/vagrant/profiles')
```

Run:

```
mkdir -p profiles
pip install snakeviz
iati run --host 0.0.0.0
```

In another window run:

```
snakeviz -H 0.0.0.0 -p 5555 -s /vagrant/profiles/
```

Go to a URL as normal.

You should see files appear in the `profiles` directory.

Go to http://127.0.0.1:5555/snakeviz/%2Fvagrant%2Fprofiles and you can browse them with pretty graphs.

To turn this off, just undo your changes to `iati_datastore/iatilib/frontend/app.py`.

### Database Logging

As root, create and edit the file `/etc/postgresql/12/main/conf.d/log.conf` and put in:

```
log_min_duration_statement = 0
```

Restart Postgres:

```
sudo /etc/init.d/postgresql restart
```

Open a new window and see queries made as other tasks are carried out:

```
sudo tail -f /var/log/postgresql/postgresql-12-main.log
```

Note if you do something like a data import this will include A LOT of queries - make sure you turn this off when you don't need this any more!

To turn this off, just delete the config file you created and restart postgres again.

Deploying with nginx
--------------------
Expand Down
2 changes: 1 addition & 1 deletion Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Vagrant.configure(2) do |config|
app.vm.box = "ubuntu/focal64"

app.vm.network "forwarded_port", guest: 5000, host: 5000

app.vm.network "forwarded_port", guest: 5555, host: 5555

app.vm.synced_folder ".", "/vagrant", :owner=> 'ubuntu', :group=>'users', :mount_options => ['dmode=777', 'fmode=777']

Expand Down

0 comments on commit 90c15e0

Please sign in to comment.