Apsaravideo for VOD is the most popular Internet service in recent years. This article analyzes the key technologies of apsaravideo for VOD from a technical perspective.
How video content is distributed on the Internet
Video websites, such as YouTube, Youku, Tudou, and Sina video, use multiple CDN technologies to distribute video content. The translation of CDN into Chinese is "content delivery network ". Editing, users make or upload videos to the CDN network, CDN network will distribute these videos to on-demand services distributed in IDCs across the country. The user accesses the nearest VOD service for video experience. Key software that makes up CDN networks include HTTP-based server software such as squid and Apache and Domain Name Server software such as bind, the Domain Name Server Software directs HTTP requests to the On-Demand Server in the IDC nearest to the user based on the user's IP address.
CDN software analysis
Popular VOD services are mainly based on HTTP, MMS, and rmtp protocols. Http does not control messages. Therefore, this protocol does not support controlling On-Demand Streaming Media, such as progress dragging, play, pause, stop, etc.
Squid Apche, which supports HTTP-based on-demand services, is currently the most popular. Most video sharing websites adopt similar solutions. The main function of squid is the reverse proxy function. It is generally used as a VoD front-end server. What is reverse proxy-to put it bluntly, when a user accesses the squid service software, if squid does not have this video file, it will according to the parameters set in the configuration file, go to the upstream data center to capture the file, and then return it to the user for viewing. For example, when a user in Xi'an accesses Youku, Youku finds that the user accessing Xi'an directs the access to the squid server deployed by Youku in Xi'an, when squid finds that no video is required by the user, it crawls files to its local server in Beijing based on the parameters set in the configuration file. Then return the video file to the user. When another user accesses the same video, the local video already exists, and the video is directly returned to the user.
Media Service, flash server. These two servers support control protocols. Media Service supports MMS, RTSP, and Flash server support rtmp. When you access the VOD service of these two protocols, you can drag the scroll bar, pause, terminate, and other control operations. You can drag a video on the 56 network to watch it. I think the rtmp protocol should be used. Sina's early video services were on-demand video with MMS protocol and supported drag.
VOD technical solutions and advantages
Squid + Apache solution. advantages of this solution:
The software is mature and stable.
Video distribution adopts the PULL mode. And squid can be grouped, so distribution is simple and relatively efficient.
Open technology. Because squid and Apache are popular software on Linux and open source code, you can perform secondary development.
The software cost is low, Linux does not require authorization fees, squid and Apache are free of charge, and the software cost is basically 0.
Disadvantages:
Squid is an antique software designed to act as a proxy. At that time, there was no video sharing concept. Therefore, it is difficult to provide CDN services. Many companies perform transformation and secondary development for squid when constructing a CDN network.
The squid agent is a file. When the video file size is large, such as several hundred megabytes, reverse proxy crawling efficiency is low. Everyone has experience. It takes a long time to upload a file of several hundred megabytes, which occupies a lot of bandwidth and CPU resources.
Squid and system integration. As a server software, supporting concurrency is a very important parameter. If a server supports a large number of concurrent users, it can save a lot of cost for the company. The number of concurrent jobs has the following factors:
Bandwidth: We all know that the server Nic is usually a gigabit Nic. If the video encoding bit rate is 400 K and dividing 2500 m by K, the system can support connections when the network adapter is fully running. However, the actual situation is generally 500 m, and it is good to support 1000 concurrent connections.
Memory: when the number of concurrent connections is large, the memory used by the server tends to experience a bottleneck. Think about it. If a connection requires 1 MB of memory for data transmission, 1000 concurrent 1 GB memory will be gone. This is the fact. Therefore, ngix is superior to Apache in this respect.
CPU: network I/O consumes a fatal CPU in many systems. The reason is that some platforms do not provide efficient I/O model solutions. Network I/O is divided into blocking and non-blocking modes, asynchronous and synchronous modes.
The worst way is to block the synchronization mode. However, this mode is actually the most commonly used. This is the BSD socket interface, read, write, connect, bind, listen, which is used by most software. For programming convenience, the calling thread is blocked to call these system calls. This programming method is absolutely unacceptable when the concurrency is large, especially for server software.
Non-blocking synchronization mode: This mode is the most popular in Server programming. In UNIX and Linux, select, poll, and Windows support select, but waitforobject system calls provide better performance. However, these calls are based on the query handle status, and in the user mode, when the concurrency is large, this round robin consumes a lot of CPU. Servers before linux2.6 can only use this solution, and it is the best solution. However, this requirement for high concurrency of network services is unacceptable. In this solution, some secondary development will transform the number of write and read system calls and replace them with writev. readv is an iovector-based call that reduces the number of system calls during Io. However, I personally think the effect is limited.
The most efficient non-blocking asynchronous mode: the operating systems that support this mode include Solaris, windows, Linux 2.6 or later, and FreeBSD
Based on AIO, Solaris and windows are truly kernel-state asynchronous Io. Epoll calls in Linux only notify the handle state asynchronously, but the read/write of Io is still the responsibility of the user, so it is not really asynchronous Io. FreeBSD's kqueue is similar. However, this solution is the best solution in the existing solution. I am more optimistic about Windows's iocp, because the system calls in Windows's iocp are not only true asynchronous Io, but also support overlapped read and write. It can be said that it supports multi-thread concurrent read and write of the same IO handle. The Windows platform should be the best future solution for network services. Too good. The aiowait System of Solaris does not support multithreading.
The impact of CPU on I/O seems to be too much ink, mainly because it has a huge impact on the concurrency.
Bandwidth speed limit: We all know that the user bandwidth is getting bigger and bigger. If we do not limit the user download speed, the consequences are very serious. For example, if a user makes 10 Mbps of bandwidth and the speed is not limited, 100 users will eat the server bandwidth. In actual situations, 50 of them will not work. Therefore, the server must limit the download speed. If the video code stream is 400 K, it is best to limit the user to 500 K, which does not affect the user's smooth viewing, but also saves the server bandwidth. In this way, the concurrency of a server can support more users.
Local cache: the main advantage of squid is local cache. However, if the cache is occupied by files rarely accessed by a large number of users, the server disk space is limited, which will increase the number of reverse proxies. To reduce the proxy effect, you must adjust and design the cache algorithm.
The Application of CDN to P2P technology. If the reverse proxy software can form a P2P network, it can exchange and store network data blocks. This will greatly reduce the number of accesses to the data center and accelerate the efficiency of data exchange. Squid is a file-based proxy. If it is used as a file-based proxy, the effect is poor when asked about the huge size.