ngrinder的脚本可以实现参数化功能吗?

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

ngrinder的脚本可以实现参数化功能吗?

shuewah
测试登录,1000个账号,ngrinder脚本可以实现1000用户并发时,分别使用账号文件中的数值吗?
如果可以,如何实现?
Reply | Threaded
Open this post in threaded view
|

RE: ngrinder的脚本可以实现参数化功能吗?

Mavlarn

用户并发就是设置虚拟用户,要设置1千个用户的话,使用groovy类型的脚本的话,用一台agent机器也够了,但是要注意,如果每个测试需要的时间非常短,例如几毫秒,也就是在IO上面消耗的时间非常少,那么设置太多虚拟用户就会造成agent机器无法响应。

 

至于使用账号文件,也很简单,你可以把账号文件上传到resources目录里,你就可以在脚本里面读到这个文件。具体参考:

http://www.cubrid.org/wiki_ngrinder/entry/how-to-use-resources 

你只需要在每个test方法里面,通过一定方式读取不同的账号就可以。例如获取当前的线程、进程ID,生成一个值,对应文件里的一行。

http://www.cubrid.org/wiki_ngrinder/entry/how-to-make-each-thread-act-differently 

 

 

 

-----Original Message-----
From: "shuewah [via ngrinder]"<[hidden email]>
To: "Mavlarn"<[hidden email]>;
Cc:
Sent: 2014-04-08 (星期二) 16:55:21
Subject: ngrinder的脚本可以实现参数化功能吗?

测试登录,1000个账号,ngrinder脚本可以实现1000用户并发时,分别使用账号文件中的数值吗?
如果可以,如何实现?


If you reply to this email, your message will be added to the discussion below:
http://ngrinder.642.n7.nabble.com/ngrinder-tp1467.html
To start a new topic under ngrinder-user-cn, email [hidden email]
To unsubscribe from ngrinder-user-cn, click here.
NAML
lee
Reply | Threaded
Open this post in threaded view
|

Re: ngrinder的脚本可以实现参数化功能吗?

lee
In reply to this post by shuewah
你好  你的并发登陆实现了  请教下
lee
Reply | Threaded
Open this post in threaded view
|

RE: ngrinder的脚本可以实现参数化功能吗?

lee
In reply to this post by Mavlarn
你好  你给的参考地址404  有没有例子啊  这方面的太少了
Reply | Threaded
Open this post in threaded view
|

Re: ngrinder的脚本可以实现参数化功能吗?

ziteng
In reply to this post by lee
我的做法大致如下,实现了不同的 Vuser 取不同的值


from net.grinder.script.Grinder import grinder
from net.grinder.script import Test
from net.grinder.plugin.http import HTTPRequest
from net.grinder.plugin.http import HTTPPluginControl
from HTTPClient import NVPair
import datetime
import random
import string
from org.json import JSONObject
import hashlib
log=grinder.logger.info

test_query_file = "./resources/configEnv.json"
file = open(test_query_file, "r")
fileStr = str(file.read())
file.close()

jsonObject=JSONObject(fileStr)

env = jsonObject.getString("Name")
#grinder.logger.info("Current Environment:"+env)
#Get the env sub jsonobject, so that can get the sub keys
envInfo = jsonObject.getJSONObject(env)
filepath = str(envInfo.getString("wx_pay_datafile"))

test1 = Test(1, url)
request1 = HTTPRequest(url=url)
# Make any method call on request1 increase TPS
test1.record(request1)

control = HTTPPluginControl.getConnectionDefaults()
# if you don't want that HTTPRequest follows the redirection, please modify the following option 0.
# control.followRedirects = 1
# if you want to increase the timeout, please modify the following option.
control.timeout = 6000

#################
numGrinderProcesses = int(grinder.properties.getProperty("grinder.processes"))
numGrinderThreads = int(grinder.properties.getProperty("grinder.threads")) 
# the below means 'Interval_file_row'
numGrinderRuns = int(grinder.properties.getProperty("grinder.runs"))
#################

class TestRunner:
	# initlialize a thread 
	def __init__(self):
		grinder.statistics.delayReports=True
		self.threadNumber = int(grinder.getThreadNumber())
		#grinder.logger.info('threadNumber: '+str(self.threadNumber))
		self.processNumber = int(grinder.getProcessNumber())
		#grinder.logger.info('processNumber: '+str(self.processNumber))
		self.agentNumber = int(grinder.getAgentNumber())
		self.curNumber = (self.agentNumber*numGrinderProcesses*numGrinderThreads)+(self.processNumber*numGrinderThreads)+self.threadNumber

	# test method		
	def __call__(self):
		# Open the file with the user information.
		self.runNumber = int(grinder.getRunNumber())
		userFile = open(filepath, 'r') 
		lines = userFile.readlines()
		userFile_rowCount = len(lines)
		current_line = self.curNumber*numGrinderRuns+self.runNumber
		# Start with a value in userFileLine so we can tell if we read an empty line or an end-of-file marker. 
		userFileLine = 'X' # 'X' is just a randomly picked value; it doesn't mean anything. 
		if userFile_rowCount:
			userFileLine = lines[current_line] 
			userFileLine = userFileLine.strip() 
			if userFileLine: 
				# the number starting from 0 within a single process.
				log('agent-process-thread-run: '+str(self.agentNumber)+'-'+str(self.processNumber)+'-'+str(self.threadNumber)+'-'+str(self.runNumber)+' curNumber:'+str(self.curNumber)+' Current_line:'+str(current_line))
				ch_details=userFileLine.split(',')
				############### do something #################

		userFile.close()

Reply | Threaded
Open this post in threaded view
|

Re: ngrinder的脚本可以实现参数化功能吗?

dulio
很棒,近期也遇到API Session互斥的问题,就看到了这个示例代码,谢谢