Skip to content

Commit 481f368

Browse files
committed
feat: replace uwsgi with granian
1 parent c95b073 commit 481f368

17 files changed

Lines changed: 99 additions & 80 deletions

File tree

docs/configuration.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,10 @@ This defines the default version that will be pulled from all Open edX git repos
140140

141141
This defines the version that will be pulled from just the Open edX platform git repositories. You may also override this configuration parameter at build time, by providing a ``--build-arg`` option.
142142

143-
- ``OPENEDX_CMS_UWSGI_WORKERS`` (default: ``2``)
144-
- ``OPENEDX_LMS_UWSGI_WORKERS`` (default: ``2``)
143+
- ``OPENEDX_CMS_GRANIAN_WORKERS`` (default: ``2``)
144+
- ``OPENEDX_LMS_GRANIAN_WORKERS`` (default: ``2``)
145145

146-
By default, there are 2 `uwsgi worker processes <https://uwsgi-docs.readthedocs.io/en/latest/Options.html#processes>`__ to serve requests for the LMS and the CMS. However, each worker requires upwards of 500 Mb of RAM. You should reduce this value to 1 if your computer/server does not have enough memory.
146+
By default, there are 2 Granian worker processes to serve requests for the LMS and the CMS. You should reduce this value to 1 if your computer/server does not have enough memory. You can increase it when you need higher throughput, as long as CPU and memory resources are available.
147147

148148
- ``OPENEDX_CELERY_REDIS_DB`` (default: ``0``)
149149
- ``OPENEDX_CACHE_REDIS_DB`` (default: ``1``)

docs/local.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,9 @@ To update the course search index, run::
206206
Reloading Open edX settings
207207
~~~~~~~~~~~~~~~~~~~~~~~~~~~
208208

209-
After modifying Open edX settings, for instance when running ``tutor config save``, you will want to restart the web processes of the LMS and the CMS to take into account those new settings. It is possible to simply restart the whole platform (with ``tutor local reboot``) or just a single service (``tutor local restart lms``) but that is overkill. A quicker alternative is to send the HUP signal to the uwsgi processes running inside the containers. The "openedx" Docker image comes with a convenient script that does just that. To run it, execute::
209+
After modifying Open edX settings, for instance when running ``tutor config save``, you will want to restart the web processes of the LMS and the CMS to take into account those new settings. It is possible to simply restart the whole platform (with ``tutor local reboot``) or just a single service (``tutor local restart lms``) but that is overkill. A quicker alternative is to restart just the web server process running inside the containers. This can be done by updating a file in the granian's "--reload-paths" config. The "openedx" Docker image comes with a convenient script that does just that. To run it, execute::
210210

211-
tutor local exec lms reload-uwsgi
211+
tutor local exec lms reload-granian
212212

213213

214214
Customizing the deployed services

docs/reference/patches.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -390,13 +390,13 @@ File: ``apps/redis/redis.conf``
390390

391391
Implement this patch to override hard-coded Redis configuration values. See the `Redis configuration reference <https://redis.io/docs/management/config-file/>`__`.
392392

393-
``uwsgi-config``
393+
``granian-config``
394394
================
395395

396-
File: ``apps/openedx/settings/uwsgi.ini``
396+
File: ``apps/openedx/settings/granian-config``
397397

398-
A .INI formatted file used to extend or override the uWSGI configuration.
398+
A file used to extend or override the Granian configuration.
399399

400-
Check the uWSGI documentation for more details about the `.INI format <https://uwsgi-docs.readthedocs.io/en/latest/Configuration.html#ini-files>`__ and the `list of available options <https://uwsgi-docs.readthedocs.io/en/latest/Options.html>`__.
400+
Check the Granian documentation for the `list of available options <https://github.com/emmett-framework/granian>`__.
401401

402-
.. patch:: uwsgi-config
402+
.. patch:: granian-config

docs/tutorials/proxy.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Quite often, there is already a web proxy running on the host, and this web prox
1111

1212
With these changes, Tutor will no longer listen to ports 80 and 443 on the host. In this configuration, the Caddy container will only listen to port 81 on the host. Web requests will follow this path::
1313

