Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Profile app with py-spy #16

Merged
merged 3 commits into from
Sep 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 9 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ build:
docker-compose build

up:
docker-compose up -d api db
docker-compose up -d
make migrate-up

start:
docker-compose start api db
docker-compose start

stop:
docker-compose stop
Expand All @@ -52,14 +52,17 @@ logs:
shell: ## Shell into web container
docker-compose exec api bash

shell-root: # Shell into web container as root
docker-compose exec -u root api bash
shell-db: ## Shell into postgres process inside db container
docker-compose exec db psql -w --username "sivdev_user" --dbname "sivdev"

shell-ipython: ## Shell into ipython with falcon context
docker-compose exec api python /app/scripts/ipython_shell.py

shell-db: ## Shell into postgres process inside db container
docker-compose exec db psql -w --username "sivdev_user" --dbname "sivdev"
shell-profiler:
docker-compose exec profiler bash

shell-root: # Shell into web container as root
docker-compose exec -u root api bash

migration: ## Create migrations using alembic
docker-compose exec api alembic revision --autogenerate -m "$(m)"
Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,17 @@ Movie.search("top gun", page=1, per_page=5)
* Remove database from request before sending response
* Migrations with [Alembic](http://alembic.zzzcomputing.com/en/latest/)

### Profiler

* Attach [py-spy](https://github.com/benfred/py-spy) to Python process to profile
* Connect to Gunicorn process to profile web application
* [Gunicorn architecture](http://docs.gunicorn.org/en/stable/design.html)

```console
USAGE:
py-spy --duration <duration> --pid <pid> --rate <rate>
```

### Testing

* [pytest](https://docs.pytest.org/en/latest/)
Expand Down
18 changes: 16 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ services:
api:
build:
context: .
dockerfile: ./docker/Dockerfile
command: ["gunicorn", "app:api", "-b", "0.0.0.0:7000", "--reload", "--timeout", "100000"]
environment:
API_URL: http://api:7000
Expand Down Expand Up @@ -75,7 +76,7 @@ services:
# task queue
rq-dash:
build:
context: ./scripts/rq-dashboard/
context: ./docker/rq-dashboard/
environment:
RQ_DASHBOARD_REDIS_URL: redis://redis:6379
depends_on:
Expand All @@ -85,7 +86,7 @@ services:
command: ["rq-dashboard"]
rq-scheduler:
build:
context: ./scripts/rq-scheduler/
context: ./docker/rq-scheduler/
environment:
RQ_REDIS_HOST: redis
RQ_REDIS_PORT: 6379
Expand All @@ -95,6 +96,7 @@ services:
worker:
build:
context: .
dockerfile: ./docker/Dockerfile
environment:
GMAIL_ADDRESS: $GMAIL_ADDRESS
GMAIL_APPLICATION_PASSWORD: $GMAIL_APPLICATION_PASSWORD
Expand All @@ -112,3 +114,15 @@ services:
- elasticsearch
ports:
- "5601:5601"

# dev tools
profiler:
build:
context: ./docker/py-spy/
pid: "service:api"
cap_add:
- SYS_PTRACE
volumes:
- ./docker/py-spy/flame-graphs:/flame-graphs
stdin_open: true
tty: true
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting stdin_open and tty prevents containers from exiting when loading via Docker-Compose.

File renamed without changes.
3 changes: 3 additions & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Docker Images

Supporting materials required to make Docker images for webapp.
5 changes: 5 additions & 0 deletions docker/py-spy/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM python:3.7.0-stretch

RUN pip install py-spy

CMD ["python"]
File renamed without changes.
File renamed without changes.