Skip to content

Commit

Permalink
fix: high memory/cpu usage in dev
Browse files Browse the repository at this point in the history
In development, the tutor-mfe plugin runs a separate container for every
MFE. This runs `npm run start` for each of the 9 MFEs, which causes the
developer laptops to crash and ice caps to melt.

Here, we adopt a different solution. By default, all MFEs run in a
single container, which is the same as the production container (with
caddy). Only the Caddyfile is different. This effectively resolves the
performance issue.

But to allow developers to hack on invidual MFEs, we also need to run
some of them in development mode, with `npm run start`. To do that, we
run separately only those MFEs for which the developer has a
bind-mounted directory that corresponds to the MFE repository. This
allows developers to keep working on MFEs with the help of `tutor mounts
...` command.
  • Loading branch information
regisb committed Aug 3, 2023
1 parent 584d1e0 commit 0fc643f
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 10 deletions.
1 change: 1 addition & 0 deletions changelog.d/20230802_121750_regis_single_dev_container.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- [Improvement] Fix very high CPU and memory usage in development. We resolve this issue by running just a single container for all MFES, just like in production. To al;low developers to test their changes in Tutor, we run `npm run start` only for those MFEs that have a manual bind-mount that was created with `tutor mounts add .../frontend-app-mymfe`. (by @regisb)
5 changes: 0 additions & 5 deletions tutormfe/patches/caddyfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,5 @@
request_body {
max_size 2MB
}
reverse_proxy /api/mfe_config/v1* lms:8000 {
# We need to specify the host header, otherwise it will be rejected with 400
# from the lms.
header_up Host {{ LMS_HOST }}
}
import proxy "mfe:8002"
}
20 changes: 15 additions & 5 deletions tutormfe/patches/local-docker-compose-dev-services
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
# MFE apps
{% for app_name, app in iter_mfes() %}
{{ app_name }}:
mfe:
ports:
{%- for app_name, app in iter_mfes() %}
{%- if not iter_mounts(MOUNTS, app_name)|list %}
- {{ app["port"] }}:8002 # {{ app_name }}
{%- endif %}
{%- endfor %}

{%- for app_name, app in iter_mfes() %}
{%- set mounts = iter_mounts(MOUNTS, app_name)|list %}
{%- if mounts %}
{{ app_name }}: # Work on this MFE for development
image: "{{ DOCKER_REGISTRY }}overhangio/openedx-{{ app_name }}-dev:{{ MFE_VERSION }}"
ports:
- "{{ app["port"] }}:{{ app["port"] }}"
stdin_open: true
tty: true
volumes:
- ../plugins/mfe/apps/mfe/webpack.dev-tutor.config.js:/openedx/app/webpack.dev-tutor.config.js:ro
{%- for mount in iter_mounts(MOUNTS, app_name) %}
{%- for mount in mounts %}
- {{ mount }}
{%- endfor %}
restart: unless-stopped
depends_on:
- lms
{% endfor %}
{%- endif %}
{%- endfor %}
6 changes: 6 additions & 0 deletions tutormfe/templates/mfe/apps/mfe/Caddyfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
}
}

reverse_proxy /api/mfe_config/v1* lms:8000 {
# We need to specify the host header, otherwise it will be rejected with 400
# from the lms.
header_up Host {{ LMS_HOST }}
}

{% for app_name, app in iter_mfes() %}
@mfe_{{ app_name }} {
path /{{ app_name }} /{{ app_name }}/*
Expand Down

0 comments on commit 0fc643f

Please sign in to comment.