Create a gist now

Instantly share code, notes, and snippets.

@udzura /burn.md Secret
Last active Dec 9, 2016

デモ手順

  • 目標3~4分程度
  • mruby-vm の xenialでやる
  • DSLを見せる
$ cd ~/demo
$ vi tokyo.haco
  • cgroupの設定
  config.cgroup["cpuset.cpus"] = "0"
  config.cgroup["cpuset.mems"] = "0"
  config.cgroup["cpu.cfs_period_us"] = 100000
  config.cgroup["cpu.cfs_quota_us"]  =  30000
  • Rubyでフィボナッチをぶん回すコンテナ
sudo haconiwa run tokyo.haco -D -- \
  /usr/bin/ruby -e "def fib(n);n<2?1:fib(n-2)+fib(n-1);end;loop.with_index{|_,i|p fib(i)}"
  • 同じコンソールでhtopコマンドを打つ
$ htop
  • 別のコンソールでSIGTTIN/TTOUを打ってcgroup動的操作
$ ps auxf...
$ sudo kill -TTIN 12345
  • フックの箇所を見せる
  config.add_handler :TTIN do |b, sig|
    cpu = ::Cgroup::CPU.new(b.name)
    cpu.cfs_quota_us = cpu.cfs_quota_us - 10000
    if cpu.cfs_quota_us > 0
      cpu.modify
      Haconiwa::Logger.info "Changed cpu.cfs_quota_us = #{cpu.cfs_quota_us}"
    end
  end

  config.add_handler :TTOU do |b, sig|
    cpu = ::Cgroup::CPU.new(b.name)
    cpu.cfs_quota_us = cpu.cfs_quota_us + 10000
    if cpu.cfs_quota_us <= cpu.cfs_period_us
      cpu.modify
      Haconiwa::Logger.info "Changed cpu.cfs_quota_us = #{cpu.cfs_quota_us}"
    end
  end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment