HTTP Simple Table ServerPerformance testing with JMeter can be done with several JMeter injectors (on a remote host) and one JMeter controller (with GUI, on your local host). Scripts are sent to JMeter injectors using RMI protocol. Results are brought back periodically to the JMeter controller. Unfortunately the dataset and csv files aren't transferred from the controller to injectors. The main idea is to use a tiny http server in JMeter Plugins to manage the dataset files with simple commands to get / add rows of data in files. 使用JMeter进行性能测试可以使用多个JMeter注入器(在远程主机上)和一个JMeter控制器(在本地主机上使用GUI)完成。使用RMI协议将脚本发送到JMeter注入器。结果定期返回JMeter控制器。遗憾的是,数据集和csv文件不会从控制器传输到喷射器。 主要思想是在JMeter插件中使用一个微小的http服务器来管理数据集文件,使用简单的命令来获取/添加文件中的数据行。 组态在jmeter.properties文件中: ConfigurationIn jmeter.properties file: jmeterPlugin.sts.port=9191jmeterPlugin.sts.addTimestamp=truejmeterPlugin.sts.datasetDirectory=D:/jmeter/datasetjmeterPlugin.sts.loadAndRunOnStartup=false Do not use '\' in the path directory, it doesn't work well, use '/' or '\' instead. It is also recommended to use UTF-8 as the encoding: 不要在路径目录中使用'\',它不能很好地工作,而是使用'/'或'\'。还建议使用UTF-8作为编码:
sampleresult.default.encoding=UTF-8 If you want automatically start a Simple Table Server on JMeter STARTUP simply add "simple-table-server.bsh" in the "beanshell.init.file" property. Be sure that simple-table-server.bsh file is in your JMETER_HOME/bin directory. The Simple Table Server is a tiny http server which can send http GET/POST requests on port 9191 (by default). You can set a custom port through the graphical user interface or by overriding the jmeterplugin.sts.port property. 如果要在JMeter STARTUP上自动启动简单表服务器,只需在“beanshell.init.file”属性中添加“simple-table-server.bsh”即可。确保simple-table-server.bsh文件位于JMETER_HOME / bin目录中。 Simple Table Server是一个很小的http服务器,它可以在端口9191上发送http GET / POST请求(默认情况下)。您可以通过图形用户界面或通过覆盖jmeterplugin.sts.port属性来设置自定义端口。 JMeter的分布式架构简单表服务器在JMeter控制器(主服务器)上运行,负载生成器(从服务器)调用STS来获取或添加一些数据。在测试开始时,第一个负载生成器将在内存中加载数据(初始调用),并在测试结束时询问STS在文件中保存值。所有负载生成器都会询问来自JMeter控制器上启动的同一STS的数据。 Distributed architecture for JMeterThe Simple Table Server runs on the JMeter controller (master) and load generators (slaves) make calls to the STS to get or add some data. At the beginning of the test, the first load generator will load data in memory (initial call) and at the end of the test it asks the STS saving values in a file. All the load generators ask data from the same STS which is started on the JMeter controller. Getting StartedThere are different ways to start the STS:
jmeterPlugin.sts.loadAndRunOnStartup=truejmeterPlugin.sts.port=9191 beanshell.init.file=simple-table-server.bsh When the STS is running go to http://<HOST>:<PORT>/sts/ to see all available commands. Calls are synchronized, all commands are executed one by one.Example of a dataset file logins.csv: 当STS运行时,转到http:// <HOST>:<PORT> / sts /以查看所有可用命令。 呼叫是同步的,所有命令都是逐个执行的。 数据集文件logins.csv的示例: login1;password1login2;password2login3;password3login4;password4login5;password5 INITFILELoad file in memory. Lines are stored in a linked list, 1 line = 1 elementThe filename is limited to 128 characters maxi and must not contains characters \ / : or .. 在内存中加载文件。行存储在链表中,1行= 1个元素 文件名限制为128个字符maxi,不得包含字符\ /:或.. http://hostname:port/sts/INITFILE?FILENAME=logins.csv HTML format:
Linked list after this command: login1;password1login2;password2login3;password3login4;password4login5;password5 READGet one line from listhttp://hostname:port/sts/READ?READ_MODE={FIRST, LAST, RANDOM}&KEEP={TRUE, FALSE}&FILENAME=logins.csv HTML format:
Available options:
KEEP=TRUE, READ_MODE=FIRST => login1;password1 Linked list after this command: login2;password2login3;password3login4;password4login5;password5login1;password1 KEEP=TRUE, READ_MODE=LAST => login5;password5 Linked list after this command: login1;password1login2;password2login3;password3login4;password4login5;password5 KEEP=TRUE, READ_MODE=RANDOM => login2;password2 Linked list after this command: login1;password1login3;password3login4;password4login5;password5login2;password2 KEEP=FALSE (delete mode), READ_MODE=FIRST => login1;password1 Linked list after this command: login2;password2login3;password3login4;password4login5;password5 KEEP=FALSE, READ_MODE=LAST => login5;password5 Linked list after this command: login1;password1login2;password2login3;password3login4;password4 KEEP=FALSE, READ_MODE=RANDOM => login2;password2 Linked list after this command: login1;password1login3;password3login4;password4login5;password5 ADDAdd a line into a file: (GET OR POST HTTP protocol)GET Protocol http://hostname:port/sts/ADD?FILENAME=dossier.csv&LINE=D0001123&ADD_MODE={FIRST, LAST}&UNIQUE={FALSE, TRUE} GET Parameters : FILENAME=dossier.csv&LINE=D0001123&ADD_MODE={FIRST, LAST}&UNIQUE={FALSE, TRUE} POST Protocolhttp://hostname:port/sts/ADD POST Parameters : FILENAME=dossier.csv, LINE=D0001123, ADD_MODE={FIRST, LAST}, UNIQUE={FALSE, TRUE} HTML format:
Available options:
POST Protocol with parameters LENGTHReturn the number of remaining lines of a linked list 返回链表的剩余行数 http://hostname:port/sts/LENGTH?FILENAME=logins.csv HTML format:
STATUS显示已加载文件的列表以及每个链接列表的剩余行数 Display the list of loaded files and the number of remaining lines for each linked list
http://hostname:port/sts/STATUS HTML format:
SAVESave the specified linked list in a file to the specified location 将文件中指定的链接列表保存到指定位置 http://hostname:port/sts/SAVE?FILENAME=logins.csv If jmeterPlugin.sts.addTimestamp is set to true then a timestamp will be add to the filename, the file is stored in the custom directory specified by editing the jmeterPlugin.sts.datasetDirectory property or in JMETER_HOME/bin directory by default: 如果jmeterPlugin.sts.addTimestamp设置为true,则会将时间戳添加到文件名,该文件存储在通过编辑jmeterPlugin.sts.datasetDirectory属性指定的自定义目录中,或默认情况下存储在JMETER_HOME / bin目录中: 20140520T16h33m27s.logins.csv HTML format:
RESETRemove all of the elements from the specified listhttp://hostname:port/sts/RESET?FILENAME=logins.csv HTML format:
STOPShutdown the Simple Table Serverhttp://hostname:port/sts/STOP 有关详细信息,请参阅以下示例 在测试计划中使用STS通过使用一个或多个HTTP请求采样器调用URL,使用“setUp线程组”初始化文件。 读取一行数据是通过HTTP请求采样器在每次迭代时调用READ方法完成的。然后,您可以使用正则表达式提取器来解析响应数据。 阅读登录 See examples below for further information. Using STS in a Test PlanInitialize file using a "setUp Thread Group" by calling URL with one or more HTTP Request Sampler. Reading a row of data is done by calling READ method at each iteration by a HTTP Request Sampler. Then you can use a Regular Expression Extractor to parse the response data. Reading login: Reading password: At the end of your Test Plan you can save remaining/adding data with a HTTP Request Sampler in a "tearDown Thread Group". Example
In a loop, read random values from a file containing a login and a password at each row: Read value from a file containing a login and a password at each row, each value is unique and cannot be read anymore: Add rows in a new linked list and save it in a file when the test is done: Read in a random mode a dataset located on the controller machine with severals slaves. The first injector loads the dataset in memory while the other injectors are waiting few seconds. The different injectors read randomly the data containing logins and passwords. When the test is done the first injector save the values in a file with a timestamp as prefix: You can override STS settings using command-line options:
jmeter.bat -DjmeterPlugin.sts.loadAndRunOnStartup=true -DjmeterPlugin.sts.port=9191 -DjmeterPlugin.sts.datasetDirectory=d:/data -n –t testdemo.jmx When it's done see results in the Listener Tree View. |
在测试计划结束时,您可以使用“泪滴线程组”中的HTTP请求采样器保存剩余/添加数据。
例
- 将logins.csv文件放在JMETER_HOME / bin目录中:
- 使用simple-table-server.cmd文件手动运行Simple Table Server,或使用beanShell配置自动运行。
- 运行以下脚本之一:
在循环中,从包含每行的登录名和密码的文件中读取随机值:
从包含每行的登录名和密码的文件中读取值,每个值都是唯一的,不能再读取:
在新链接列表中添加行并在测试完成后将其保存在文件中:
以随机模式读取位于控制器机器上的具有多个从站的数据集。第一个喷射器将数据集加载到内存中,而其他喷射器等待几秒钟。不同的注射器随机读取包含登录名和密码的数据。测试完成后,第一个注入器将值保存在一个文件中,时间戳为前缀:
您可以使用命令行选项覆盖STS设置:
- -DjmeterPlugin.sts.port = <端口号>
- -DjmeterPlugin.sts.loadAndRunOnStartup = <真/假>
- -DjmeterPlugin.sts.datasetDirectory = <路径/到/你的/目录>
- -DjmeterPlugin.sts.addTimestamp = <真/假>