SlideShare una empresa de Scribd logo
1 de 29
Descargar para leer sin conexión
マスタリング DEA/NG 第2版

岩嵜 雄大
NTT Software Innovation Center
2012-09-13


                 NTT Software Innovation Center
はじめに




              情報はすべて資料作成当時のものです
              – 更新が頻繁なため情報がすぐに古くなります
              – 必ず最新のソースコードを確認してください




2012-09-13           NTT Software Innovation Center   2
今日の内容

              そもそもDEAとは
              – 簡単な紹介


              DEA_NG起動から、Warden上でのアプリ
               ケーション実行までを追う
              – エントリーポイントからインスタンス起動まで


              Promiseパターンについて
              – DEA_NGに頻出するPromiseとは何者か



2012-09-13              NTT Software Innovation Center   3
そもそもDEAとは




2012-09-13    NTT Software Innovation Center   4
DEAとは
  ユーザのアプリケーションを実行するためのコン
   ポーネント
      – Dropletと呼ばれる形式のアプリケーションを実行する
      – DEAを増やすことでCloud Foundryの実行能力はスケー
        ルする
                   App
                                                     App
                   App
                                                     App
                   App
                                                     App
             App   App
                                              App    App
             App
                   DEA
             App                               App   DEA
             App                               App
                                              App
             DEA
                                              DEA

2012-09-13         NTT Software Innovation Center          5
DEAがやること


              Dropletのダウンロード

              ランタイム(Java, Ruby, etc)の管理

              アプリケーション隔離用コンテナの管理
              – コンテナには独自の「Warden」を使用

              アプリケーションの管理・死活監視




2012-09-13             NTT Software Innovation Center   6
DEAサーバの起動から
             アプリケーションの起動まで




2012-09-13      NTT Software Innovation Center   7
全体的な概念図(今日話す範囲)

                       DEA
                  Instance
                     Instance
                        Instance
                           Instance
                                                     1対1対応で生成や起動などを担当
                                                     通信はWarden Protocol
                     生成
CCからの命令
                       NATS
基本的には
イベントドリブン                                               App App App App App
                     DEAプロセスの
                     セットアップ                       ContainerContainerContainer
                                                      ContainerContainer

        bin/dea       BootStrap                             Warden

                                     VM
       ※他にもDroplet RegistryやDirectory Serverなどがサブモジュールがある
2012-09-13                 NTT Software Innovation Center                       8
エントリーポイント

              /bin/dea

               bootstrap = Dea::Bootstrap.new(config)
                EM.run do
                  bootstrap.setup
                  bootstrap.start
                end


              – コマンドライン引数のパース
              – DEAプロセスをキック


2012-09-13                 NTT Software Innovation Center   9
DEA serverの起動
  /lib/dea/bootstrap.rb
      – プロセスの初期セットアップ (setup_*)
      – NATSクライアントの起動
         • あとはNATSまかせ
             def start
               start_component
               start_nats
               start_directory_server
               start_finish
             end
             …
             def setup_nats
               @nats = Dea::Nats.new(self, config)
             end
2012-09-13               NTT Software Innovation Center   10
NATSに対するディスパッチャーの登録

  /lib/dea/nats.rb
      – アプリケーションインスタンスの起動イベント

   def start
   …
     subscribe("dea.#{bootstrap.uuid}.start") do |message|
       bootstrap.handle_dea_directed_start(message)
     end
   …
   end

   def subscribe(subject)
     sid = client.subscribe(subject) do |raw_data, respond_to|
       message = Message.decode(self, subject, raw_data, respond_to)
       logger.debug "Received on #{subject.inspect}: #{message.data.inspect}"
       yield message
     end

     @sids[subject] = sid
   end

2012-09-13                    NTT Software Innovation Center                    11
Bootstrap側のハンドラ


  DEA::Instance オブジェクトを生成
      – オブジェクトはレジストリに登録する

 def handle_dea_directed_start(message)
   instance = create_instance(message.data)
 …
   instance.start
 end
 …
 def create_instance(attributes)
   instance = Instance.new(self, Instance.translate_attributes(attributes))

   instance.on(Instance::Transition.new(:born, :starting)) do
     instance_registry.register(instance)
   end
 … (他のインスタンス状態変化トリガ)
   instance
 end

2012-09-13                   NTT Software Innovation Center                   12
インスタンスの起動
  /lib/dea/instance.rb
        – Promiseについては後述
  def start(&callback)
  …
        if !droplet.droplet_exist?
          logger.info("Starting droplet download")

  …
          promise_droplet_download.resolve
                                                                      ドロップレット
        end
                                                                      をダウンロード
        promise_container = Promise.new do |p|
          promise_create_container.resolve
          promise_setup_network.resolve
          promise_limit_disk.resolve
          promise_limit_memory.resolve                              コンテナの準備
          p.deliver
        end
  …
        promise_extract_droplet.resolve
        promise_prepare_start_script.resolve
                                                                    インスタンスの
  …
        promise_start.resolve
                                                                       起動
  end

2012-09-13                         NTT Software Innovation Center             13
コンテナの生成設定

  DEAホストのDropletとランタイムをコンテナ内
   から見えるように追加のマウント情報を設定

def promise_create_container
…
    connection = promise_warden_connection(:app).resolve

     # Droplet and runtime
     bind_mounts = [droplet.droplet_dirname, runtime.dirname].map do |path|
       bind_mount = ::Warden::Protocol::CreateRequest::BindMount.new
       bind_mount.src_path = path
       bind_mount.dst_path = path
       bind_mount.mode = ::Warden::Protocol::CreateRequest::BindMount::Mode::RO
       bind_mount
     end

…次ページに続く



2012-09-13                    NTT Software Innovation Center                  14
コンテナの生成設定


  ライブラリ類もマウントとして追加


 …前ページから
    # Extra mounts (these typically include libs like pq, mysql, etc)
    bootstrap.config["bind_mounts"].each do |bm|
      bind_mount = ::Warden::Protocol::CreateRequest::BindMount.new

             bind_mount.src_path = bm["src_path"]
             bind_mount.dst_path = bm["dst_path"] || bm["src_path"]

             mode = bm["mode"] || "ro"
             bind_mount.mode = BIND_MOUNT_MODE_MAP[mode]

      bind_mounts << bind_mount
    end
 …次ページへ


2012-09-13                         NTT Software Innovation Center       15
アプリケーションインスタンスの実行
  Warden Protocolによりコンテナを起動
 …前ページから
    create_request = ::Warden::Protocol::CreateRequest.new
    create_request.bind_mounts = bind_mounts

        response =promise_warden_call
                         (connection, create_request).resolve
 …
   end
 end

  コンテナ起動後にメモリとディスクの制限を行う
      – promise_setup_network
      – promise_limit_disk
      – promise_limit_memory

