0

我将 Thread.sleep(100) 放在 Play 2.2 控制器中以模拟后端操作。

@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以获得更好的性能吗?如果是,如何?

4

1 回答 1

1

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

于 2013-11-05T14:14:38.813 回答