csv HTTP简单表服务器

HTTP Simple Table Server

 Download

Performance 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文件中:

Configuration

In jmeter.properties file:

jmeterPlugin.sts.port=9191
jmeterPlugin.sts.addTimestamp=true
jmeterPlugin.sts.datasetDirectory=D:/jmeter/dataset
jmeterPlugin.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 JMeter

The 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 Started

There are different ways to start the STS:

  • with JMeter GUI:
  • 有不同的方式来启动STS:

    • 使用JMeter GUI:

  • with simple-table-server.cmd (.sh for UNIX) script located in your JMETER_HOME/bin directory. Parameters are read in the jmeter.properties or you could also set parameters like simple-table-server.cmd -DjmeterPlugin.sts.addTimestamp=true -DjmeterPlugin.sts.datasetDirectory=D:/jmeter/dataset
  • on JMeter CLI startup (Windows : jmeter-n.cmd or Linux jmeter -n) following properties in jmeter.properties file or in user.properties :
    • 使用位于JMETER_HOME / bin目录中的simple-table-server.cmd(.sh for UNIX)脚本。参数在jmeter.properties中读取,或者您也可以设置参数,如simple-table-server.cmd -DjmeterPlugin.sts.addTimestamp = true -DjmeterPlugin.sts.datasetDirectory = D:/ jmeter / dataset
    • 在JMeter CLI启动(Windows:jmeter-n.cmd或Linux jmeter -n)中,以下是jmeter.properties文件或user.properties中的属性:
jmeterPlugin.sts.loadAndRunOnStartup=true
jmeterPlugin.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;password1
login2;password2
login3;password3
login4;password4
login5;password5

INITFILE

Load file in memory. Lines are stored in a linked list, 1 line = 1 element

The 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:

  1. <html><title>OK</title>
  2. <body>5</body><!-- number of lines read -->
  3. </html>

Linked list after this command:

login1;password1
login2;password2
login3;password3
login4;password4
login5;password5

READ

Get one line from list
http://hostname:port/sts/READ?READ_MODE={FIRST, LAST, RANDOM}&KEEP={TRUE, FALSE}&FILENAME=logins.csv

HTML format:

  1. <html><title>OK</title>
  2. <body>login1;password1</body>
  3. </html>

Available options:

  • READ_MODE=FIRST => login1;password1
  • READ_MODE=LAST => login5;password5
  • READ_MODE=RANDOM => login?;password?
  • KEEP=TRUE => the data is kept and put to the end of list
  • KEEP=FALSE => the data is removed

KEEP=TRUE, READ_MODE=FIRST => login1;password1

Linked list after this command:

login2;password2
login3;password3
login4;password4
login5;password5
login1;password1

KEEP=TRUE, READ_MODE=LAST => login5;password5

Linked list after this command:

login1;password1
login2;password2
login3;password3
login4;password4
login5;password5

KEEP=TRUE, READ_MODE=RANDOM => login2;password2

Linked list after this command:

login1;password1
login3;password3
login4;password4
login5;password5
login2;password2

KEEP=FALSE (delete mode), READ_MODE=FIRST => login1;password1

Linked list after this command:

login2;password2
login3;password3
login4;password4
login5;password5

KEEP=FALSE, READ_MODE=LAST => login5;password5

Linked list after this command:

login1;password1
login2;password2
login3;password3
login4;password4

KEEP=FALSE, READ_MODE=RANDOM => login2;password2

Linked list after this command:

login1;password1
login3;password3
login4;password4
login5;password5

ADD

Add 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 Protocol

http://hostname:port/sts/ADD

POST Parameters : FILENAME=dossier.csv, LINE=D0001123, ADD_MODE={FIRST, LAST}, UNIQUE={FALSE, TRUE}

HTML format:

  1. <html><title>OK</title>
  2. <body></body>
  3. </html>

