Show

Show

Show

blob-on-fire

TankieTube is suffering from success.

  • GaveUp [she/her]
    ·
    4 hours ago

    I devote exactly half of it to a nginx cache for the object storage. It caches for up to a year.

    I bet there's a ton of low hanging fruit optimizations to be done with the caching

    I couldn't find Nginxs replacement policy but I'm going to assume it's LRU like 99% of everything else

    Can I ask what your current caching strategy is? Like what/how things gets cached

    I.e. what types of files, if any custom settings like this file needs to be requested at least 5 times before nginx caches it (default is once), etc.

    • TankieTanuki [he/him]
      hexagon
      ·
      edit-2
      3 hours ago

      Yeah, it's doing last use. I'd love some protips!

      The files are all M3U8s and fragmented MP4s used for HTTP Live Streaming. I don't know how big the fragments are.

      Show

      Here is the whole config:

      spoiler
      proxy_cache_path /var/cache/peertube/s3 levels=1:2 keys_zone=CACHE-S3:400M inactive=1y max_size=1000G;
      
      server {
        listen      80;
        listen [::]:80;
        server_name medias.tankie.tube;
        location / { return 301 https://$host$request_uri; }
      }
      
      server {
        listen      443 ssl http2;
        listen [::]:443 ssl http2;
        server_name medias.tankie.tube;
      
        access_log /var/log/nginx/medias.peertube.access.log; # reduce I/0 with buffer=10m flush=5m
        error_log  /var/log/nginx/medias.peertube.error.log;
      
        ssl_protocols TLSv1.2 TLSv1.3;
        ssl_ciphers HIGH:!MEDIUM:!LOW:!aNULL:!NULL:!SHA;
        ssl_prefer_server_ciphers on;
        ssl_session_cache shared:SSL:10m;
        ssl_session_tickets off;
      
        keepalive_timeout 30;
      
        location = / {
          index index.html;
        }
      
        location / {
          try_files $uri @s3;
        }
      
        ##################################################################################
        ##################################################################################
        set $bucket_name 'tankie-tube';
        set $endpoint    's3.eu-central-003.backblazeb2.com';
        ##################################################################################
        ##################################################################################
        
        #set $s3_backend 'https://tankie-tube.s3.eu-central-003.backblazeb2.com';
        set $s3_fqdn ${bucket_name}.$endpoint;
        set $s3_backend https://$s3_fqdn;
      
        location @s3 {
          limit_except GET OPTIONS {
              deny all;
          }
      
          resolver 1.1.1.1 8.8.8.8 208.67.222.222 208.67.220.220;
          proxy_set_header Host $s3_fqdn;
          proxy_set_header Connection '';
          proxy_set_header Authorization '';
          proxy_set_header Range $slice_range;
          proxy_hide_header Set-Cookie;
          proxy_hide_header 'Access-Control-Allow-Origin';
          proxy_hide_header 'Access-Control-Allow-Methods';
          proxy_hide_header 'Access-Control-Allow-Headers';
          proxy_hide_header x-amz-id-2;
          proxy_hide_header x-amz-request-id;
          proxy_hide_header x-amz-meta-server-side-encryption;
          proxy_hide_header x-amz-server-side-encryption;
          proxy_hide_header x-amz-bucket-region;
          proxy_hide_header x-amzn-requestid;
          proxy_ignore_headers Set-Cookie;
          proxy_pass $s3_backend$uri;
          proxy_intercept_errors off;
          proxy_cache CACHE-S3;
      
          ##################################################################################
          ##################################################################################
          proxy_cache_valid 200 206 1y;
          ##################################################################################
          ##################################################################################
      
          proxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504;
          slice              1m;
          proxy_cache_key    $host$uri$is_args$args$slice_range;
          proxy_http_version 1.1;
      
          ##################################################################################
          ##################################################################################  
          expires 1y;
          ##################################################################################
          ##################################################################################
        
          add_header Cache-Control public;
          add_header 'Access-Control-Allow-Origin' '*';
          add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';
          add_header 'Access-Control-Allow-Headers' 'Range,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
          add_header X-Cache-Status $upstream_cache_status;
          add_header X-Content-Type-Options nosniff;
          add_header Content-Security-Policy "default-src 'none'; form-action 'none'";
        }
      
      }