背景
我目前正在为使用gatling的压力测试工具开发能力分析集。在Gatling场景中产生多个进一步操作的动作
这部分涉及使用滚动查询加载elasticsearch,然后加载更新API调用。
我想实现
第1步是什么:运行滚动发起并保存在那里可以通过进一步滚动使用的_scroll_id
查询
步骤2:运行滚动查询上重复一遍,作为每个滚动查询的一部分,对返回的每个匹配进行修改,并将其重新索引到elasticsearch中,从一次滚动查询操作中有效产生多达1000个操作,并对结果进行采样。
第1步很容易。第2步不是很多。
我已经试过
我目前正试图通过一个分析JSON格式结果的ResponseTransformer实现这一目标,使修改每一个和火灾关闭一个线程试图另一个exec(http(...).post(...) etc)
到索引中的每一个这些变化回到elasticsearch。
基本上,我认为我会用错误的方式去解决它。索引线程永远不会运行,更不用说采样了。
这里是我的滚动查询行为的主体:
...
val pool = Executors.newFixedThreadPool(parallelism)
val query = exec(http("Scroll Query")
.get(s"/_search/scroll")
.body(ElFileBody("queries/scrollquery.json")).asJSON // Do the scroll query
.check(jsonPath("$._scroll_id").saveAs("scroll_id")) // Get the scroll ID from the response
.transformResponse { case response if response.isReceived =>
new ResponseWrapper(response) {
val responseJson = JSON.parseFull(response.body.string)
// Get the hits and
val hits = responseJson.get.asInstanceOf[Map[String, Any]]("hits").asInstanceOf[Map[String,Any]]("hits").asInstanceOf[List[Map[String, Any]]]
for (hit <- hits) {
val id = hit.get("_id").get.asInstanceOf[String]
val immutableSource = hit.get("_source").get.asInstanceOf[Map[String, Any]]
val source = collection.mutable.Map(immutableSource.toSeq: _*) // Make the map mutable
source("newfield") = "testvalue" // Make a modification
Thread.sleep(pause) // Pause to simulate topology throughput
pool.execute(new DocumentIndexer(index, doctype, id, source)) // Create a new thread that executes the index request
}
}
}) // Make some mods and re-index into elasticsearch
...
DocumentIndexer看起来是这样的:
class DocumentIndexer(index: String, doctype: String, id: String, source: scala.collection.mutable.Map[String, Any]) extends Runnable {
...
val httpConf = http
.baseURL(s"http://$host:$port/${index}/${doctype}/${id}")
.acceptHeader("application/json")
.doNotTrackHeader("1")
.disableWarmUp
override def run() {
val json = new ObjectMapper().writeValueAsString(source)
exec(http(s"Index ${id}")
.post("/_update")
.body(StringBody(json)).asJSON)
}
}
问题
- 使用加特林这甚至可能吗?
- 我该如何达到我想达到的目标?
感谢您的任何帮助/建议!