美文网首页
Slipstream: Automatic Interproce

Slipstream: Automatic Interproce

作者: LucasHao | 来源:发表于2020-10-18 14:38 被阅读0次

关键词:容器本地TCP通信
实验源代码

0

TCP endpoint: A 2-tuple,<local IP address,TCP port number>

shim:In computer programming, a shim is a small library that transparently intercepts an API, changing the parameters passed, handling the operation itself, or redirecting the operation elsewhere

1 背景

本地应用之间的TCP交互成本过高而且没必要,在OS上的优化将导致失去TCP的通用型和移植性优点,在应用上改代码更不用提。

2 主要目标&基本思路

2.1 主要目标

基于识别和优化本机TCP通信,在不改动kernel(含kernel module)和application的基础上减少延迟,增加吞吐。同时,对于一方使用slim另一方不使用也要兼容

2.2 基本思想

在libc之上插入一个optional shim library ,仅依赖TCP的可观察这一特性来检测本地TCP通信。

a backwards-compatible algorithm for classifying communication between two end point

检测到之后,将替换为一种更快的本地通信来模拟所有的TCP操作,难点在于在user-level中replicate kernel-level TCP state,以及对上层调用保留TCP接口语义以及可靠性保证,失败重传等机制

replace TCP with Unix domain sockets as the transport layer

3 挑战&架构

3.1 挑战

  • 不同namespace中(如虚拟网络)会在网络中出现。一对相同的IP/port pair属于不同的流(tcp endpoint in kernel不一样)的情况

  • 内核可以把一个TCP endpoint映射在不同进程上;一个kernel-level TCP endpoint可以与多个userspace file descriptors映射。slipstream需要检测应用在kernel的交互(如对endpoint instance的创建和删除)

  • Inband && outband

    TCP协议不支持在端点之间“outband”传输额外数据的任何可靠机制(有TCP紧急数据功能,但用于传输大量数据的方法不可靠);

    另一方面,将任何此类数据“inbound”注入流中会破坏未使用Slip stream的应用,因此无法过滤额外数据。 这使检测两个tcp endpoint在同一台主机以及确保Slipstream可用性变得复杂。

  • POSIX文件描述符通过大量系统调用实现大量的功能,必须正确地实现它们才能透明地保留应用程序功能。

3.2 架构

截屏2020-10-18 下午2.37.35.png

slipstream构造了一个shim library: libipc,负责跟踪所有与TCP相关的系统调用中的tcp endpoint,并向系统范围的进程ipcd报告所有TCP流标识信息。 ipcd收集并记录所有流信息,并使用流匹配算法分析所有现有流。

一旦Slipstream检测到流的两个端点都是本地的,libipc就会修改信道以使用本地IPC传输(在我们的实现中为UDS)

4 实现

  • 识别两个端点都在本地的TCP通信流;

  • 用替代的本地传输代替TCP;

  • 模拟TCP套接字接口的大多数功能

拦截:通过LD_PRELOAD的方法拦截应用的socket调用

追踪:为了追踪跟踪TCP流,Slipstream为应用程序创建和使用的每个TCP endpoint分配一个unique endpoint ID(EPid),libipc会给每个EPid分配一个状态

Pre-opt: 没有尝试优化

No-opt:尝试优化失败

Opt:优化成功

Libipc通过跟踪关键的系统调用(例如fork/TCP modifying operations)来复制在user-level的endpoint state;

  • Libipc在跟踪这些调用的时候,维护着一个持有这个endpoint至少一个fd的进程的计数;而且将fd EPid这些细节尽可能详细的存放在libipc而不是频繁与ipcd交互增加额外开销

  • 实现上,libipc维护着两张表

    • Track file descriptors:做到和kernel一个粒度,并包含了fd到endpoint的关系映射

    • Track endpoints:EPid->state

  • 通过观察 the initial TCP conversation(由流的前N bytes的哈希值和连接创建调用的精确timing组成)来被动识别本地的流,当这些信息不足以提供判断,不优化

step1:When a new TCP socket is connected,libipc immediately records the time of the connection attemptand forwards it toipc dalong with the IP and port information.

step2:Ipcd uses this information to identify endpoints that are likely candidates for pairing.

step3:Ipcd can eagerly detect if multiple pairings are possible due to overlapping address/port pairs and timing information.

step4:After Nbytes have been sent in one direction on the stream,libipc contacts ipcd to attempt to find a matching endpoint.

step5: If a single matching endpoint is found,ipcd initiatesthe optimization procedure

5 实验结果

服务器应用程序的吞吐量提高了16-100%,Docker的吞吐量提高了100-200%,微基准测试表明延迟减少了一半

相关文章

网友评论

      本文标题:Slipstream: Automatic Interproce

      本文链接:https://www.haomeiwen.com/subject/yrlcmktx.html