2012-12-17 94 views
4

如果我的測試計劃中有3個線程組,我如何設置每個組的恆定概率(請求權重)? 我是JMeter的新手。您能否在截圖中顯示您的設置?每個線程組的概率

+0

你可以發佈你的截圖嗎? – Kimi

+0

對不起,我試過添加屏幕截圖,但是我不能: •很抱歉,作爲垃圾郵件防護機制,新用戶不允許發佈圖片。獲得超過10個聲望來發布圖像。 –

+0

什麼概率? –

回答

2

那麼只需將每個組的線程數設置爲測試線程總數的一個因子即可。 如果100個VU,爲g1設置50,爲g2設置爲30,爲g3設置爲20。

爲了使動態,你可以使用BeanShell功能,您將設置線程數來:

${__BeanShell(50*${USERS}/100)} 

,並會使用含有User Defined Variables

USERS : ${__P(USERS, 10)} // for 10 users by default, 

然後,用戶可以作爲傳遞命令行選項:

-JUSERS=100 

樣本:

<?xml version="1.0" encoding="UTF-8"?> 
<jmeterTestPlan version="1.2" properties="2.4" jmeter="2.9-SNAPSHOT.20121216"> 
    <hashTree> 
    <TestPlan guiclass="TestPlanGui" testclass="TestPlan" testname="Test Plan" enabled="true"> 
     <stringProp name="TestPlan.comments"></stringProp> 
     <boolProp name="TestPlan.functional_mode">false</boolProp> 
     <boolProp name="TestPlan.serialize_threadgroups">false</boolProp> 
     <elementProp name="TestPlan.user_defined_variables" elementType="Arguments" guiclass="ArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true"> 
     <collectionProp name="Arguments.arguments"/> 
     </elementProp> 
     <stringProp name="TestPlan.user_define_classpath"></stringProp> 
    </TestPlan> 
    <hashTree> 
     <Arguments guiclass="ArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true"> 
     <collectionProp name="Arguments.arguments"> 
      <elementProp name="USERS" elementType="Argument"> 
      <stringProp name="Argument.name">USERS</stringProp> 
      <stringProp name="Argument.value">${__P(USERS, 20)}</stringProp> 
      <stringProp name="Argument.metadata">=</stringProp> 
      <stringProp name="Argument.desc">20 is default, to change it on command line -JUSERS=30</stringProp> 
      </elementProp> 
     </collectionProp> 
     </Arguments> 
     <hashTree/> 
     <ThreadGroup guiclass="ThreadGroupGui" testclass="ThreadGroup" testname="Run50Pct" enabled="true"> 
     <stringProp name="ThreadGroup.on_sample_error">continue</stringProp> 
     <elementProp name="ThreadGroup.main_controller" elementType="LoopController" guiclass="LoopControlPanel" testclass="LoopController" testname="Loop Controller" enabled="true"> 
      <boolProp name="LoopController.continue_forever">false</boolProp> 
      <stringProp name="LoopController.loops">1</stringProp> 
     </elementProp> 
     <stringProp name="ThreadGroup.num_threads">${__BeanShell(50*${USERS}/100)}</stringProp> 
     <stringProp name="ThreadGroup.ramp_time">1</stringProp> 
     <longProp name="ThreadGroup.start_time">1356191395000</longProp> 
     <longProp name="ThreadGroup.end_time">1356191395000</longProp> 
     <boolProp name="ThreadGroup.scheduler">false</boolProp> 
     <stringProp name="ThreadGroup.duration"></stringProp> 
     <stringProp name="ThreadGroup.delay"></stringProp> 
     </ThreadGroup> 
     <hashTree> 
     <DebugSampler guiclass="TestBeanGUI" testclass="DebugSampler" testname="DS1" enabled="true"> 
      <boolProp name="displayJMeterProperties">false</boolProp> 
      <boolProp name="displayJMeterVariables">true</boolProp> 
      <boolProp name="displaySystemProperties">false</boolProp> 
     </DebugSampler> 
     <hashTree/> 
     </hashTree> 
     <ThreadGroup guiclass="ThreadGroupGui" testclass="ThreadGroup" testname="Run20Pct" enabled="true"> 
     <stringProp name="ThreadGroup.on_sample_error">continue</stringProp> 
     <elementProp name="ThreadGroup.main_controller" elementType="LoopController" guiclass="LoopControlPanel" testclass="LoopController" testname="Loop Controller" enabled="true"> 
      <boolProp name="LoopController.continue_forever">false</boolProp> 
      <stringProp name="LoopController.loops">1</stringProp> 
     </elementProp> 
     <stringProp name="ThreadGroup.num_threads">${__BeanShell(20*${USERS}/100)}</stringProp> 
     <stringProp name="ThreadGroup.ramp_time">1</stringProp> 
     <longProp name="ThreadGroup.start_time">1356191395000</longProp> 
     <longProp name="ThreadGroup.end_time">1356191395000</longProp> 
     <boolProp name="ThreadGroup.scheduler">false</boolProp> 
     <stringProp name="ThreadGroup.duration"></stringProp> 
     <stringProp name="ThreadGroup.delay"></stringProp> 
     </ThreadGroup> 
     <hashTree> 
     <DebugSampler guiclass="TestBeanGUI" testclass="DebugSampler" testname="DS2" enabled="true"> 
      <boolProp name="displayJMeterProperties">false</boolProp> 
      <boolProp name="displayJMeterVariables">true</boolProp> 
      <boolProp name="displaySystemProperties">false</boolProp> 
     </DebugSampler> 
     <hashTree/> 
     </hashTree> 
     <ThreadGroup guiclass="ThreadGroupGui" testclass="ThreadGroup" testname="Run30Pct" enabled="true"> 
     <stringProp name="ThreadGroup.on_sample_error">continue</stringProp> 
     <elementProp name="ThreadGroup.main_controller" elementType="LoopController" guiclass="LoopControlPanel" testclass="LoopController" testname="Loop Controller" enabled="true"> 
      <boolProp name="LoopController.continue_forever">false</boolProp> 
      <stringProp name="LoopController.loops">1</stringProp> 
     </elementProp> 
     <stringProp name="ThreadGroup.num_threads">${__BeanShell(30*${USERS}/100)}</stringProp> 
     <stringProp name="ThreadGroup.ramp_time">1</stringProp> 
     <longProp name="ThreadGroup.start_time">1356191395000</longProp> 
     <longProp name="ThreadGroup.end_time">1356191395000</longProp> 
     <boolProp name="ThreadGroup.scheduler">false</boolProp> 
     <stringProp name="ThreadGroup.duration"></stringProp> 
     <stringProp name="ThreadGroup.delay"></stringProp> 
     </ThreadGroup> 
     <hashTree> 
     <DebugSampler guiclass="TestBeanGUI" testclass="DebugSampler" testname="DS3" enabled="true"> 
      <boolProp name="displayJMeterProperties">false</boolProp> 
      <boolProp name="displayJMeterVariables">true</boolProp> 
      <boolProp name="displaySystemProperties">false</boolProp> 
     </DebugSampler> 
     <hashTree/> 
     </hashTree> 
     <ResultCollector guiclass="ViewResultsFullVisualizer" testclass="ResultCollector" testname="View Results Tree" enabled="false"> 
     <boolProp name="ResultCollector.error_logging">false</boolProp> 
     <objProp> 
      <name>saveConfig</name> 
      <value class="SampleSaveConfiguration"> 
      <time>true</time> 
      <latency>true</latency> 
      <timestamp>true</timestamp> 
      <success>true</success> 
      <label>true</label> 
      <code>true</code> 
      <message>false</message> 
      <threadName>true</threadName> 
      <dataType>false</dataType> 
      <encoding>false</encoding> 
      <assertions>false</assertions> 
      <subresults>false</subresults> 
      <responseData>false</responseData> 
      <samplerData>false</samplerData> 
      <xml>false</xml> 
      <fieldNames>true</fieldNames> 
      <responseHeaders>false</responseHeaders> 
      <requestHeaders>false</requestHeaders> 
      <responseDataOnError>false</responseDataOnError> 
      <saveAssertionResultsFailureMessage>false</saveAssertionResultsFailureMessage> 
      <assertionsResultsToSave>0</assertionsResultsToSave> 
      <bytes>true</bytes> 
      <hostname>true</hostname> 
      <threadCounts>true</threadCounts> 
      <sampleCount>true</sampleCount> 
      </value> 
     </objProp> 
     <stringProp name="filename"></stringProp> 
     </ResultCollector> 
     <hashTree/> 
     <ResultCollector guiclass="StatVisualizer" testclass="ResultCollector" testname="Aggregate Report" enabled="true"> 
     <boolProp name="ResultCollector.error_logging">false</boolProp> 
     <objProp> 
      <name>saveConfig</name> 
      <value class="SampleSaveConfiguration"> 
      <time>true</time> 
      <latency>true</latency> 
      <timestamp>true</timestamp> 
      <success>true</success> 
      <label>true</label> 
      <code>true</code> 
      <message>false</message> 
      <threadName>true</threadName> 
      <dataType>false</dataType> 
      <encoding>false</encoding> 
      <assertions>false</assertions> 
      <subresults>false</subresults> 
      <responseData>false</responseData> 
      <samplerData>false</samplerData> 
      <xml>false</xml> 
      <fieldNames>true</fieldNames> 
      <responseHeaders>false</responseHeaders> 
      <requestHeaders>false</requestHeaders> 
      <responseDataOnError>false</responseDataOnError> 
      <saveAssertionResultsFailureMessage>false</saveAssertionResultsFailureMessage> 
      <assertionsResultsToSave>0</assertionsResultsToSave> 
      <bytes>true</bytes> 
      <hostname>true</hostname> 
      <threadCounts>true</threadCounts> 
      <sampleCount>true</sampleCount> 
      </value> 
     </objProp> 
     <stringProp name="filename"></stringProp> 
     </ResultCollector> 
     <hashTree/> 
    </hashTree> 
    </hashTree> 
</jmeterTestPlan> 
+0

是的,我知道這種方式並使用它。但我想知道,如果我需要這種方式,我可以如何修復每個組的概率,然後只更改普通用戶數量。 –

+0

我更新了我的答案 –

+0

謝謝!我明白我應該打開每個線程組併爲每個線程組設置概率:對於第一,我應該寫第二個$ {__ BeanShell(50 * $ {USERS}/100)}我應該寫$ {__ BeanShell(30 * $ {USERS}/100)}我應該寫$ {__ BeanShell(20 * $ {USERS}/100)}但爲什麼我們需要使用字符串$ {__ P(USERS,10)}?在測試計劃中,我可以定義USERS的金額?也在「用戶默認變量」? $ {USERS} = 1000(例如) - 它正確嗎? –