2012-09-13                NTT Software Innovation Center        16
【寄り道】      promise_warden_callで何が起きているのか

  connectionは EM::Warden::Client::Connection
  def promise_warden_call(connection, request)
       Promise.new do |p|
         logger.debug2(request.inspect)
         connection.call(request) do |result|
           logger.debug2(result.inspect)
            …
           if error
              logger.warn "Request failed: #{request.inspect}"
              logger.log_exception(error)

              p.fail(error)
            else
              p.deliver(response)
            end
          end
         …
   end

2012-09-13                 NTT Software Innovation Center        17
【寄り道】      Warden Clientの話

  Warden本体については「すごく分かるWarden」
      – http://www.slideshare.net/i_yudai/warden


  3つのライブラリ
      – warden-client
         • Unix Socketによる(簡易な)実装
         • ライブラリ的なものも含む
      – em-warden-client
         • EventMachineを使用した実装
         • warden-clientに依存
      – warden-protocol
         • サーバクライアント間の通信に使うクラスのセット
2012-09-13             NTT Software Innovation Center   18
【寄り道】      Warden Protocol
  Wardenに対する各種命令
        •    ping              •   run
        •    create            •   info
        •    stop              •   LimitDisk
        •    spawn             •   LimitMemory
        •    link              •   net_in
        •    stream            •   net_out

  コマンドラインコマンドとほぼ同等
ping                          - ping warden
create [OPTION OPTION ...]    - create container, optionally pass options.
destroy <handle>              - shutdown container <handle>
stop <handle>                 - stop all processes in <handle>
spawn <handle> cmd            - spawns cmd inside container <handle>, returns #jobid
link <handle> #jobid          - do blocking read on results from #jobid
stream <handle> #jobid        - do blocking stream on results from #jobid
run <handle> cmd              - short hand for stream(spawn(cmd)) i.e. spawns cmd, streams the result
list                          - list containers
info <handle>                 - show metadata for container <handle>
limit <handle> mem [<value>] - set or get the memory limit for the container (in bytes)
net <handle> #in              - forward port #in on external interface to container <handle>
net <handle> #out <address[/mask][:port]> - allow traffic from the container <handle> to address
<address>

2012-09-13                             NTT Software Innovation Center                                   19
【寄り道】      EM::Warden::FiberAwareClient
  /em-warden-client/lib/em/warden/client.rb
      – create()メソッドは存在しない
         • method_missing()からcall()が呼ばれる

  def call(*args, &blk)
    …
    f = Fiber.current
    @connection.call(*args) {|res| f.resume(res) }
    result = Fiber.yield

    result.get     EventMachine::Warden::Client::Connection
  end

  def method_missing(method, *args, &blk)
    call(method, *args, &blk)
  end

2012-09-13               NTT Software Innovation Center   20
【寄り道】      EM::Warden::FiberAwareClient
  /em-warden-client/lib/em/warden/client.rb
      – create()メソッドは存在しない
         • method_missing()からcall()が呼ばれる

  def call(*args, &blk)
    …
                使わなくなりました
    f = Fiber.current
    @connection.call(*args) {|res| f.resume(res) }
    result = Fiber.yield

    result.get     EventMachine::Warden::Client::Connection
  end

  def method_missing(method, *args, &blk)
    call(method, *args, &blk)
  end

2012-09-13               NTT Software Innovation Center   21
【寄り道】      EventMachine::Warden::Client::Connection
  /em-warden-
   client/lib/em/warden/client/connection.rb
      – EM::Connectionを継承

def call(*args, &blk)
  if args.first.kind_of?(::Warden::Protocol::BaseRequest)
    request = args.first              Protocolオブジェクトが
  else                                   渡されている場合
    …
    request = ::Warden::Client::V1.request_from_v1(args.dup)
    @v1mode = true
                               argsに”create”が渡されていれば
  end
                             Warden::Protocol::CreateRequest
   @request_queue << { :request => request, :callback => blk }

  process_queue
end
2012-09-13               NTT Software Innovation Center          22
【寄り道】      コンテナ生成時におけるマウントの追加
  /warden/warden/lib/warden/container/linux.rb
      – フックにマウントの命令を追加する
   def write_bind_mount_commands(request)
     return if request.bind_mounts.nil? || request.bind_mounts.empty?

     File.open(File.join(container_path, "hook-parent-before-clone.sh"), "a") do |file|
       …
       request.bind_mounts.each do |bind_mount|
         src_path = bind_mount.src_path
         dst_path = bind_mount.dst_path

         # Fix up destination path to be an absolute path inside the union
         dst_path = File.join(container_path, "union", dst_path[1..-1])

         mode = case bind_mount.mode
                when Protocol::CreateRequest::BindMount::Mode::RO
                  "ro"
                when Protocol::CreateRequest::BindMount::Mode::RW
                  "rw"
                else
                  raise "Unknown mode"
                end

         file.puts "mkdir -p #{dst_path}" % [dst_path]
         file.puts "mount -n --bind #{src_path} #{dst_path}"
         file.puts "mount -n --bind -o remount,#{mode} #{src_path} #{dst_path}"
       end
     end
   end


2012-09-13                                NTT Software Innovation Center                  23
Dropletの展開
  コンテナ上でtarコマンドを実行


   def promise_extract_droplet
     Promise.new do |p|
       connection = promise_warden_connection(:app).resolve
       script = "tar zxf #{droplet.droplet_path}"

         promise_warden_run(connection, script).resolve

       p.deliver
     end
   end




2012-09-13                   NTT Software Innovation Center   24
スタートアップスクリプトの調整
  アプリケーション起動スクリプトのプレースホル
   ダを置換する
      – @がデリミタ

   def promise_prepare_start_script
     Promise.new do |p|
       connection = promise_warden_connection(:app).resolve
       script = "sed -i
   's@%VCAP_LOCAL_RUNTIME%@#{runtime.executable}@g' startup"

         promise_warden_run(connection, script).resolve

       p.deliver
     end
   end




2012-09-13                   NTT Software Innovation Center    25
スタートアップスクリプトの呼び出し
   def promise_start
     Promise.new do |p|
       script = []
       script << "renice 0 $$"
       script << "ulimit -n %d" % self.file_descriptor_limit
       script << "ulimit -u %d" % 512
       script << "umask 077"

       env = Env.new(self)
       env.env.each do |(key, value)|
         script << "export %s=%s" % [key, value]
       end

       startup = "./startup"

       # Pass port to `startup` if we have one
       if self.instance_host_port
         startup << " -p %d" % self.instance_host_port
       end

       script << startup
       script << "exit"

       connection = promise_warden_connection(:app).resolve

       request = ::Warden::Protocol::SpawnRequest.new
       request.handle = attributes["warden_handle"]
       request.script = script.join("¥n")
       response = promise_warden_call(connection, request).resolve

       attributes["warden_job_id"] = response.job_id

       p.deliver
     end
   end

2012-09-13                                   NTT Software Innovation Center   26
Promise パターンについて




