Skip to content

Commit

Permalink
♻️(tray) split websocket and asgi apps in tray
Browse files Browse the repository at this point in the history
We have detected a memory leak in the websocket application. An issue
exists on the django channels github repo about this topic.
We also detected that this memory leak can have side effect on the asgi
application, the application can become slower leading to timeout. To
remove this side effect we decided to create a deploy dedicated to the
websocket application and nginx is reponsible to use the right backend
based on the request path.

django/channels#2094
  • Loading branch information
lunika committed Oct 3, 2024
1 parent 8161193 commit 7692832
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ Versioning](https://semver.org/spec/v2.0.0.html).

- Add peertube transcript generation

### Changed

- Split websocket and asgi apps in tray

### Fixed

- Allow to change username if one is persisted on classroom join
Expand Down
29 changes: 29 additions & 0 deletions src/tray/templates/services/app/deploy_ws.yml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{% set service_variant = "ws" %}
{% set marsha_replicas = marsha_ws_replicas %}
{% set marsha_livenessprobe = {
"httpGet": {
"path": "/__heartbeat__",
"port": "django-port",
"httpHeaders": [{
"name": "Host",
"value": marsha_hosts[0],
}],
},
"initialDelaySeconds": 60,
"periodSeconds": 30 ,
} %}
{% set marsha_readynessprobe = {
"httpGet": {
"path": "/__lbheartbeat__",
"port": "django-port",
"httpHeaders": [{
"name": "Host",
"value": marsha_hosts[0],
}],
},
"initialDelaySeconds": 10,
"periodSeconds": 5,
} %}
{% set marsha_resources = marsha_ws_resources %}

{% include "./_deploy_base.yml.j2" with context %}
20 changes: 20 additions & 0 deletions src/tray/templates/services/app/svc_ws.yml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
apiVersion: v1
kind: Service
metadata:
labels:
app: marsha
service: ws
version: "{{ marsha_image_tag }}"
deployment_stamp: "{{ deployment_stamp }}"
name: marsha-ws-{{ deployment_stamp }} # name of the service should be host name in nginx
namespace: "{{ namespace_name }}"
spec:
ports:
- name: {{ marsha_django_port }}-tcp
port: {{ marsha_django_port }}
protocol: TCP
targetPort: {{ marsha_django_port }}
selector:
app: marsha
deployment: "marsha-ws-{{ deployment_stamp }}"
type: ClusterIP
6 changes: 5 additions & 1 deletion src/tray/templates/services/nginx/configs/marsha.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ upstream marsha-backend {
server marsha-app-{{ deployment_stamp }}:{{ marsha_django_port }} fail_timeout=0;
}

upstream marsha-ws {
server marsha-ws-{{ deployment_stamp }}:{{ marsha_django_port }} fail_timeout=0;
}

upstream marsha-xapi {
server marsha-xapi-{{ deployment_stamp }}:{{ marsha_django_port }} fail_timeout=0;
}
Expand Down Expand Up @@ -62,7 +66,7 @@ server {
}

location /ws/ {
proxy_pass http://marsha-backend;
proxy_pass http://marsha-ws;

proxy_http_version 1.1;
proxy_set_header Connection "Upgrade";
Expand Down
9 changes: 9 additions & 0 deletions src/tray/vars/all/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ marsha_image_name: "fundocker/marsha"
marsha_image_tag: "3.23.0"
marsha_django_port: 8000
marsha_app_replicas: 1
marsha_ws_replicas: 1
marsha_xapi_replicas: 1
marsha_celery_replicas: 1
marsha_django_configuration: "Development"
Expand Down Expand Up @@ -123,6 +124,14 @@ marsha_app_resources:
cpu: 0.8
memory: 1Gi

marsha_ws_resources:
requests:
cpu: 0.3
memory: 500Mi
limits:
cpu: 0.8
memory: 1Gi

marsha_xapi_resources:
requests:
cpu: 0.3
Expand Down

0 comments on commit 7692832

Please sign in to comment.