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

Document and stress test production deployment #50

Open
oplatek opened this issue Jul 16, 2024 · 5 comments
Open

Document and stress test production deployment #50

oplatek opened this issue Jul 16, 2024 · 5 comments
Assignees
Labels
documentation Improvements or additions to documentation enhancement New feature or request testing Testing, checks, asserts

Comments

@oplatek
Copy link
Member

oplatek commented Jul 16, 2024

I just tested on localhost without (without host_prefix)

gunicorn -w 1 --threads 10 'factgenie.cli:create_app()' --bind 127.0.0.1:11111 on commit 76ab57c

But we should test it thoroughly and then add it to README.
We should include a version of gunicorn, which we use.

@oplatek oplatek added documentation Improvements or additions to documentation enhancement New feature or request labels Jul 16, 2024
@dmhowcroft
Copy link
Contributor

I'm using Docker Compose to launch the server behind an nginx reverse proxy.

One level up from factgenie repo root, I have the following docker-compose.yml

services:
  factgenie:
    container_name: factgenie
    image: factgenie
    restart: on-failure
    ports:
      - 8080:80
    build: ./factgenie

In the factgenie repo root I added this Dockerfile:

FROM python:3.10

RUN mkdir -p /usr/src/factgenie
WORKDIR /usr/src/factgenie

COPY . /usr/src/factgenie

RUN pip install -e .

EXPOSE 80
ENTRYPOINT ["gunicorn", "-b", ":80", "-w", "1", "--threads", "2", "factgenie.cli:create_app"]

The docker compose file ensures that the gunicorn server running on port 80 inside docker is exposed at localhost:8080, which is where nginx expects to find it when forwarding traffic.

When running wget localhost:8080 or loading DOMAIN.TLD/MY_HOST_PREFIX in a browser, I get the following error:

factgenie  | [2024-07-16 12:06:48 +0000] [6] [ERROR] Error handling request /MY_HOST_PREFIX/
factgenie  | Traceback (most recent call last):
factgenie  |   File "/usr/local/lib/python3.10/site-packages/gunicorn/workers/gthread.py", line 282, in handle
factgenie  |     keepalive = self.handle_request(req, conn)
factgenie  |   File "/usr/local/lib/python3.10/site-packages/gunicorn/workers/gthread.py", line 334, in handle_request
factgenie  |     respiter = self.wsgi(environ, resp.start_response)
factgenie  | TypeError: create_app() takes 0 positional arguments but 2 were given

@oplatek
Copy link
Member Author

oplatek commented Jul 16, 2024

@dmhowcroft I test it without prefix on a local setup on latest commit just to be sure.

##### First terminal - in the factgenie root repo
$ gunicorn -w 1 --threads 2 'factgenie.cli:create_app()' --bind 127.0.0.1:8080
2024-07-16 14:29:04 +0200] [55374] [INFO] Starting gunicorn 22.0.0
[2024-07-16 14:29:04 +0200] [55374] [INFO] Listening at: http://127.0.0.1:8080 (55374)
[2024-07-16 14:29:04 +0200] [55374] [INFO] Using worker: gthread
[2024-07-16 14:29:04 +0200] [55375] [INFO] Booting worker with pid: 55375
2024-07-16 14:29:12 INFO Application ready
2024-07-16 14:31:15 INFO Main page loaded
##### Second terminal
$ wget localhost:8080
--2024-07-16 14:31:15--  http://localhost:8080/
Resolving localhost (localhost)... ::1, 127.0.0.1
Connecting to localhost (localhost)|::1|:8080... failed: Connection refused.
Connecting to localhost (localhost)|127.0.0.1|:8080... connected.
HTTP request sent, awaiting response... 200 OK
Length: 3447 (3.4K) [text/html]
Saving to: ‘index.html’

index.html                                     100%[=================================================================================================>]   3.37K  --.-KB/s    in 0s      

2024-07-16 14:31:15 (365 MB/s) - ‘index.html’ saved [3447/3447]

My version used:

  • On factgenie commit 64c54e5
  • python -V # Python 3.11.5 (I believe anything 3.7+ is fine)
  • gunicorn (version 22.0.0)

I have tested it with a prefix and reproduced your bug. See #51

@oplatek
Copy link
Member Author

oplatek commented Aug 29, 2024

FYI @kasnerz:
Find below how I document my setup for deployment. Should we add it to the wiki?

ATM I am starting at ufal factgenie with the following config using gunicorn using this script.
The factgenie is installed via pip install -e .[dev,deploy] into virtualenv.

factgenie/config.yml

---
debug: false
host_prefix: "/demo/factgenie"
logging_level: INFO
login:
  active: true
  username: MASKED_OUT
  password: MASKED_OUT

I run this gunicorn.sh script from the factgenie root dir

#!/bin/bash
# Section in the `/etc/nginx/sites-available/default`
#
# ```
#     # factgenie
#     rewrite ^/factgenie/(.*)/$ /demo/factgenie/$1 permanent;
#     location /factgenie {
#         proxy_pass http://localhost:5000/;
#     }
#     location /factgenie/ {
#         proxy_pass http://localhost:5000/;
#     }
#     # end of factgenie
# ```
gunicorn -w 1 --threads 2 'factgenie.cli:create_app()' --bind 127.0.0.1:5000

@kasnerz
Copy link
Collaborator

kasnerz commented Sep 10, 2024

@oplatek You should definitely document how to use dev and deploy arguments for pip - I don't think that's documented anywhere.

It will also be useful to show the gunicorn command for deployment.

Regarding nginx configuration, I think that's quite specific to our setup, so writing specific commands might confuse users that copy-paste it and expect it to work.

@oplatek
Copy link
Member Author

oplatek commented Sep 10, 2024

I will document how I deploy it in case where no host_prefix is needed and then I will compare it with the setup where host_prefix is needed.
I will document it using nginx and gunicorn tools.

@kasnerz kasnerz added the testing Testing, checks, asserts label Oct 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request testing Testing, checks, asserts
Projects
None yet
Development

No branches or pull requests

3 participants