2012-09-13       NTT Software Innovation Center   27
Promise(future)パターンとは

 DEA::InstanceがPromiseまみれになった

             • 非同期プログラミング
              – Wardenとの通信が発生する


             • ブロックを避けたい
              – Wardenの処理待ち中ブロックされたくない


             • deferredに似てる
              – JavaScriptプログラマーにはおなじみ



2012-09-13              NTT Software Innovation Center   28
イメージ

 処理AのIO待ち中に処理Bを済ませておきたい

             • 処理Aをスタートし、引換券(Promise)をもらう

             • IO待ち中に処理Bを開始する

             • どうしても処理Aの結果がほしくなったら引換券を
               実際の値に交換してもらう(resolve)

             • 処理Aは結果が出たら値を記録しておく
               (deliver)



2012-09-13             NTT Software Innovation Center   29

Más contenido relacionado

La actualidad más candente

めんどうくさくないWardenハンズオン
めんどうくさくないWardenハンズオンめんどうくさくないWardenハンズオン
めんどうくさくないWardenハンズオンi_yudai
 
あの日実行したコンテナの名前を僕達はまだ知らない。
あの日実行したコンテナの名前を僕達はまだ知らない。あの日実行したコンテナの名前を僕達はまだ知らない。
あの日実行したコンテナの名前を僕達はまだ知らない。Masahito Zembutsu
 
すごいBOSHたのしく学ぼう
すごいBOSHたのしく学ぼうすごいBOSHたのしく学ぼう
すごいBOSHたのしく学ぼうi_yudai
 
Using Kubernetes on Google Container Engine
Using Kubernetes on Google Container EngineUsing Kubernetes on Google Container Engine
Using Kubernetes on Google Container EngineEtsuji Nakai
 
ネットワークエンジニアのための Puppet / Chef
ネットワークエンジニアのための Puppet / Chefネットワークエンジニアのための Puppet / Chef
ネットワークエンジニアのための Puppet / Chefnpsg
 
Docker volume基礎/Project Longhorn紹介
Docker volume基礎/Project Longhorn紹介Docker volume基礎/Project Longhorn紹介
Docker volume基礎/Project Longhorn紹介Masahito Zembutsu
 
Wardenで学ぶコンテナの基礎
Wardenで学ぶコンテナの基礎Wardenで学ぶコンテナの基礎
Wardenで学ぶコンテナの基礎Hiroaki_UKAJI
 
爆速プレビュープロキシ pool
爆速プレビュープロキシ pool爆速プレビュープロキシ pool
爆速プレビュープロキシ poolmookjp
 
cf-containers-broker を使ってローカル環境もサービスの恩恵をうける
cf-containers-broker を使ってローカル環境もサービスの恩恵をうけるcf-containers-broker を使ってローカル環境もサービスの恩恵をうける
cf-containers-broker を使ってローカル環境もサービスの恩恵をうけるTakeshi Morikawa
 
Cloud Foundry Admin UI v2を使ってみた
Cloud Foundry Admin UI v2を使ってみたCloud Foundry Admin UI v2を使ってみた
Cloud Foundry Admin UI v2を使ってみたi_yudai
 
Docker hands on nifty sakura jul19
Docker hands on nifty sakura jul19Docker hands on nifty sakura jul19
Docker hands on nifty sakura jul19Masahito Zembutsu
 
【dots. IT勉強会】開発環境のDocker化
【dots. IT勉強会】開発環境のDocker化【dots. IT勉強会】開発環境のDocker化
【dots. IT勉強会】開発環境のDocker化Yuki Kanazawa
 
Docker on RHEL & Project Atomic 入門 - #Dockerjp 4
Docker on RHEL & Project Atomic 入門 - #Dockerjp 4Docker on RHEL & Project Atomic 入門 - #Dockerjp 4
Docker on RHEL & Project Atomic 入門 - #Dockerjp 4Emma Haruka Iwao
 
DockerでWordPressサイトを開発してみよう
DockerでWordPressサイトを開発してみようDockerでWordPressサイトを開発してみよう
DockerでWordPressサイトを開発してみようmookjp
 
LL言語でもHudsonを使おう!
LL言語でもHudsonを使おう!LL言語でもHudsonを使おう!
LL言語でもHudsonを使おう!KLab株式会社
 
JAWS-UG コンテナ支部 Docker入門 ハンズオン
JAWS-UG コンテナ支部 Docker入門 ハンズオンJAWS-UG コンテナ支部 Docker入門 ハンズオン
JAWS-UG コンテナ支部 Docker入門 ハンズオンRyo Nakamaru
 
Infinite Debian - Platform for mass-producing system every second
Infinite Debian - Platform for mass-producing system every secondInfinite Debian - Platform for mass-producing system every second
Infinite Debian - Platform for mass-producing system every secondTaisuke Yamada
 
Docker向け軽量os 3製品比較
Docker向け軽量os 3製品比較Docker向け軽量os 3製品比較
Docker向け軽量os 3製品比較cloudconductor
 
【18-E-3】クラウド・ネイティブ時代の2016年だから始める Docker 基礎講座
【18-E-3】クラウド・ネイティブ時代の2016年だから始める Docker 基礎講座【18-E-3】クラウド・ネイティブ時代の2016年だから始める Docker 基礎講座
【18-E-3】クラウド・ネイティブ時代の2016年だから始める Docker 基礎講座Masahito Zembutsu
 
Docker Swarm モード にゅうもん
Docker Swarm モード にゅうもんDocker Swarm モード にゅうもん
Docker Swarm モード にゅうもんMasahito Zembutsu
 

La actualidad más candente (20)

めんどうくさくないWardenハンズオン
めんどうくさくないWardenハンズオンめんどうくさくないWardenハンズオン
めんどうくさくないWardenハンズオン
 
あの日実行したコンテナの名前を僕達はまだ知らない。
あの日実行したコンテナの名前を僕達はまだ知らない。あの日実行したコンテナの名前を僕達はまだ知らない。
あの日実行したコンテナの名前を僕達はまだ知らない。
 
すごいBOSHたのしく学ぼう
すごいBOSHたのしく学ぼうすごいBOSHたのしく学ぼう
すごいBOSHたのしく学ぼう
 
Using Kubernetes on Google Container Engine
Using Kubernetes on Google Container EngineUsing Kubernetes on Google Container Engine
Using Kubernetes on Google Container Engine
 
ネットワークエンジニアのための Puppet / Chef
ネットワークエンジニアのための Puppet / Chefネットワークエンジニアのための Puppet / Chef
ネットワークエンジニアのための Puppet / Chef
 
Docker volume基礎/Project Longhorn紹介
Docker volume基礎/Project Longhorn紹介Docker volume基礎/Project Longhorn紹介
Docker volume基礎/Project Longhorn紹介
 
Wardenで学ぶコンテナの基礎
Wardenで学ぶコンテナの基礎Wardenで学ぶコンテナの基礎
Wardenで学ぶコンテナの基礎
 
