HTTP请求中文件协议的使用

Usage of file protocol in HTTP request

使用HTTP Request is suggested for Passing variables between threads读取文件。

For example you could use the Save Responses to a file listener or perhaps a BeanShell PostProcessor in one thread, and read the file using the HTTP Sampler "file:" protocol, and extract the information using a PostProcessor

哪个有效,但应该忽略文档中的警告吗?

Note: the FILE protocol is intended for testing purposes only. It is handled by the same code regardless of which HTTP Sampler is used.

Is/when它safe/good练习使用文件协议还是deprecated/bad练习?

  1. 使用 Beanshell PostProcessor 绝对是一种糟糕的做法,since JMeter 3.1 you should be using JSR223 Test Elements and Groovy 语言
  2. 写入和读取文件可能会导致大量 disk IO 开销,这可能成为脚本的瓶颈,尤其是在高负载时。而且in-memory操作会比writing/reading文件to/from文件系统
  3. 快很多

假设以上所有:

虽然如果您需要从文件系统上的文件中读取数据,使用file协议没有任何问题,但最好避免使用这些临时文件并使用内存在线程之间传递数据,选项在:

  1. 在其他Thread Group中使用__setProperty() function in 1st thread group to store the value and __P() function读取之前存储的值
  2. 使用Inter-Thread Communication Plugin which can be used for passing variables between threads, even if they live in different Thread Groups (see SynchronizationExample.jmx for a practical use case). Inter-Thread Communication Plugin can be installed using JMeter Plugins Manager