Available options:

  • ADD_MODE=FIRST => add to the top
  • ADD_MODE=LAST => add to the end
  • FILENAME=dossier.csv => if doesn't already exist it creates a LinkList in memory
  • LINE=1234;98763 => the line to add
  • UNIQUE=TRUE => do not add line if the list already contains such line

POST Protocol with parameters

LENGTH

Return the number of remaining lines of a linked list

返回链表的剩余行数

http://hostname:port/sts/LENGTH?FILENAME=logins.csv

HTML format:

  1. <html><title>OK</title>
  2. <body>5</body><!-- remaining lines -->
  3. </html>

STATUS

显示已加载文件的列表以及每个链接列表的剩余行数

Display the list of loaded files and the number of remaining lines for each linked list

http://hostname:port/sts/STATUS

HTML format:

  1. <html><title>OK</title>
  2. <body>
  3. logins.csv = 5<br />
  4. dossier.csv = 1<br />
  5. </body></html>

SAVE

Save 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:

  1. <html><title>OK</title>
  2. <body>5</body><!-- number of lines saved -->
  3. </html>

RESET

Remove all of the elements from the specified list
http://hostname:port/sts/RESET?FILENAME=logins.csv

HTML format:

  1. <html><title>OK</title>
  2. <body></body>
  3. </html>

STOP

Shutdown the Simple Table Server
http://hostname:port/sts/STOP

有关详细信息,请参阅以下示例

在测试计划中使用STS

通过使用一个或多个HTTP请求采样器调用URL,使用“setUp线程组”初始化文件。

读取一行数据是通过HTTP请求采样器在每次迭代时调用READ方法完成的。然后,您可以使用正则表达式提取器来解析响应数据。

阅读登录

See examples below for further information.

Using STS in a Test Plan

Initialize 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

  • Put the logins.csv file in your JMETER_HOME/bin directory:
Download logins.csv file
  • Run the Simple Table Server manually with the simple-table-server.cmd file or automatically with beanShell configuration.
  • Run one of the following scripts:

In a loop, read random values from a file containing a login and a password at each row:

Download Example Test Plan 1

Read value from a file containing a login and a password at each row, each value is unique and cannot be read anymore:

Download Example Test Plan 2

Add rows in a new linked list and save it in a file when the test is done:

Download Example Test Plan 3

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:

Download Example Test Plan 4

You can override STS settings using command-line options:

  • -DjmeterPlugin.sts.port=<port number>
  • -DjmeterPlugin.sts.loadAndRunOnStartup=<true/false>
  • -DjmeterPlugin.sts.datasetDirectory=<path/to/your/directory>
  • -DjmeterPlugin.sts.addTimestamp=<true/false>
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目录中:

下载logins.csv文件

  • 使用simple-table-server.cmd文件手动运行Simple Table Server,或使用beanShell配置自动运行。
  • 运行以下脚本之一:

在循环中,从包含每行的登录名和密码的文件中读取随机值:

下载示例测试计划1

从包含每行的登录名和密码的文件中读取值,每个值都是唯一的,不能再读取:

下载示例测试计划2

在新链接列表中添加行并在测试完成后将其保存在文件中:

下载示例测试计划3

以随机模式读取位于控制器机器上的具有多个从站的数据集。第一个喷射器将数据集加载到内存中,而其他喷射器等待几秒钟。不同的注射器随机读取包含登录名和密码的数据。测试完成后,第一个注入器将值保存在一个文件中,时间戳为前缀:

下载示例测试计划4

您可以使用命令行选项覆盖STS设置:

  • -DjmeterPlugin.sts.port = <端口号>
  • -DjmeterPlugin.sts.loadAndRunOnStartup = <真/假>
  • -DjmeterPlugin.sts.datasetDirectory = <路径/到/你的/目录>
  • -DjmeterPlugin.sts.addTimestamp = <真/假>

 

 

猜你喜欢

转载自www.cnblogs.com/a00ium/p/10465103.html
csv
今日推荐