爆速プレビュープロキシ pool
爆速プレビュープロキシ pool爆速プレビュープロキシ pool
爆速プレビュープロキシ pool
 
cf-containers-broker を使ってローカル環境もサービスの恩恵をうける
cf-containers-broker を使ってローカル環境もサービスの恩恵をうけるcf-containers-broker を使ってローカル環境もサービスの恩恵をうける
cf-containers-broker を使ってローカル環境もサービスの恩恵をうける
 
Cloud Foundry Admin UI v2を使ってみた
Cloud Foundry Admin UI v2を使ってみたCloud Foundry Admin UI v2を使ってみた
Cloud Foundry Admin UI v2を使ってみた
 
Docker hands on nifty sakura jul19
Docker hands on nifty sakura jul19Docker hands on nifty sakura jul19
Docker hands on nifty sakura jul19
 
【dots. IT勉強会】開発環境のDocker化
【dots. IT勉強会】開発環境のDocker化【dots. IT勉強会】開発環境のDocker化
【dots. IT勉強会】開発環境のDocker化
 
Docker on RHEL & Project Atomic 入門 - #Dockerjp 4
Docker on RHEL & Project Atomic 入門 - #Dockerjp 4Docker on RHEL & Project Atomic 入門 - #Dockerjp 4
Docker on RHEL & Project Atomic 入門 - #Dockerjp 4
 
DockerでWordPressサイトを開発してみよう
DockerでWordPressサイトを開発してみようDockerでWordPressサイトを開発してみよう
DockerでWordPressサイトを開発してみよう
 
LL言語でもHudsonを使おう!
LL言語でもHudsonを使おう!LL言語でもHudsonを使おう!
LL言語でもHudsonを使おう!
 
JAWS-UG コンテナ支部 Docker入門 ハンズオン
JAWS-UG コンテナ支部 Docker入門 ハンズオンJAWS-UG コンテナ支部 Docker入門 ハンズオン
JAWS-UG コンテナ支部 Docker入門 ハンズオン
 
Infinite Debian - Platform for mass-producing system every second
Infinite Debian - Platform for mass-producing system every secondInfinite Debian - Platform for mass-producing system every second
Infinite Debian - Platform for mass-producing system every second
 
Docker向け軽量os 3製品比較
Docker向け軽量os 3製品比較Docker向け軽量os 3製品比較
Docker向け軽量os 3製品比較
 
【18-E-3】クラウド・ネイティブ時代の2016年だから始める Docker 基礎講座
【18-E-3】クラウド・ネイティブ時代の2016年だから始める Docker 基礎講座【18-E-3】クラウド・ネイティブ時代の2016年だから始める Docker 基礎講座
【18-E-3】クラウド・ネイティブ時代の2016年だから始める Docker 基礎講座
 
Docker Swarm モード にゅうもん
Docker Swarm モード にゅうもんDocker Swarm モード にゅうもん
Docker Swarm モード にゅうもん
 

Destacado

816 b dd01 neap 2011mut
816 b dd01 neap 2011mut816 b dd01 neap 2011mut
816 b dd01 neap 2011mutmelodyn tabamo
 
הראיות לפסיכולוגיה מונחית ראיות
הראיות לפסיכולוגיה מונחית ראיותהראיות לפסיכולוגיה מונחית ראיות
הראיות לפסיכולוגיה מונחית ראיותTsviGil
 
Integrating omic approaches to investigate the gut microbiota, School of Bios...
Integrating omic approaches to investigate the gut microbiota, School of Bios...Integrating omic approaches to investigate the gut microbiota, School of Bios...
Integrating omic approaches to investigate the gut microbiota, School of Bios...Copenhagenomics
 
The PPACTE survey on the economic aspects of smoking in Europe
The PPACTE survey on the economic aspects of smoking in EuropeThe PPACTE survey on the economic aspects of smoking in Europe
The PPACTE survey on the economic aspects of smoking in EuropeUCT ICO
 
Aug 31 2012 WEBQUEST
Aug 31 2012 WEBQUESTAug 31 2012 WEBQUEST
Aug 31 2012 WEBQUESTRachael Mann
 
Health and safety ppe
Health and safety ppeHealth and safety ppe
Health and safety ppehpinn
 
07 bio มข
07 bio มข07 bio มข
07 bio มขBiobiome
 
Reasons why your email marketing isn’t working
Reasons why your email marketing isn’t workingReasons why your email marketing isn’t working
Reasons why your email marketing isn’t workingdatadoctor
 
Suomen rakennerahasto-ohjelma2014-2020
Suomen rakennerahasto-ohjelma2014-2020Suomen rakennerahasto-ohjelma2014-2020
Suomen rakennerahasto-ohjelma2014-2020lansisuomenhelmet
 
ECONOMY OF CULTURE IN EUROPE
ECONOMY OF CULTURE IN EUROPEECONOMY OF CULTURE IN EUROPE
ECONOMY OF CULTURE IN EUROPEpesec
 
17102413 otisci-bogova
17102413 otisci-bogova17102413 otisci-bogova
17102413 otisci-bogovacosmoi
 
Discovery of Cow Rumen Biomass-Degrading Genes and Genomes through DNA Sequen...
Discovery of Cow Rumen Biomass-Degrading Genes and Genomes through DNA Sequen...Discovery of Cow Rumen Biomass-Degrading Genes and Genomes through DNA Sequen...
Discovery of Cow Rumen Biomass-Degrading Genes and Genomes through DNA Sequen...Copenhagenomics
 

Destacado (16)

816 b dd01 neap 2011mut
816 b dd01 neap 2011mut816 b dd01 neap 2011mut
816 b dd01 neap 2011mut
 
הראיות לפסיכולוגיה מונחית ראיות
הראיות לפסיכולוגיה מונחית ראיותהראיות לפסיכולוגיה מונחית ראיות
הראיות לפסיכולוגיה מונחית ראיות
 
Latiff
LatiffLatiff
Latiff
 
Integrating omic approaches to investigate the gut microbiota, School of Bios...
Integrating omic approaches to investigate the gut microbiota, School of Bios...Integrating omic approaches to investigate the gut microbiota, School of Bios...
Integrating omic approaches to investigate the gut microbiota, School of Bios...
 
ccnp route 642 902
ccnp route 642 902ccnp route 642 902
ccnp route 642 902
 
The PPACTE survey on the economic aspects of smoking in Europe
The PPACTE survey on the economic aspects of smoking in EuropeThe PPACTE survey on the economic aspects of smoking in Europe
The PPACTE survey on the economic aspects of smoking in Europe
 
Aug 31 2012 WEBQUEST
Aug 31 2012 WEBQUESTAug 31 2012 WEBQUEST
Aug 31 2012 WEBQUEST
 
Health and safety ppe
Health and safety ppeHealth and safety ppe
Health and safety ppe
 
Eu future tense posted
Eu future tense postedEu future tense posted
Eu future tense posted
 
07 bio มข
07 bio มข07 bio มข
07 bio มข
 
