From d1a1992ced7f6c998a2f101f4aab773f10d7b8de Mon Sep 17 00:00:00 2001 From: David Kennedy Date: Wed, 6 Mar 2024 07:07:00 -0500 Subject: [PATCH 1/4] dbcache and multiple gunicorn workers --- src/registrar/config/settings.py | 11 ++++++----- src/run.sh | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/registrar/config/settings.py b/src/registrar/config/settings.py index 3107661b9..18b680e0d 100644 --- a/src/registrar/config/settings.py +++ b/src/registrar/config/settings.py @@ -192,11 +192,12 @@ WSGI_APPLICATION = "registrar.config.wsgi.application" # For a low to medium traffic site, caching causes more # problems than it solves. Should caching be desired, # a reasonable start might be: -# CACHES = { -# "default": { -# "BACKEND": "django.core.cache.backends.db.DatabaseCache", -# } -# } +CACHES = { + "default": { + "BACKEND": "django.core.cache.backends.db.DatabaseCache", + "LOCATION": "cache_table", + } +} # Absolute path to the directory where `collectstatic` # will place static files for deployment. diff --git a/src/run.sh b/src/run.sh index 1d35cd617..0228f143f 100755 --- a/src/run.sh +++ b/src/run.sh @@ -6,4 +6,4 @@ set -o pipefail # Make sure that django's `collectstatic` has been run locally before pushing up to any environment, # so that the styles and static assets to show up correctly on any environment. -gunicorn --worker-class=gevent registrar.config.wsgi -t 60 +gunicorn --workers=3 --worker-class=gevent registrar.config.wsgi -t 60 From e3e8c2646b68ef4448af02ceafa88546713bd258 Mon Sep 17 00:00:00 2001 From: David Kennedy Date: Wed, 6 Mar 2024 11:54:34 -0500 Subject: [PATCH 2/4] added createcachetable to docker-compose --- src/docker-compose.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/src/docker-compose.yml b/src/docker-compose.yml index fdf069f56..2e4ecaae5 100644 --- a/src/docker-compose.yml +++ b/src/docker-compose.yml @@ -66,6 +66,7 @@ services: command: > bash -c " python manage.py migrate && python manage.py load && + python manage.py createcachetable && python manage.py runserver 0.0.0.0:8080" db: From b33d71ee541d35c0d1905542c235e1947a686291 Mon Sep 17 00:00:00 2001 From: David Kennedy Date: Wed, 6 Mar 2024 12:13:18 -0500 Subject: [PATCH 3/4] new createcachetable.yaml script, updated create_dev_sandbox.sh --- .github/workflows/createcachetable.yaml | 46 +++++++++++++++++++++++++ ops/scripts/create_dev_sandbox.sh | 3 ++ 2 files changed, 49 insertions(+) create mode 100644 .github/workflows/createcachetable.yaml diff --git a/.github/workflows/createcachetable.yaml b/.github/workflows/createcachetable.yaml new file mode 100644 index 000000000..8fa4d76c8 --- /dev/null +++ b/.github/workflows/createcachetable.yaml @@ -0,0 +1,46 @@ +# This workflow can be run from the CLI for any environment +# gh workflow run createcachetable.yaml -f environment=ENVIRONMENT +# OR +# cf run-task getgov-ENVIRONMENT --command 'python manage.py createcachetable' --name createcachetable + +name: Create cache table +run-name: Create cache table for ${{ github.event.inputs.environment }} + +on: + workflow_dispatch: + inputs: + environment: + type: choice + description: Which environment should we create cache table for? + options: + - stable + - staging + - development + - backup + - ky + - es + - nl + - rh + - za + - gd + - rb + - ko + - ab + - rjm + - dk + +jobs: + createcachetable: + runs-on: ubuntu-latest + env: + CF_USERNAME: CF_${{ github.event.inputs.environment }}_USERNAME + CF_PASSWORD: CF_${{ github.event.inputs.environment }}_PASSWORD + steps: + - name: Create cache table for ${{ github.event.inputs.environment }} + uses: cloud-gov/cg-cli-tools@main + with: + cf_username: ${{ secrets[env.CF_USERNAME] }} + cf_password: ${{ secrets[env.CF_PASSWORD] }} + cf_org: cisa-dotgov + cf_space: ${{ github.event.inputs.environment }} + cf_command: "run-task getgov-${{ github.event.inputs.environment }} --command 'python manage.py createcachetable' --name createcachetable" diff --git a/ops/scripts/create_dev_sandbox.sh b/ops/scripts/create_dev_sandbox.sh index c9c55ae29..676fcf7ae 100755 --- a/ops/scripts/create_dev_sandbox.sh +++ b/ops/scripts/create_dev_sandbox.sh @@ -90,6 +90,9 @@ cd src/ cd .. cf push getgov-$1 -f ops/manifests/manifest-$1.yaml +echo "Creating cache table..." +cf run-task getgov-$1 --command 'python manage.py createcachetable' --name createcachetable + read -p "Please provide the email of the space developer: " -r cf set-space-role $REPLY cisa-dotgov $1 SpaceDeveloper From 83800b6a65e2005b795048aca954b01c1a841234 Mon Sep 17 00:00:00 2001 From: David Kennedy Date: Thu, 7 Mar 2024 08:51:43 -0500 Subject: [PATCH 4/4] updated comments in settings.py --- src/registrar/config/settings.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/registrar/config/settings.py b/src/registrar/config/settings.py index 18b680e0d..15799f91b 100644 --- a/src/registrar/config/settings.py +++ b/src/registrar/config/settings.py @@ -188,10 +188,6 @@ WSGI_APPLICATION = "registrar.config.wsgi.application" # https://docs.djangoproject.com/en/4.0/howto/static-files/ -# Caching is disabled by default. -# For a low to medium traffic site, caching causes more -# problems than it solves. Should caching be desired, -# a reasonable start might be: CACHES = { "default": { "BACKEND": "django.core.cache.backends.db.DatabaseCache",