Want more timely Centmin Mod News Updates?
Become a Member

Beta Branch revert ngx_brotli auto enable for intel skylake cpus in 123.09beta01

Discussion in 'Centmin Mod Github Commits' started by eva2000, Feb 21, 2019.

  1. eva2000

    eva2000 Administrator Staff Member

    41,386
    9,297
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +14,261
    Local Time:
    3:39 PM
    Nginx 1.17.x
    MariaDB 5.5/10.x
    revert ngx_brotli auto enable for intel skylake cpus in 123.09beta01

    - Previously auto enabled ngx_brotli when intel skylake cpus were detected https://community.centminmod.com/th...tel-skylake-newer-cpus-in-123-09beta01.16553/ but that was under a flawed assumption that intel skylake cpus accelerated broti compressed http requests compared to gzip compressed http requests. The acceleration didn't come from intel skylake cpus but from an ngx_brotli configuration setting update did at https://community.centminmod.com/th...iles-greater-than-64kb-in-123-09beta01.15951/ which changed brotli_min_length from 1000 to 65536 bytes so that Brotli compression is only used for files greater than 64KB when NGXDYNAMIC_BROTLI='y' and NGINX_LIBBROTLI='y' set https://community.centminmod.com/threads/nginx-config-suggestions.15950/#post-68317. The incorrect assumption was that brotli_min_length from 1000 to 65536 bytes change would switch to gzip compression if file was under 65536 bytes in length and only brotli compress files greater than 65536 bytes. When in fact what happens is that any files under 65536 bytes will end up without any form of compression and not switch back to gzip. So when you test brotli encoded requests for files under 65536 bytes, ngx_brotli serves them uncompressed instead of the flawed assumption that it will fallback to gzip. This meant that benchmarks on intel skylake cpus which happen to test files less than 65536 bytes ended up serving the file uncompressed which meant it's performance was better than compared gzip compressed encoded http requests for the same file.
    - When brotli_min_length was changed back from 65536 bytes to 1400 bytes, then files under 65536 bytes and over 1400 bytes were then properly brotli compressed for brotli encoded http requests were made. However, the performance throughput was about 1/5th of gzip compressed performance in terms of requests/s throughput for on the fly dynamic brotli vs gzip.
    - As such this commit update corrects some of the incorrect assumptions by first changing brotli_min_length back from 65536 bytes to 1400 bytes so that files under 65536 are properly brotli compressed again instead being served uncompressed and leaves ngx_brotli enabling up to end user to optionally enable again https://community.centminmod.com/th...sion-for-centmin-mod-nginx-web-servers.10688/ and disables ngx_brotli by default otherwise.
    - You can always reduce the brotli compression level default from 5 to 4 by manually editing the settings in /usr/local/nginx/conf/brotli_inc.conf and restart nginx service to improve brotli requests/s throughput by ~90%. This comparatively improves brotli on the fly compression throughput performance in terms of requests/s from 1/5th the speed of gzip to 1/4th the speed of gzip. So brotli on the fly performance is still slower than gzip but still improved. However, resulting brotli compressed files maybe slightly larger in some instances than gzip compressed file as seen below for jquery file bit larger but index.html bit smaller compressed file.
    - What about brotli vs gzip on the fly compressed file size differences ? Below are tests done against Centmin Mod default index.html page and jquery file via my custom curltest command which tests both the gzip and brotli encoded http request for each respective file

    with brotli previous default of level 5 compression and brotli_min_length 65536 bytes

    for index.html - notice brotli encoded request served the compressed version as uncompressed due to brotli_min_length 65536 bytes - that is where intel skylake cpu benchmarks got that accelerated performance as the request was not compressed at all !
    Code (Text):
    curltest gzip http://localhost/
    URI: http://localhost/ (gzip)
    Uncompressed size : 4.40 KiB
    Compressed size   : 1.81 KiB
    
    curltest br http://localhost/
    URI: http://localhost/ (br)
    Uncompressed size : 4.40 KiB
    Compressed size   : 4.40 KiB
    

    for jquery - notice now the brotli encoded request was served compresed due to brotli_min_length 65536 bytes and that the file is greater than 65536 bytes at 84.88KB uncompressed so that activated ngx_brotli on the fly compression
    Code (Text):
    curltest gzip http://localhost/jquery-3.3.1.min.js
    URI: http://localhost/jquery-3.3.1.min.js (gzip)
    Uncompressed size : 84.88 KiB
    Compressed size   : 29.75 KiB
    
    curltest br http://localhost/jquery-3.3.1.min.js
    URI: http://localhost/jquery-3.3.1.min.js (br)
    Uncompressed size : 84.88 KiB
    Compressed size   : 29.01 KiB
    

    now with brotli default of level 4 compression and brotli_min_length 1400 bytes

    for index.html
    Code (Text):
    curltest gzip http://localhost/
    URI: http://localhost/ (gzip)
    Uncompressed size : 4.40 KiB
    Compressed size   : 1.81 KiB
    
    curltest br http://localhost/
    URI: http://localhost/ (br)
    Uncompressed size : 4.40 KiB
    Compressed size   : 1.65 KiB
    

    for jquery file
    Code (Text):
    curltest gzip http://localhost/jquery-3.3.1.min.js
    URI: http://localhost/jquery-3.3.1.min.js (gzip)
    Uncompressed size : 84.88 KiB
    Compressed size   : 29.75 KiB
    
    curltest br http://localhost/jquery-3.3.1.min.js
    URI: http://localhost/jquery-3.3.1.min.js (br)
    Uncompressed size : 84.88 KiB
    Compressed size   : 30.54 KiB
    

    now with brotli default of level 5 compression and brotli_min_length 1400 bytes

    for index.html
    Code (Text):
    curltest gzip http://localhost/
    URI: http://localhost/ (gzip)
    Uncompressed size : 4.40 KiB
    Compressed size   : 1.81 KiB
    
    curltest br http://localhost/
    URI: http://localhost/ (br)
    Uncompressed size : 4.40 KiB
    Compressed size   : 1.53 KiB
    

    for jquery file
    Code (Text):
    curltest gzip http://localhost/jquery-3.3.1.min.js
    URI: http://localhost/jquery-3.3.1.min.js (gzip)
    Uncompressed size : 84.88 KiB
    Compressed size   : 29.75 KiB
    
    curltest br http://localhost/jquery-3.3.1.min.js
    URI: http://localhost/jquery-3.3.1.min.js (br)
    Uncompressed size : 84.88 KiB
    Compressed size   : 29.01 KiB
    


    Continue reading...

    123.09beta01 branch
     
    Last edited: Feb 21, 2019
    • Informative Informative x 1
  2. Jimmy

    Jimmy Well-Known Member

    1,606
    337
    83
    Oct 24, 2015
    East Coast USA
    Ratings:
    +847
    Local Time:
    1:39 AM
    1.15.x
    MariaDB 10.3.x
    What about the Brotli setting in Cloudflare? Should that be disabled.

    So, if we want to disable brotli we should:

    1. Remove the variables in the custom_config (2 lines).

    2. Rebuild nginx / php

    Do we have to uncomment the line below in the nginx.conf?
    Code:
    include /usr/local/nginx/conf/brotli_inc.conf;
     
  3. eva2000

    eva2000 Administrator Staff Member

    41,386
    9,297
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +14,261
    Local Time:
    3:39 PM
    Nginx 1.17.x
    MariaDB 5.5/10.x
    Cloudflare Brotli is a different beast as the load is spread across many Cloudflare Edge servers so extreme high loads don't have just one server from one geographic region handling the load unlike Centmin Mod Nginx sole server setup. It's safe to leave Cloudflare Brotli compression enabled. Though still slower from tests at https://community.centminmod.com/th...-vs-nxg_brotli-compression-level-tests.13820/ but that is because Cloudflare tests transversed remote network while other tests tested localhost/server.

    last 4 results are for Cloudflare Brotli performance as a reverse proxy

    config compressed size req/s avg latency max latency
    Centmin Mod Nginx zlib level 5 pre-compress static (cf fork) 3.79KB 72443 3.27ms 32.38ms
    Centmin Mod Nginx zlib level 6 pre-compress static (cf fork) 3.79KB 71905 3.36ms 50.43ms
    Centmin Mod Nginx brotli level 5 pre-compress static 3.38KB 84643 2.76ms 39.79ms
    Centmin Mod Nginx brotli level 6 pre-compress static 3.38KB 84975 2.96ms 87.54ms
    Centmin Mod Nginx zlib level 5 dynamic (cf fork) 4.12KB 21906 9.07ms 74.32ms
    Centmin Mod Nginx zlib level 6 dynamic (cf fork) 4.00KB 16997 11.67ms 49.06ms
    Centmin Mod Nginx brotli level 5 dynamic 3.93KB 5060 38.61ms 167.43ms
    Centmin Mod Nginx brotli level 6 dynamic 3.66KB 4875 40.12ms 119.51ms
    Cloudflare Reverse Proxy zlib 1st run 4.00KB 3693 133.71ms 2000.0ms
    Cloudflare Reverse Proxy zlib 2nd run 4.00KB 8224 38.08ms 1930.0ms
    Cloudflare Reverse Proxy brotli 1st run 3.66KB 6634 23.45ms 778.5ms
    Cloudflare Reverse Proxy brotli 2nd run 3.66KB 7294 24.99ms 1400.0ms


    To disable Centmin Mod nginx brotli just remove from persistent config file the 2 variables
    Code (Text):
    NGXDYNAMIC_BROTLI='y'
    NGINX_LIBBROTLI='y'
    

    then recompile nginx via centmin.sh menu option 4 which will auto disable include file at
    /usr/local/nginx/conf/brotli_inc.conf.
     
    • Like Like x 1
  4. Jimmy

    Jimmy Well-Known Member

    1,606
    337
    83
    Oct 24, 2015
    East Coast USA
    Ratings:
    +847
    Local Time:
    1:39 AM
    1.15.x
    MariaDB 10.3.x
    Thanks for the info! I'm going to disable it for the time being.
     
    • Like Like x 1