Reasons why your email marketing isn’t working
Reasons why your email marketing isn’t workingReasons why your email marketing isn’t working
Reasons why your email marketing isn’t working
 
Suomen rakennerahasto-ohjelma2014-2020
Suomen rakennerahasto-ohjelma2014-2020Suomen rakennerahasto-ohjelma2014-2020
Suomen rakennerahasto-ohjelma2014-2020
 
ECONOMY OF CULTURE IN EUROPE
ECONOMY OF CULTURE IN EUROPEECONOMY OF CULTURE IN EUROPE
ECONOMY OF CULTURE IN EUROPE
 
17102413 otisci-bogova
17102413 otisci-bogova17102413 otisci-bogova
17102413 otisci-bogova
 
Rails3 asset-pipeline
Rails3 asset-pipelineRails3 asset-pipeline
Rails3 asset-pipeline
 
Discovery of Cow Rumen Biomass-Degrading Genes and Genomes through DNA Sequen...
Discovery of Cow Rumen Biomass-Degrading Genes and Genomes through DNA Sequen...Discovery of Cow Rumen Biomass-Degrading Genes and Genomes through DNA Sequen...
Discovery of Cow Rumen Biomass-Degrading Genes and Genomes through DNA Sequen...
 

Similar a マスタリング DEA/NG 第2版

"Up" with vagrant and docker
"Up" with vagrant and docker"Up" with vagrant and docker
"Up" with vagrant and dockerHiroshi Miura
 
名古屋Ruby会議01 A3.製造業向け3Dデータ変換ソリューションにおけるRuby活用事例
名古屋Ruby会議01 A3.製造業向け3Dデータ変換ソリューションにおけるRuby活用事例名古屋Ruby会議01 A3.製造業向け3Dデータ変換ソリューションにおけるRuby活用事例
名古屋Ruby会議01 A3.製造業向け3Dデータ変換ソリューションにおけるRuby活用事例Shigeru UCHIYAMA
 
"Up" with vagrant and docker
"Up" with vagrant and docker"Up" with vagrant and docker
"Up" with vagrant and dockerHiroshi Miura
 
20140612_Docker上でCloudStackを動かしてみる!!
20140612_Docker上でCloudStackを動かしてみる!!20140612_Docker上でCloudStackを動かしてみる!!
20140612_Docker上でCloudStackを動かしてみる!!Midori Oge
 
Android程序的编译,安装和运行 | 小米科技 汪文俊
Android程序的编译,安装和运行 | 小米科技 汪文俊Android程序的编译,安装和运行 | 小米科技 汪文俊
Android程序的编译,安装和运行 | 小米科技 汪文俊imShining @DevCamp
 
13016 n分で作るtype scriptでnodejs
13016 n分で作るtype scriptでnodejs13016 n分で作るtype scriptでnodejs
13016 n分で作るtype scriptでnodejsTakayoshi Tanaka
 
WebRTC meetup Tokyo 1
WebRTC meetup  Tokyo 1WebRTC meetup  Tokyo 1
WebRTC meetup Tokyo 1mganeko
 
Sflt17 meteorではじめる最速ウェブアプリ開発
Sflt17 meteorではじめる最速ウェブアプリ開発Sflt17 meteorではじめる最速ウェブアプリ開発
Sflt17 meteorではじめる最速ウェブアプリ開発Hironao Sekine
 
泥臭い運用から、プログラマブルインフラ構築(に行きたい)
泥臭い運用から、プログラマブルインフラ構築(に行きたい) 泥臭い運用から、プログラマブルインフラ構築(に行きたい)
泥臭い運用から、プログラマブルインフラ構築(に行きたい) Akihiro Kuwano
 
2019年度 CaaS ワークショップ @ NTTコム
2019年度 CaaS ワークショップ @ NTTコム2019年度 CaaS ワークショップ @ NTTコム
2019年度 CaaS ワークショップ @ NTTコムTomoyaTakegoshi
 
【16-D-4】3分ではじめるスマホアプリのビジュアル開発
【16-D-4】3分ではじめるスマホアプリのビジュアル開発【16-D-4】3分ではじめるスマホアプリのビジュアル開発
【16-D-4】3分ではじめるスマホアプリのビジュアル開発hmimura_embarcadero
 
オススメのJavaログ管理手法 ~コンテナ編~(Open Source Conference 2022 Online/Spring 発表資料)
オススメのJavaログ管理手法 ~コンテナ編~(Open Source Conference 2022 Online/Spring 発表資料)オススメのJavaログ管理手法 ~コンテナ編~(Open Source Conference 2022 Online/Spring 発表資料)
オススメのJavaログ管理手法 ~コンテナ編~(Open Source Conference 2022 Online/Spring 発表資料)NTT DATA Technology & Innovation
 
Docker ComposeでMastodonが必要なものを梱包する話
Docker ComposeでMastodonが必要なものを梱包する話Docker ComposeでMastodonが必要なものを梱包する話
Docker ComposeでMastodonが必要なものを梱包する話Masahito Zembutsu
 
Db2 Warehouse Spark利用ガイド チュートリアル編
Db2 Warehouse Spark利用ガイド チュートリアル編Db2 Warehouse Spark利用ガイド チュートリアル編
Db2 Warehouse Spark利用ガイド チュートリアル編IBM Analytics Japan
 
DPDKによる高速コンテナネットワーキング
DPDKによる高速コンテナネットワーキングDPDKによる高速コンテナネットワーキング
DPDKによる高速コンテナネットワーキングTomoya Hibi
 
Cloud Foundry構成概要 111018
Cloud Foundry構成概要 111018Cloud Foundry構成概要 111018
Cloud Foundry構成概要 111018Uemura Yuichi
 
SDLoader SeasarCon 2009 Whire
SDLoader SeasarCon 2009 WhireSDLoader SeasarCon 2009 Whire
SDLoader SeasarCon 2009 WhireAkio Katayama
 
Build 番号の自動更新スクリプトについて #cocoa_kansai
Build 番号の自動更新スクリプトについて #cocoa_kansaiBuild 番号の自動更新スクリプトについて #cocoa_kansai
Build 番号の自動更新スクリプトについて #cocoa_kansaiTomohiro Kumagai
 
ネットワークコマンド入力に対応したツール事例
ネットワークコマンド入力に対応したツール事例ネットワークコマンド入力に対応したツール事例
ネットワークコマンド入力に対応したツール事例fumoto kazuhiro
 

Similar a マスタリング DEA/NG 第2版 (20)

"Up" with vagrant and docker
"Up" with vagrant and docker"Up" with vagrant and docker
"Up" with vagrant and docker
 
名古屋Ruby会議01 A3.製造業向け3Dデータ変換ソリューションにおけるRuby活用事例
名古屋Ruby会議01 A3.製造業向け3Dデータ変換ソリューションにおけるRuby活用事例名古屋Ruby会議01 A3.製造業向け3Dデータ変換ソリューションにおけるRuby活用事例
名古屋Ruby会議01 A3.製造業向け3Dデータ変換ソリューションにおけるRuby活用事例
 
