Cloud foundry warden源码学习(1)

来源:互联网 发布:淘宝我的发票灰色的 编辑:程序博客网 时间:2024/06/07 01:09

Cloud Foundy是一个open source的PAAS平台,warden是其运行时应用驻留的容器,和AWS及Asuze不同的是,Cloud Foundry追求所谓的高密度部署,即在每一个虚机节点上,可以部署多个应用。每个应用都会以warden容器的方式和其他应用共享该虚机。最早Cloud foundry是通过LXC实现这一套资源隔离和分享,但是LXC本身提供的能力和Cloud foundry的目标有所不同,从V2开始,Cloud foundry自己利用Linux kernal control group(C-group)技术,实现了一套资源隔离技术。这就是warden。在新的Diego项目中,应该会变成所谓的Garden。

首先看看warden的体系架构



Warden Server面向客户端提供的功能

Create创建一个warden container

Run (spawn + Link) –-handle执行某段bash command

Stop --handle

Destroy --handle

Net-in --handle

Net-out --handle

Copy-in --handle

Copy-out --handle


下面是Runtime的进程结构:



通过pstree看到的进程树



Warden server通过unix socket和客户端相连,对于每一次用户请求(一般是运行某些bash脚本),都会使用DeferredChild方式fork出iomux-spawn进程,iomux-spawn进程中又会fork出另一个子进程wsh。注意是每次请求都会有新的iomux-spawn等一系列进程被创建出来。

wsh进程负责和wshd,也即真正的warden instance server使用unix sockect(形如/var/vcap/data/warden/depot/17r47v9ocsj/run/wshd.sock)通信,同时使用两组pipe和iomux-spawn进程通信,将wsh获取的STDOUT,STDERR发送给iomux-spawn进程。

iomux-spawn进程除了fork一个wsh进程之外,还会pthred_create出5个线程,分别是:

  • muxer-run (wsh STDOUT pipe)和wsh子进程通信,接收标准输入流
  • muxer-accept (unix socket out /var/vcap/data/warden/depot/17vedc80gj3/jobs/54/stdour.socket)和连接来的link请求交互,将接收到的标准输出回写给link
  • muxer-run (wsh STDERR pipe)和wsh子进程通信,接收错误输入流
  • muxer-accept (unix socket out /var/vcap/data/warden/depot/17vedc80gj3/jobs/54/stderr.socket)和连接来的link请求交互,将接收到的错误输出回写给link
  • status-writer-run(unix socket out /var/vcap/data/warden/depot/17vedc80gj3/jobs/54/status.socket) 和连接来的link请求交互,将状态输出回写给link

下面是一个使用wardenclient(runner)的例子

/var/vcap/packages/warden/warden/bin/warden --socket /var/vcap/data/warden/warden.sock  --tracewarden> listhandles[0] : 17r47v9ocsihandles[1] : 17r47v9ocshhandles[2] : 17r47v9ocsjhandles[3] : 17r47v9ocslhandles[4] : 17r47v9ocsnhandles[5] : 17r47v9ocspwarden> run --handle 17r47v9ocsp --script "ps xf"  PID TTY      STAT   TIME COMMAND  128 ?        S<s    0:00 /bin/bash  129 ?        R<     0:00  \_ ps xf   29 ?        S<s    0:00 /bin/bash   31 ?        S<     0:00  \_ /bin/bash   32 ?        S<     0:00      \_ /bin/bash   34 ?        S<     0:00      |   \_ tee /home/vcap/logs/stdout.log   33 ?        S<     0:00      \_ /bin/bash   36 ?        S<     0:00      |   \_ tee /home/vcap/logs/stderr.log   38 ?        S<     0:00      \_ /bin/sh .liberty/bin/server run defaultServer   64 ?        S<l    1:25          \_ /home/vcap/app/.java/jre/bin/java -XX:MaxPermSize=256m -Djava.awt.headless=true -XX:OnOutOfMemoryError=./.buildpack-diagnostics/killjava -Xtune:virtualized -Xmx576M -javaagent:/home/vcap/app/.liberty/bin/tools/ws-javaagent.jar -jar /home/vcap/app/.liberty/bin/tools/ws-server.jar defaultServerwarden> info  --handle 17r47v9ocspstate : activehost_ip : 10.254.0.33container_ip : 10.254.0.34container_path : /var/vcap/data/warden/depot/17r47v9ocspmemory_stat.cache : 223944704memory_stat.rss : 93593600memory_stat.mapped_file : 45498368memory_stat.pgpgin : 95451memory_stat.pgpgout : 17927memory_stat.swap : 0memory_stat.pgfault : 73742memory_stat.pgmajfault : 79memory_stat.inactive_anon : 0memory_stat.active_anon : 93597696memory_stat.inactive_file : 183410688memory_stat.active_file : 40529920memory_stat.unevictable : 0memory_stat.hierarchical_memory_limit : 805306368memory_stat.hierarchical_memsw_limit : 805306368memory_stat.total_cache : 223944704memory_stat.total_rss : 93593600memory_stat.total_mapped_file : 45498368memory_stat.total_pgpgin : 95451memory_stat.total_pgpgout : 17927memory_stat.total_swap : 0memory_stat.total_pgfault : 73742memory_stat.total_pgmajfault : 79memory_stat.total_inactive_anon : 0memory_stat.total_active_anon : 93597696memory_stat.total_inactive_file : 183410688memory_stat.total_active_file : 40529920memory_stat.total_unevictable : 0cpu_stat.usage : 90655481463cpu_stat.user : 3814cpu_stat.system : 4928disk_stat.bytes_used : 223223808disk_stat.inodes_used : 2014bandwidth_stat.in_rate : 4294967295bandwidth_stat.in_burst : 4294967295bandwidth_stat.out_rate : 4294967295bandwidth_stat.out_burst : 4294967295job_ids[0] : 39warden> run --handle 17vedc80gj3 --script "while true; do echo 'here';sleep 3;done"herehere 

运行完该脚本后,发现多了一组进程24026(iomux-spawn),24027(wsh)和iomux-link(24030),说明每次运行一个bash command都会有iomux-spawn通过wsh连接到warden容器,而且可以看到iomux-spawn有5个线程。(23588-23593)。

0 0
原创粉丝点击