gpt4 book ai didi

java - Play 2.2 中的性能问题

转载 作者:行者123 更新时间:2023-12-01 13:53:23 25 4
gpt4 key购买 nike

我将 Thread.sleep(100) 放入 Play 2.2 Controller 中以模拟后端操作。

@BodyParser.Of(BodyParser.Json.class)
public Promise<Result> d() {
Promise<JsonNode> promiseOfJson = Promise.promise(new Function0<JsonNode>() {
public JsonNode apply() throws Exception {
ABean aBean = new ABean();

aBean.setStatus("success");
aBean.setMessage("Hello World...");

Thread.sleep(100);

return Json.toJson(aBean);
}
});

return promiseOfJson.map(new Function<JsonNode, Result>() {
public Result apply(JsonNode jsonNode) {
return ok(jsonNode);
}
});
}

我的application.conf配置为

#Play Internal Thread Pool
internal-threadpool-size=4

#Scala Iteratee thread pool
iteratee-threadpool-size=4

# Akka Configuration for making parallelism
# ~~~~~
# Play's Default Thread Pool
play {
akka {
akka.loggers = ["akka.event.Logging$DefaultLogger", "akka.event.slf4j.Slf4jLogger"]
loglevel = ERROR
actor {

deployment {

/actions {
router = round-robin
nr-of-instances = 100
}

/promises {
router = round-robin
nr-of-instances = 100
}

}

retrieveBodyParserTimeout = 5 seconds

actions-dispatcher = {
fork-join-executor {
parallelism-factor = 100
parallelism-max = 100
}
}

promises-dispatcher = {
fork-join-executor {
parallelism-factor = 100
parallelism-max = 100
}
}

default-dispatcher = {
fork-join-executor {

# No. of minimum threads = 8 ; at the most 64 ; or other wise 3 times the no. of processors available on the system
# parallelism-factor = 1.0
# parallelism-max = 64
# parallelism-min = 8

parallelism-factor = 3.0
parallelism-max = 64
parallelism-min = 8

}
}
}
}
}

我运行 ab 命令如下:

ab -n 900 -c 1 http://localhost:9000/a/b/c/d

结果显示每秒仅处理 9 个请求。

可以调整application.conf以获得更好的性能吗?如果是,怎么办?

最佳答案

这是由 sleep(100) 调用引起的。即使所有其余代码都无限快,您仍然只能通过 1 个测试线程每秒收到 10 个请求。

关于java - Play 2.2 中的性能问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19790945/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com