ようへいの日々精進XP

よかろうもん

ruby-jmeter tips(1)

tl;dr

ruby-jmeter の tips というか、自分がハマった事などを雑にメモ。ハマったら追記してくことにする。


Throughput Shaping Timer を呼び出す際の注意

注意点

memo

variable_throughput_timer.rb

大体の場合、メソッドが記述されたファイル名を利用して以下のように呼べる(はず)。

require 'rubygems'require 'ruby-jmeter'test do
  threads count: 10 do
    visit name: 'example.com', url: 'http://example.com'
  end
  variable_throughput_timer
end.jmx(file: "sample.jmx")

しかし、シナリオを吐き出そうとすると...

/path/to/vendor/bundle/ruby/2.2.0/gems/ruby-jmeter-2.13.10/lib/ruby-jmeter/helpers/fallback_content_proxy.rb:44:in `__proxy_method__': undefined method `variable_throughput_timer' for #<RubyJmeter::ExtendedDSL:0x007fe95b84e198> (NoMethodError)
        from /path/to/vendor/bundle/ruby/2.2.0/gems/ruby-jmeter-2.13.10/lib/ruby-jmeter/helpers/fallback_content_proxy.rb:39:in `method_missing'
        from sample.rb:9:in `block in <main>'
        from /path/to/vendor/bundle/ruby/2.2.0/gems/ruby-jmeter-2.13.10/lib/ruby-jmeter/helpers/helper.rb:8:in `instance_eval'
        from /path/to/vendor/bundle/ruby/2.2.0/gems/ruby-jmeter-2.13.10/lib/ruby-jmeter/helpers/helper.rb:8:in `dsl_eval'
        from /path/to/vendor/bundle/ruby/2.2.0/gems/ruby-jmeter-2.13.10/lib/ruby-jmeter/dsl.rb:697:in `test'
        from sample.rb:4:in `<main>'

ん...困った。

  • 認識が誤っていた

メソッドが記述されたファイル名で呼び出せたのはタマタマだと思った方が良い。結局は、lib/ruby-jmeter/dsl.rb を見るのが正しい。

(snip)

    def throughput_shaper(name = 'Throughput Shaping Timer', steps=[], params = {}, &block)
      node = RubyJmeter::Plugins::ThroughputShapingTimer.new(name, steps)
      attach_node(node, &block)
    end

(snip)

上記のメソッド名で呼び出すのが正解。

  • 以下のように記述する
require 'rubygems'
require 'ruby-jmeter'

test do
  threads count: 10 do
    visit name: 'example.com', url: 'http://example.com'
  end
  throughput_shaper(
    name = "Throughput Shaping Timer",
    steps = [
      { start_rps: 1, end_rps: 10, duration: 10 },
      { start_rps: 10, end_rps: 10, duration: 10 },
      { start_rps: 10, end_rps: 1, duration: 10 }
    ]
  )
end.jmx(file: "sample.jmx")

以下のように吐き出される。

(snip)

     <kg.apc.jmeter.timers.VariableThroughputTimer guiclass="kg.apc.jmeter.timers.VariableThroughputTimerGui" testclass="kg.apc.jmeter.timers.VariableThroughputTimer" testname="Throughput Shaping Timer" enabled="true">
        <collectionProp name="load_profile">
          <collectionProp name="step_0">
            <stringProp name="start_rps_0">1</stringProp>
            <stringProp name="end_rps_0">10</stringProp>
            <stringProp name="duration_sec_0">10</stringProp>
          </collectionProp>
          <collectionProp name="step_1">
            <stringProp name="start_rps_1">10</stringProp>
            <stringProp name="end_rps_1">10</stringProp>
            <stringProp name="duration_sec_1">10</stringProp>
          </collectionProp>
          <collectionProp name="step_2">
            <stringProp name="start_rps_2">10</stringProp>
            <stringProp name="end_rps_2">1</stringProp>
            <stringProp name="duration_sec_2">10</stringProp>
          </collectionProp>
        </collectionProp>
      </kg.apc.jmeter.timers.VariableThroughputTimer>

(snip)

JMeter に読み込ませると以下のように定義される。

f:id:inokara:20160513083821p:plain

そもそも Throughput Shaping Timer とは

で、Throughput Shaping Timer とは?


以上

メモでした。