"Up" with vagrant and docker
"Up" with vagrant and docker"Up" with vagrant and docker
"Up" with vagrant and docker
 
20140612_Docker上でCloudStackを動かしてみる!!
20140612_Docker上でCloudStackを動かしてみる!!20140612_Docker上でCloudStackを動かしてみる!!
20140612_Docker上でCloudStackを動かしてみる!!
 
Android程序的编译,安装和运行 | 小米科技 汪文俊
Android程序的编译,安装和运行 | 小米科技 汪文俊Android程序的编译,安装和运行 | 小米科技 汪文俊
Android程序的编译,安装和运行 | 小米科技 汪文俊
 
13016 n分で作るtype scriptでnodejs
13016 n分で作るtype scriptでnodejs13016 n分で作るtype scriptでnodejs
13016 n分で作るtype scriptでnodejs
 
WebRTC meetup Tokyo 1
WebRTC meetup  Tokyo 1WebRTC meetup  Tokyo 1
WebRTC meetup Tokyo 1
 
Sflt17 meteorではじめる最速ウェブアプリ開発
Sflt17 meteorではじめる最速ウェブアプリ開発Sflt17 meteorではじめる最速ウェブアプリ開発
Sflt17 meteorではじめる最速ウェブアプリ開発
 
泥臭い運用から、プログラマブルインフラ構築(に行きたい)
泥臭い運用から、プログラマブルインフラ構築(に行きたい) 泥臭い運用から、プログラマブルインフラ構築(に行きたい)
泥臭い運用から、プログラマブルインフラ構築(に行きたい)
 
2019年度 CaaS ワークショップ @ NTTコム
2019年度 CaaS ワークショップ @ NTTコム2019年度 CaaS ワークショップ @ NTTコム
2019年度 CaaS ワークショップ @ NTTコム
 
【16-D-4】3分ではじめるスマホアプリのビジュアル開発
【16-D-4】3分ではじめるスマホアプリのビジュアル開発【16-D-4】3分ではじめるスマホアプリのビジュアル開発
【16-D-4】3分ではじめるスマホアプリのビジュアル開発
 
オススメのJavaログ管理手法 ~コンテナ編~(Open Source Conference 2022 Online/Spring 発表資料)
オススメのJavaログ管理手法 ~コンテナ編~(Open Source Conference 2022 Online/Spring 発表資料)オススメのJavaログ管理手法 ~コンテナ編~(Open Source Conference 2022 Online/Spring 発表資料)
オススメのJavaログ管理手法 ~コンテナ編~(Open Source Conference 2022 Online/Spring 発表資料)
 
Docker ComposeでMastodonが必要なものを梱包する話
Docker ComposeでMastodonが必要なものを梱包する話Docker ComposeでMastodonが必要なものを梱包する話
Docker ComposeでMastodonが必要なものを梱包する話
 
Db2 Warehouse Spark利用ガイド チュートリアル編
Db2 Warehouse Spark利用ガイド チュートリアル編Db2 Warehouse Spark利用ガイド チュートリアル編
Db2 Warehouse Spark利用ガイド チュートリアル編
 
DPDKによる高速コンテナネットワーキング
DPDKによる高速コンテナネットワーキングDPDKによる高速コンテナネットワーキング
DPDKによる高速コンテナネットワーキング
 
Cloud Foundry構成概要 111018
Cloud Foundry構成概要 111018Cloud Foundry構成概要 111018
Cloud Foundry構成概要 111018
 
SDLoader SeasarCon 2009 Whire
SDLoader SeasarCon 2009 WhireSDLoader SeasarCon 2009 Whire
SDLoader SeasarCon 2009 Whire
 
perfを使ったPostgreSQLの解析(後編)
perfを使ったPostgreSQLの解析(後編)perfを使ったPostgreSQLの解析(後編)
perfを使ったPostgreSQLの解析(後編)
 
Build 番号の自動更新スクリプトについて #cocoa_kansai
Build 番号の自動更新スクリプトについて #cocoa_kansaiBuild 番号の自動更新スクリプトについて #cocoa_kansai
Build 番号の自動更新スクリプトについて #cocoa_kansai
 
ネットワークコマンド入力に対応したツール事例
ネットワークコマンド入力に対応したツール事例ネットワークコマンド入力に対応したツール事例
ネットワークコマンド入力に対応したツール事例
 

Último

論文紹介:Semantic segmentation using Vision Transformers: A survey
論文紹介:Semantic segmentation using Vision Transformers: A survey論文紹介:Semantic segmentation using Vision Transformers: A survey
論文紹介:Semantic segmentation using Vision Transformers: A surveyToru Tamaki
 
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...Toru Tamaki
 
論文紹介:Automated Classification of Model Errors on ImageNet
論文紹介:Automated Classification of Model Errors on ImageNet論文紹介:Automated Classification of Model Errors on ImageNet
論文紹介:Automated Classification of Model Errors on ImageNetToru Tamaki
 
TSAL operation mechanism and circuit diagram.pdf
TSAL operation mechanism and circuit diagram.pdfTSAL operation mechanism and circuit diagram.pdf
TSAL operation mechanism and circuit diagram.pdftaisei2219
 
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介Yuma Ohgami
 
SOPを理解する 2024/04/19 の勉強会で発表されたものです
SOPを理解する       2024/04/19 の勉強会で発表されたものですSOPを理解する       2024/04/19 の勉強会で発表されたものです
SOPを理解する 2024/04/19 の勉強会で発表されたものですiPride Co., Ltd.
 
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略Ryo Sasaki
 
Postman LT Fukuoka_Quick Prototype_By Daniel
Postman LT Fukuoka_Quick Prototype_By DanielPostman LT Fukuoka_Quick Prototype_By Daniel
Postman LT Fukuoka_Quick Prototype_By Danieldanielhu54
 
スマートフォンを用いた新生児あやし動作の教示システム
スマートフォンを用いた新生児あやし動作の教示システムスマートフォンを用いた新生児あやし動作の教示システム
スマートフォンを用いた新生児あやし動作の教示システムsugiuralab
 

Último (9)

論文紹介:Semantic segmentation using Vision Transformers: A survey
論文紹介:Semantic segmentation using Vision Transformers: A survey論文紹介:Semantic segmentation using Vision Transformers: A survey
論文紹介:Semantic segmentation using Vision Transformers: A survey
 
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
 
論文紹介:Automated Classification of Model Errors on ImageNet
論文紹介:Automated Classification of Model Errors on ImageNet論文紹介:Automated Classification of Model Errors on ImageNet
論文紹介:Automated Classification of Model Errors on ImageNet
 
TSAL operation mechanism and circuit diagram.pdf
TSAL operation mechanism and circuit diagram.pdfTSAL operation mechanism and circuit diagram.pdf
TSAL operation mechanism and circuit diagram.pdf
 
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
 
