Trendyol CDN — 2

Levent CENGIZ
Trendyol Tech
Published in
4 min readAug 25, 2020

Go to the following link to read our previous post about Trendyol CDN.

What is Brotli ?

Brotli is a new generation compression algorithm developed by Google. The algorithm is named after the Swiss pastry, Spanisch Brötli. Brotli uses a modern version of the LZ77 algorithm and Huffman coding.

Advantages of Brotli:

Brotli is 20% to 25% more efficient than Zopfli in terms of compressing HTML, CSS, and javascript files and it makes 20% more efficient compression than Gzip. The new algorithm reduces bandwidth consumption and helps to upload the content faster.

Browsers Supporting Brotli:

Types of data that can be compressed with Brotli:

  • application/jаvascript
  • application/json
  • application/x-jаvascript
  • application/xml
  • application/xml+rss
  • text/css
  • text/html
  • text/jаvascript
  • text/plain
  • text/xml
  • application/vnd.ms-fontobject
  • application/x-font-ttf
  • image/x-icon

Brotli is not predefined with Nginx and Tengine by default. Therefore, you must first compile Nginx with Brotli support to be able to use Brotli.

Go to the following URL to access Tengine RPM that we have custom-built for this article. Specially compiled Tengine content offers Brotli support.

https://trendyol.dsmcdn.com/RPM/tengine-2.3.2-1.el7.ngx.x86_64.rpm

You can enable ngx_brotli on Nginx by adding the following config inside the ‘http {…}’ section.

brotli on;
brotli_comp_level 6;
brotli_static on;
brotli_types text/plain text/css application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript image/x-icon image/vnd.microsoft.icon image/bmp image/svg+xml;

For the CDN service, we will make suggestions for efficiency/performance optimizations of different layers of the system such as hardware and drivers, starting from the lowest level.

CPU

For Asymmetric RSA/EC Performance, we prefer processors that have at least AVX2 support and preferably hardware with high arithmetic precision (bmi and adx). The uses such as latency-sensitive will utilize fewer NUMA nodes and disabled HT. highly productive tasks perform better with more cores and utilize Hyper-Threading (as long as they’re not bound to cache memory) and usually, they do not regard NUMA too much.

At least Haswell/Broadwell and ideally Skylake CPUs can be preferred particularly on the Intel side. EPYC shows quite an impressive performance on the AMD side.

Memory

Here, the rule of thumb is that latency-sensitive tasks need a faster memory while throughput-sensitive tasks need more memory.

Storage

It is directly proportional to your Buffering/Caching needs, but if you need too much Caching, Flash-based storage should be used.

CPU Affinity

To illustrate, you can reduce latency by applying Thread/Process CPU affinity. Nginx has a worker_cpu_affinity directive that can automatically connect each web server process to its core. This should eliminate CPU transitions, reduce cache deficiencies and page faults, and slightly increase the instructions per cycle. You can verify all these processes with performance metrics.

Unfortunately, enabling the affinity can also increase the time a process spends on an idle CPU and thus, adversely affect the performance.

If you see millisecond latencies, there may be other applications on the server other than Nginx. In this case, affinity will increase the latency rather than reducing it.

Maximum Number of Open Files

Nofile (Maximum number of open files) limits on the Linux kernel are 1024 by default. Make sure that these limits don’t give rise to bottlenecks for you.

Using the command below, you can display the Max Open Files values ​​of your Nginx service.

cat /proc/$(cat /var/run/nginx.pid)/limits | grep open.files
Max open files 100000 100000

Nginx Worker Process limit

ps — ppid $(cat /var/run/nginx.pid) -o %p|sed ‘1d’|xargs -I{} cat /proc/{}/limits|grep open.files
Max open files 100480 100480 files
Max open files 100480 100480 files
Max open files 100480 100480 files
Max open files 100480 100480 files
Max open files 100480 100480 files
Max open files 100480 100480 files
Max open files 100480 100480 files
Max open files 100480 100480 files
Max open files 100480 100480 files
Max open files 100480 100480 files
Max open files 100480 100480 files
Max open files 100480 100480 files
Max open files 100480 100480 files
Max open files 100480 100480 files
Max open files 100480 100480 files
Max open files 100480 100480 files
Max open files 100480 100480 files

You can change the Nofile limits as stated below.

nano /etc/systemd/system/nginx.service.d/nginx.conf
[Service]
LimitNOFILE=100000
$ systemctl daemon-reload
$ systemctl restart nginx.service

SSL

Intel® QuickAssist Technology (QAT) uses some special CPU-based algorithms and significantly increases the SSL/TLS performance.

RSA-2K Connections per Second

ECDHE-RSA-2K Connections per Second

Fist bump, keep in touch!

--

--