RTSP基于TCP传输请求和响应报文,RTP基于UDP传输流媒体数据,RTCP基于UDP传送传输质量信息(如丢包和延迟)。
比如喀什一个局域网内10个人同时点播广州的同一个源,喀什和广州之间就要传10x4Mbps的数据。1. 是为讨论下文编的; 2. 4Mbps算不上高清。
在局域网和城域网之间有个proxy,喀什和广州之间传1路,局域网内1变10: pkt = recv(); for (i = 0; i < n_receiver; i++) send(pkt).
包从网络->网卡->核心->用户态,简单判断和修改,再用户态->核心->网卡->网络,memcpy次数非常多。本例改都都不改。
Programming Protocol-independent Packet Processors (P4) is an open source, domain-specific programming language for network devices, specifying how data plane devices (switches, routers, NICs, filters, etc.) process packets. SmartNICs with P4 support: Netronome offers its P4 programmable devices under its the Agilio SmartNICs line of products, which include three series: CX (see Figure 5), FX and LX. The heart of those devices is the Netronome flagship silicon chip called NFP (Network Flow Processor or Netronome Flow Processor). CX series is the most diverse family with low-end NFP-4000 matched with 2GB of DDR3 RAM. The network interfaces available here vary from 2 x 10 GbE to 2 x 40 GbE. The cards are available in a low-profile PCI and in OCPv2 form factor. FX series right now includes only one card, a modified version of Agilio CX 2 x 10 GbE with an additional quad-core ARMv8 processor with 2 GB of RAM on-board. The LX series is the most powerful family and is built as a high-profile PCI card with 2 x 40 GbE or 1 x 100 GbE interfaces and NFP-6480 silicon with 8GB of DDR3-1866Mhz DRAM w/ECC. P4的网站上还列出了更多智能网卡。
请看下面的语言:
IP[] _receivers
loop rtp_1_to_n { # coroutine to relay/pass on RTP packets
pkt = recv()
for ip in _receivers:
sendto(pkt, ip)
endfor
}
我们把它叫做D4: Data Domain Dispatch/Deliver Description. 笑够了再往下看,也许我们能增强并实现它呢?
D4没有指针。if pkt[1:4] == 000001h 这样检查数组下标是否越界时不用检查a[1], a[2], a[3]3次。没有goto。
for i = 0 to 1000 step 1 for j = 0 to 10 for k = 0 = 10编译时遇到两条出错信息:
1. for最多套2层
2. 每个for最多循环100次
这样程序好像没法写成死的了吧?默认网络字节顺序。
Linux kernel里可不能像用户态程序那样用阻塞式recv等。好像有kernel thread。有人在用户态下做了个C的协程库(只能用全局变量)。写个kernel module, 实现协程库功能是可以做到的。
该module解释执行DPTD不难。解释执行没有那么慢,Java还能写Web服务器呢: Tomcat.
难点有2:
1. D4与外界的交互,如启动和停止协程,修改_receivers。
2. 做成编译型。
1)好像不是太难,handle = d4_exec('loop rtp_1_to_n ...'), 像Javascript和Python的exec/eval,把代码传进去,返回handle,如123,然后用handle来start和stop。d4_exec('IP[] _receivers'); 定义_receivers, d4_exec('_receivers += 192.168.0.1'),可参考JS和Python Engine的做法。
2. 做成编译型好像挺难但不是做不到。关键每个协程得有自己的堆栈。在DOS下写flood fill时我干过mov old_sp, sp; mov sp, 大内存块地址,递归,mov sp, old_sp. kernel咋加载a.out的?
用llvm做的python JIT已经有了,正在试。一种语言,三个环境:用户核心和网卡。在别的贴子里我觉得python异步I/O没大意义,现在又觉得为啥不用python写web server?在kernel里read再send,可能比不上sendfile(),但起码不用kerenel-user-kernel了。
Erlang能"一行怒解TCP", 但语法贼晦涩。
不好意思,我标题党的。
参考资料: The Linux Virtual Server Venture (LVS) permits load adjusting of organized administrations, for example, web and mail servers utilizing Layer 4 Exchanging. search(章文嵩 百科), search(IPVS, iptables and kube-proxy).
浙公网安备 33010602011771号