Installing NVENC SDK and CUDA SDK on Ubuntu 14.04

After I set up my streaming server, there are some problems brought by the design. Using CPU to process the streams will consume lots of CPU cycles and if the streaming server have lots of connections, resource to handle them will run low if the machine itself does not have strong CPUs. NVIDIA’s NVENC is a way of offload the transcoding to GPUs that is dedicated to such processing and leaves much more CPU cycles for other purposes. However, installing NVIDIA’s driver is a nightmare, which is why I decided to write it down for future reference.

Then the below installs NVENC SDK’s header into your system.

You can then now compile programs that uses NVIDIA’s NVENC to speed up video processing, including ffmpeg.

Optimizing Nginx for (large) file delivery

Some times ago, I have a need to host some big files for open download. At first, I think Nginx will perform pretty well without muck configuration. In reality, there are complains about slow and interrupted downloads which is quite annoying.

After digging the Nginx docs, I find some nice changes that can fix these problems and produce a high throughput. Here’s my tweaks made to the nginx.conf file:

  1. Turn off sendfileThe Linux sendfile call is known to have throughput degradation when in high load. Disabling it helps to keep a higher throughput at high load. Also, when serving large files with sendfile, there are no ways to control readahead.
  2. Enable TCP nopushTCP nopush fills the TCP packet to its maximum size before sending. This can help increase throughput if you’re serving large files.
  3. Use Nginx’s directio to load fileUsing directio can help improving performance by skipping a bunch of steps happened in the kernel when reading files, thus speed up the throughput.
  4. Enable the use of libaio for optimal performancelibaio allows asynchronous I/O to be done in kernel, which results in faster read and write speed. However, it needs libaio to be installed and re-compiling your Nginx in order to have it supported. I used the following flow to recompiling Nginx with aio support.

The complete nginx.conf should look like this:

There are also some lower-level tewaks like mounting your disks with noatime flags and use ext4/xfs when serving files.