14-
Client → Web proxy (http(s)://yourhost) → Caddy (0.0.0.0:81) → uwsgi (LMS/CMS/...)
14+
Client → Web proxy (http(s)://yourhost) → Caddy (0.0.0.0:81) → Granian (LMS/CMS/...)
1515

1616
.. warning::
1717
In this setup, the Caddy HTTP port (81) will be exposed to the world. Make sure to configure your server firewall to block unwanted connections to the Caddy container. Alternatively, you can configure the Caddy container to accept only local connections::

docs/tutorials/scale.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ Fortunately, Open edX was designed to run at scale -- most notably at `edX.org <
2323
Increasing web server capacity
2424
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2525

26-
As the server CPU and memory are increased, the request throughput can be increased by adjusting the number of uWSGI workers (see :ref:`configuration docs <openedx_configuration>`). By default, the "lms" and "cms" containers each spawn 2 uWSGI workers. The number of workers should be increased if you observe an increase in the latency of user requests but CPU usage remains below 100%. To increase the number of workers for the LMS and the CMS, run for example::
26+
As the server CPU and memory are increased, the request throughput can be increased by adjusting the number of Granian workers (see :ref:`configuration docs <openedx_configuration>`). By default, the "lms" and "cms" containers each spawn 2 Granian workers. The number of workers should be increased if you observe an increase in the latency of user requests but CPU usage remains below 100%. To increase the number of workers for the LMS and the CMS, run for example::
2727

2828
tutor config save \
29-
--set OPENEDX_LMS_UWSGI_WORKERS=8 \
30-
--set OPENEDX_CMS_UWSGI_WORKERS=4
29+
--set OPENEDX_LMS_GRANIAN_WORKERS=8 \
30+
--set OPENEDX_CMS_GRANIAN_WORKERS=4
3131
tutor local restart lms cms
3232

3333
The right values will very much depend on your server's available memory and CPU performance, as well as the maximum number of simultaneous users who use your platform. As an example data point, it was reported that a large Open edX platform can serve up to 500k unique users per week on a virtual server with 8 vCPU and 16 GB memory.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
{% include "build/openedx/settings/granian-config" %}
2+
{{ patch("granian-config") }}

tutor/templates/apps/openedx/uwsgi.ini

Lines changed: 0 additions & 3 deletions
This file was deleted.

tutor/templates/build/openedx/Dockerfile

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,10 @@ RUN --mount=type=cache,target=/openedx/.cache/pip,sharing=shared \
108108
# Use redis as a django cache https://pypi.org/project/django-redis/
109109
django-redis==5.4.0
110110

111-
# uwsgi server https://pypi.org/project/uWSGI/
112-
# We don't need xml configuration support in uwsgi so don't install it, as it causes
113-
# uwsgi to crash
114-
# https://github.com/xmlsec/python-xmlsec/issues/320
111+
# granian server https://pypi.org/project/granian/
112+
# We need the reload dependency so install it as well
115113
RUN --mount=type=cache,target=/openedx/.cache/pip,sharing=shared \
116-
UWSGI_PROFILE_OVERRIDE="xml=no" \
117-
pip install --no-cache-dir --compile uwsgi==2.0.24
114+
pip install --no-cache-dir --compile granian[reload]==2.6.0
118115

119116
# Install scorm xblock
120117
RUN pip install "openedx-scorm-xblock>=19.0.0,<20.0.0"
@@ -311,14 +308,18 @@ CMD ["./manage.py", "$SERVICE_VARIANT", "runserver", "0.0.0.0:8000"]
311308
###### Final image with production cmd
312309
FROM production AS final
313310

314-
# Default amount of uWSGI processes
315-
ENV UWSGI_WORKERS=2
311+
# Default amount of Granian worker processes
312+
ENV GRANIAN_WORKERS=2
316313

317-
# Copy the default uWSGI configuration
318-
COPY --chown=app:app settings/uwsgi.ini /openedx
314+
# Copy granian configuration file
315+
COPY --chown=app:app settings/granian-config /openedx
316+
317+
# Create the reload marker file
318+
RUN touch /openedx/granian-reload-path \
319+
&& chown app:app /openedx/granian-reload-path
319320

320321
# Run server
321-
CMD ["uwsgi", "/openedx/uwsgi.ini"]
322+
CMD ["run-granian"]
322323

323324
{{ patch("openedx-dockerfile-final") }}
324325

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#! /bin/bash
2+
echo "Reloading granian process..."
3+
date +%s > /openedx/.granian-reload-path

tutor/templates/build/openedx/bin/reload-uwsgi

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)