Lightweight intelligent caching and distribution launched for EFV targeted delivery
EFV recently introduced targeted distribution, assigning different delivery domains to selected videos. However, origin synchronization was mainly available from commercial storage services such as Qiniu and Alibaba Cloud. I therefore wrote a lightweight intelligent caching and distribution system. Here is a practical example of how it works.
Example
EFV transcoding server: in Germany, with a powerful CPU and large disk.
EFV domain: https://www.leimulamu.com.
Cache server: a US CN2 server with a weak CPU and a small 100G disk.
Cache-system domain: https://cdn.leimulamu.com.
In the EFV video library, assign targeted distribution to a batch of videos:
Replace http://127.0.0.1:3001 in the screenshot with https://cdn.leimulamu.com.
Caching-system settings:
module.exports = {
cacheHost: "https://www.leimulamu.com", //缓存转码服务器的域名 最后不包含/
corsUrls: "https://www.leimulamu.com|https://cdn.leimulamu.com", //留空即开放所有域名访问
maxCacheSize: 1024 * 1024 * 1024 * 30, // 默认1G 自行根据服务器情况设置
cacheDir: './tmp' // 缓存目录,默认源码目录中的tmp中,可设置绝对路径
}
The comments explain the settings clearly.
When users play these videos, their segments are served through https://cdn.leimulamu.com.
For a targeted-distribution video on Leimu Lamu, a segment URL is:
https://cdn.leimulamu.com/videos/202006/30/5efb0ec803ced46174479c7e/dc87a9/index1.ts
The cache server checks whether the requested file is cached. If so, it returns it directly. Otherwise it fetches the file from the transcoding server, returns it to the user and caches it simultaneously.
When cached files exceed the configured capacity, the least-used files are evicted.
Cached files are stored as obfuscated binary data:

Conclusion
This system pairs well with EFV targeted distribution. Use a high-spec server for transcoding and several low-spec, good-bandwidth VPS servers for caching and delivery. Tests suggest the site's first 10 pages contain the popular content; caching these can satisfy nearly 80% of visits. If previews are enabled, caching popular preview segments can greatly improve access speed and user experience.


