Video of loading time for a simple table: https://youtu.be/OAGiCmtqmPg
The page will load very slow but all that is being returned is a large amount of text. The text is in a table and the table loads row by row. It’s so slow that each cell of the table can be seen loading individually. This is not happening on my local development machine. However, it is occurring on two roughly identical Ubunutu virtual machines online. The issue occurs in both Chrome and Firefox.
uname -a:
Linux ml 5.4.0-48-generic #52-Ubuntu SMP Thu Sep 10 10:58:49 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
docker-compose.yaml:
version: '3'
services:
db:
container_name: postgresdb
image: postgres:latest
restart: always
env_file:
- project.env
ports:
- 5432:5432
volumes:
- postgres-data1:/var/lib/postgresql/data1
plumber:
build: ./rplumber/
command: /app/plumber.R
restart: always
env_file:
- project.env
ports:
- 7002:8000
volumes:
- ./rplumber:/app
web:
container_name: django
build: maldidb/
command: >
gunicorn soMedia.wsgi:application --bind 0.0.0.0:8000 --workers=4 --timeout 1000
env_file:
- project.env
expose:
- 8000
depends_on:
- db
- plumber
volumes:
- staticfiles:/home/app/web/static/
- /home/ubuntu/r01data:/home/app/r01data/
nginx:
container_name: nginx
image: nginx:mainline-alpine
restart: always
ports:
- 80:80
volumes:
- ./nginx:/etc/nginx/conf.d
- staticfiles:/home/app/web/static/
depends_on:
- web
- db
- plumber
volumes:
postgres-data1:
staticfiles:
nginx.conf:
upstream djangoapp {
server django:8000;
}
server {
listen 80;
listen [::]:80;
location / {
proxy_pass http://djangoapp;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_redirect off;
}
location /static/ {
alias /home/app/web/static/;
}
}
There is also a warning occurring which I’ve tried to fix using various suggestions from others’ posts (nginx.conf) with no success. The warning is:
nginx | 2021/02/20 17:25:01 [warn] 20#20: *13 an upstream response is buffered to a temporary file /var/cache/nginx/proxy_temp/2/00/0000000002 while reading upstream, client: <remote IP>, server: , request: "GET /spectra/ HTTP/1.1", upstream: "http://<server?>:8000/spectra/", host: "<server>", referrer: "http://<server>/cosine/"
As a test, if I output 1MB of plain text from a template in Django, the response loads in chunks and finishes in about 60 seconds. If instead I download the outputted HTML and then open it locally from the file system, then the page full of text loads immediately with no delays. I can change this to a 12MB file and it takes longer. Running htop
on the server during this loading period shows nothing out of the ordinary–a lot of free memory, no processes running above 1% CPU, all CPUs free. In the meantime, the browser that I’m running is using 100% CPU while loading the page!
Output of sysctl fs.file-nr
while the page is loading:
$ sysctl fs.file-nr
fs.file-nr = 1728 0 9223372036854775807
Saving the 12MB file and then opening it locally returns the page almost immediately. Loading the page on the server took roughly 10 minutes.
$ cat /etc/hosts
127.0.0.1 localhost
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
Speed test from the server matches speed test from within the containers, with no issues for either:
$ curl -o nul http://speedtest.dallas.linode.com/100MB-dallas.bin
100 100M 100 100M 0 0 5.7M 0 0:00:11 0:00:11 --:--:-- 5.7M
Changing nginx docker image also has no effect on loading times:
nginx:
image: nginx
docker stats does not seem to show anything out of the ordinary:
Perhaps there is a way to measure speed between the containers and check for a slow connection there?
Changing Django versions, from 3.1 to 2.2, also has no effect on loading times.
One other oddity. When building the R image, within R there are a number of small downloads that take place. I noticed that these downloads are ridiculously slow. Conversely, installing the same packages locally results in normally fast downloads. This is the only place in the containers, other than page load times, where I’ve notice an unusually slow connection.