SOPを理解する 2024/04/19 の勉強会で発表されたものです
SOPを理解する       2024/04/19 の勉強会で発表されたものですSOPを理解する       2024/04/19 の勉強会で発表されたものです
SOPを理解する 2024/04/19 の勉強会で発表されたものです
 
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略
 
Postman LT Fukuoka_Quick Prototype_By Daniel
Postman LT Fukuoka_Quick Prototype_By DanielPostman LT Fukuoka_Quick Prototype_By Daniel
Postman LT Fukuoka_Quick Prototype_By Daniel
 
スマートフォンを用いた新生児あやし動作の教示システム
スマートフォンを用いた新生児あやし動作の教示システムスマートフォンを用いた新生児あやし動作の教示システム
スマートフォンを用いた新生児あやし動作の教示システム
 

マスタリング DEA/NG 第2版

  • 1. マスタリング DEA/NG 第2版 岩嵜 雄大 NTT Software Innovation Center 2012-09-13 NTT Software Innovation Center
  • 2. はじめに  情報はすべて資料作成当時のものです – 更新が頻繁なため情報がすぐに古くなります – 必ず最新のソースコードを確認してください 2012-09-13 NTT Software Innovation Center 2
  • 3. 今日の内容  そもそもDEAとは – 簡単な紹介  DEA_NG起動から、Warden上でのアプリ ケーション実行までを追う – エントリーポイントからインスタンス起動まで  Promiseパターンについて – DEA_NGに頻出するPromiseとは何者か 2012-09-13 NTT Software Innovation Center 3
  • 4. そもそもDEAとは 2012-09-13 NTT Software Innovation Center 4
  • 5. DEAとは  ユーザのアプリケーションを実行するためのコン ポーネント – Dropletと呼ばれる形式のアプリケーションを実行する – DEAを増やすことでCloud Foundryの実行能力はスケー ルする App App App App App App App App App App App DEA App App DEA App App App DEA DEA 2012-09-13 NTT Software Innovation Center 5
  • 6. DEAがやること  Dropletのダウンロード  ランタイム(Java, Ruby, etc)の管理  アプリケーション隔離用コンテナの管理 – コンテナには独自の「Warden」を使用  アプリケーションの管理・死活監視 2012-09-13 NTT Software Innovation Center 6
  • 7. DEAサーバの起動から アプリケーションの起動まで 2012-09-13 NTT Software Innovation Center 7
  • 8. 全体的な概念図(今日話す範囲) DEA Instance Instance Instance Instance 1対1対応で生成や起動などを担当 通信はWarden Protocol 生成 CCからの命令 NATS 基本的には イベントドリブン App App App App App DEAプロセスの セットアップ ContainerContainerContainer ContainerContainer bin/dea BootStrap Warden VM ※他にもDroplet RegistryやDirectory Serverなどがサブモジュールがある 2012-09-13 NTT Software Innovation Center 8
  • 9. エントリーポイント  /bin/dea bootstrap = Dea::Bootstrap.new(config) EM.run do bootstrap.setup bootstrap.start end – コマンドライン引数のパース – DEAプロセスをキック 2012-09-13 NTT Software Innovation Center 9
  • 10. DEA serverの起動  /lib/dea/bootstrap.rb – プロセスの初期セットアップ (setup_*) – NATSクライアントの起動 • あとはNATSまかせ def start start_component start_nats start_directory_server start_finish end … def setup_nats @nats = Dea::Nats.new(self, config) end 2012-09-13 NTT Software Innovation Center 10
  • 11. NATSに対するディスパッチャーの登録  /lib/dea/nats.rb – アプリケーションインスタンスの起動イベント def start … subscribe("dea.#{bootstrap.uuid}.start") do |message| bootstrap.handle_dea_directed_start(message) end … end def subscribe(subject) sid = client.subscribe(subject) do |raw_data, respond_to| message = Message.decode(self, subject, raw_data, respond_to) logger.debug "Received on #{subject.inspect}: #{message.data.inspect}" yield message end @sids[subject] = sid end 2012-09-13 NTT Software Innovation Center 11
  • 12. Bootstrap側のハンドラ  DEA::Instance オブジェクトを生成 – オブジェクトはレジストリに登録する def handle_dea_directed_start(message) instance = create_instance(message.data) … instance.start end … def create_instance(attributes) instance = Instance.new(self, Instance.translate_attributes(attributes)) instance.on(Instance::Transition.new(:born, :starting)) do instance_registry.register(instance) end … (他のインスタンス状態変化トリガ) instance end 2012-09-13 NTT Software Innovation Center 12
  • 13. インスタンスの起動  /lib/dea/instance.rb – Promiseについては後述 def start(&callback) … if !droplet.droplet_exist? logger.info("Starting droplet download") … promise_droplet_download.resolve ドロップレット end をダウンロード promise_container = Promise.new do |p| promise_create_container.resolve promise_setup_network.resolve promise_limit_disk.resolve promise_limit_memory.resolve コンテナの準備 p.deliver end … promise_extract_droplet.resolve promise_prepare_start_script.resolve インスタンスの … promise_start.resolve 起動 end 2012-09-13 NTT Software Innovation Center 13
  • 14. コンテナの生成設定  DEAホストのDropletとランタイムをコンテナ内 から見えるように追加のマウント情報を設定 def promise_create_container … connection = promise_warden_connection(:app).resolve # Droplet and runtime bind_mounts = [droplet.droplet_dirname, runtime.dirname].map do |path| bind_mount = ::Warden::Protocol::CreateRequest::BindMount.new bind_mount.src_path = path bind_mount.dst_path = path bind_mount.mode = ::Warden::Protocol::CreateRequest::BindMount::Mode::RO bind_mount end …次ページに続く 2012-09-13 NTT Software Innovation Center 14
  • 15. コンテナの生成設定  ライブラリ類もマウントとして追加 …前ページから # Extra mounts (these typically include libs like pq, mysql, etc) bootstrap.config["bind_mounts"].each do |bm| bind_mount = ::Warden::Protocol::CreateRequest::BindMount.new bind_mount.src_path = bm["src_path"] bind_mount.dst_path = bm["dst_path"] || bm["src_path"] mode = bm["mode"] || "ro" bind_mount.mode = BIND_MOUNT_MODE_MAP[mode] bind_mounts << bind_mount end …次ページへ 2012-09-13 NTT Software Innovation Center 15
  • 16. アプリケーションインスタンスの実行  Warden Protocolによりコンテナを起動 …前ページから create_request = ::Warden::Protocol::CreateRequest.new create_request.bind_mounts = bind_mounts response =promise_warden_call (connection, create_request).resolve … end end  コンテナ起動後にメモリとディスクの制限を行う – promise_setup_network – promise_limit_disk – promise_limit_memory 2012-09-13 NTT Software Innovation Center 16
  • 17. 【寄り道】 promise_warden_callで何が起きているのか  connectionは EM::Warden::Client::Connection def promise_warden_call(connection, request) Promise.new do |p| logger.debug2(request.inspect) connection.call(request) do |result| logger.debug2(result.inspect) … if error logger.warn "Request failed: #{request.inspect}" logger.log_exception(error) p.fail(error) else p.deliver(response) end end … end 2012-09-13 NTT Software Innovation Center 17
  • 18. 【寄り道】 Warden Clientの話  Warden本体については「すごく分かるWarden」 – http://www.slideshare.net/i_yudai/warden  3つのライブラリ – warden-client • Unix Socketによる(簡易な)実装 • ライブラリ的なものも含む – em-warden-client • EventMachineを使用した実装 • warden-clientに依存 – warden-protocol • サーバクライアント間の通信に使うクラスのセット 2012-09-13 NTT Software Innovation Center 18
  • 19. 【寄り道】 Warden Protocol  Wardenに対する各種命令 • ping • run • create • info • stop • LimitDisk • spawn • LimitMemory • link • net_in • stream • net_out  コマンドラインコマンドとほぼ同等 ping - ping warden create [OPTION OPTION ...] - create container, optionally pass options. destroy <handle> - shutdown container <handle> stop <handle> - stop all processes in <handle> spawn <handle> cmd - spawns cmd inside container <handle>, returns #jobid link <handle> #jobid - do blocking read on results from #jobid stream <handle> #jobid - do blocking stream on results from #jobid run <handle> cmd - short hand for stream(spawn(cmd)) i.e. spawns cmd, streams the result list - list containers info <handle> - show metadata for container <handle> limit <handle> mem [<value>] - set or get the memory limit for the container (in bytes) net <handle> #in - forward port #in on external interface to container <handle> net <handle> #out <address[/mask][:port]> - allow traffic from the container <handle> to address <address> 2012-09-13 NTT Software Innovation Center 19
  • 20. 【寄り道】 EM::Warden::FiberAwareClient  /em-warden-client/lib/em/warden/client.rb – create()メソッドは存在しない • method_missing()からcall()が呼ばれる def call(*args, &blk) … f = Fiber.current @connection.call(*args) {|res| f.resume(res) } result = Fiber.yield result.get EventMachine::Warden::Client::Connection end def method_missing(method, *args, &blk) call(method, *args, &blk) end 2012-09-13 NTT Software Innovation Center 20
  • 21. 【寄り道】 EM::Warden::FiberAwareClient  /em-warden-client/lib/em/warden/client.rb – create()メソッドは存在しない • method_missing()からcall()が呼ばれる def call(*args, &blk) … 使わなくなりました f = Fiber.current @connection.call(*args) {|res| f.resume(res) } result = Fiber.yield result.get EventMachine::Warden::Client::Connection end def method_missing(method, *args, &blk) call(method, *args, &blk) end 2012-09-13 NTT Software Innovation Center 21
  • 22. 【寄り道】 EventMachine::Warden::Client::Connection  /em-warden- client/lib/em/warden/client/connection.rb – EM::Connectionを継承 def call(*args, &blk) if args.first.kind_of?(::Warden::Protocol::BaseRequest) request = args.first Protocolオブジェクトが else 渡されている場合 … request = ::Warden::Client::V1.request_from_v1(args.dup) @v1mode = true argsに”create”が渡されていれば end Warden::Protocol::CreateRequest @request_queue << { :request => request, :callback => blk } process_queue end 2012-09-13 NTT Software Innovation Center 22
  • 23. 【寄り道】 コンテナ生成時におけるマウントの追加  /warden/warden/lib/warden/container/linux.rb – フックにマウントの命令を追加する def write_bind_mount_commands(request) return if request.bind_mounts.nil? || request.bind_mounts.empty? File.open(File.join(container_path, "hook-parent-before-clone.sh"), "a") do |file| … request.bind_mounts.each do |bind_mount| src_path = bind_mount.src_path dst_path = bind_mount.dst_path # Fix up destination path to be an absolute path inside the union dst_path = File.join(container_path, "union", dst_path[1..-1]) mode = case bind_mount.mode when Protocol::CreateRequest::BindMount::Mode::RO "ro" when Protocol::CreateRequest::BindMount::Mode::RW "rw" else raise "Unknown mode" end file.puts "mkdir -p #{dst_path}" % [dst_path] file.puts "mount -n --bind #{src_path} #{dst_path}" file.puts "mount -n --bind -o remount,#{mode} #{src_path} #{dst_path}" end end end 2012-09-13 NTT Software Innovation Center 23
  • 24. Dropletの展開  コンテナ上でtarコマンドを実行 def promise_extract_droplet Promise.new do |p| connection = promise_warden_connection(:app).resolve script = "tar zxf #{droplet.droplet_path}" promise_warden_run(connection, script).resolve p.deliver end end 2012-09-13 NTT Software Innovation Center 24
  • 25. スタートアップスクリプトの調整  アプリケーション起動スクリプトのプレースホル ダを置換する – @がデリミタ def promise_prepare_start_script Promise.new do |p| connection = promise_warden_connection(:app).resolve script = "sed -i 's@%VCAP_LOCAL_RUNTIME%@#{runtime.executable}@g' startup" promise_warden_run(connection, script).resolve p.deliver end end 2012-09-13 NTT Software Innovation Center 25
  • 26. スタートアップスクリプトの呼び出し def promise_start Promise.new do |p| script = [] script << "renice 0 $$" script << "ulimit -n %d" % self.file_descriptor_limit script << "ulimit -u %d" % 512 script << "umask 077" env = Env.new(self) env.env.each do |(key, value)| script << "export %s=%s" % [key, value] end startup = "./startup" # Pass port to `startup` if we have one if self.instance_host_port startup << " -p %d" % self.instance_host_port end script << startup script << "exit" connection = promise_warden_connection(:app).resolve request = ::Warden::Protocol::SpawnRequest.new request.handle = attributes["warden_handle"] request.script = script.join("¥n") response = promise_warden_call(connection, request).resolve attributes["warden_job_id"] = response.job_id p.deliver end end 2012-09-13 NTT Software Innovation Center 26
  • 27. Promise パターンについて 2012-09-13 NTT Software Innovation Center 27
  • 28. Promise(future)パターンとは DEA::InstanceがPromiseまみれになった • 非同期プログラミング – Wardenとの通信が発生する • ブロックを避けたい – Wardenの処理待ち中ブロックされたくない • deferredに似てる – JavaScriptプログラマーにはおなじみ 2012-09-13 NTT Software Innovation Center 28
  • 29. イメージ 処理AのIO待ち中に処理Bを済ませておきたい • 処理Aをスタートし、引換券(Promise)をもらう • IO待ち中に処理Bを開始する • どうしても処理Aの結果がほしくなったら引換券を 実際の値に交換してもらう(resolve) • 処理Aは結果が出たら値を記録しておく (deliver) 2012-09-13 NTT Software Innovation Center 29