Chocobozzz / PeerTube

ActivityPub-federated video streaming platform using P2P directly in your web browser
https://joinpeertube.org/
GNU Affero General Public License v3.0
13.1k stars 1.51k forks source link

Add Varnish as part of install process, because it improves performance #2796

Closed McFlat closed 4 years ago

McFlat commented 4 years ago

What happened? Website gets very slow when hard drives waiting to write, when using ZFS it can slow it down while txg_sync What do you expect to happen instead? I expect the website to be responsive at all times not get slow. Installing Varnish helped to speed up the website

Steps to reproduce: https://github.com/Chocobozzz/PeerTube/pull/2798 https://github.com/Chocobozzz/PeerTube/pull/2799

  1. Install and configure varnish apt install varnish

  2. Edit Varnish configuration files

nano /etc/default/varnish

DAEMON_OPTS="-a :6081 \
             -T localhost:6082 \
             -f /etc/varnish/default.vcl \
             -S /etc/varnish/secret \
             -s malloc,1G"

nano /etc/varnish/default.vcl

backend default {
    .host = "127.0.0.1";
    .port = "8888";
}
  1. Configure varnish in front of peertube and terminated by SSL (insert this before and after the SNIP HERE marks) Let images and other static resource go through varnish in memory cache to make website faster. nano /etc/nginx/sites-available/peertube
... SNIP HERE ...
  location ^~ '/.well-known/acme-challenge' {
    default_type "text/plain";
    root /var/www/certbot;
  }
  location / {
    proxy_pass http://127.0.0.1:6081;
    proxy_set_header X-Real-IP  $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto https;
    proxy_set_header X-Forwarded-Port 443;
    proxy_set_header Host $host;

    client_max_body_size 12G;

    proxy_connect_timeout       600;
    proxy_send_timeout          600;
    proxy_read_timeout          600;
    send_timeout                600;
  }
  # Websocket tracker
  location /tracker/socket {
    # Peers send a message to the tracker every 15 minutes
    # Don't close the websocket before this time
    proxy_read_timeout 1200s;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_http_version 1.1;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $host;
    proxy_pass http://127.0.0.1:9000;
  }

  location /socket.io {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $host;

    proxy_pass http://127.0.0.1:9000; 

    # enable WebSockets
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
  }
}

server {
  listen 8888;

  # Bypass PeerTube for performance reasons. Could be removed
  location ~ ^/client/(.*\.(js|css|png|svg|woff2|otf|ttf|woff|eot))$ {
    add_header Cache-Control "public, max-age=31536000, immutable";

    alias /var/www/peertube/peertube-latest/client/dist/$1;
  }
... SNIP HERE ...

Additional information

Chocobozzz commented 4 years ago

Please add this documentation on https://docs.joinpeertube.org/#/maintain-configuration (https://framagit.org/framasoft/peertube/documentation/)