Skip to content

Instantly share code, notes, and snippets.

@udzura

udzura/burn.md Secret

Last active December 9, 2016 10:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save udzura/709be894d7b6ddb80cd20583ceba28af to your computer and use it in GitHub Desktop.
Save udzura/709be894d7b6ddb80cd20583ceba28af to your computer and use it in GitHub Desktop.

デモ手順

  • 目標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