什么是导致websphere比Tomcat慢的原因

时间:2016-12-06 03:10:03

标签: java performance tomcat websphere

使用非常基本的JDK math api的相同POJO代码,与持久层无关,只是POJO,但是迭代可能会持续数百万轮,因此从Websphere到Tomcat的总时差可能是10:1。代码是这样的。

for(int i=0;i<200000;i++){
    logger.info("calculate result 1");
    int result_int1 = new Double(param1_double_left / param1_double_right).intValue();
    logger.info("calculate result 2");
    int result_int2 = new Double(param2_double_left / param2_double_right).intValue();
    logger.info("calculate result 3");
    int result_int3 = new Double(param3_double_left / param3_double_right).intValue();
    logger.info("calculate result 4");
    int result_int4 = new Double(param4_double_left / param4_double_right).intValue();
    logger.info("calculate result 5");
    int result_int5 = new Double(param5_double_left / param5_double_right).intValue();
    //... more calculation with java math like above
}

从tomcat的log4j日志开始,它非常快,所以时间戳就像

2016-12-05 17:53:31,200 INFO .... <-200
.... another 10 - 20 lines with same timestamp
2016-12-05 17:53:31,201 INFO .... <-201
.... another 10 - 20 lines with same timestamp
2016-12-05 17:53:31,202 INFO .... <-202
.... another 10 - 20 lines with same timestamp
2016-12-05 17:53:31,203 INFO .... <-203
.... another 10 - 20 lines with same timestamp
2016-12-05 17:53:31,204 INFO .... <-204
.... another 10 - 20 lines with same timestamp

从websphere的log4j日志中,时间戳随着每次激增的时间增加而增加

2016-12-05 17:55:47,197 INFO .... <-197
.... another 10 - 20 lines with same timestamp
2016-12-05 17:55:47,212 INFO .... <-212
.... another 10 - 20 lines with same timestamp
2016-12-05 17:55:47,239 INFO .... <-239
.... another 10 - 20 lines with same timestamp
2016-12-05 17:55:47,251 INFO .... <-251
.... another 10 - 20 lines with same timestamp
2016-12-05 17:55:47,277 INFO .... <-277
.... another 10 - 20 lines with same timestamp

所以只是想知道可能是关于websphere缓慢的因素。 GC?或其他JVM调优?

1 个答案:

答案 0 :(得分:3)

首先,您通过在每次计算后打印到日志来测量log4j的性能,而不是jdk math API的性能。如果你想做得对,请在开始时一次System.currentTimeInMillis(),最后一次并打印差异。

其次,当多线程应用程序运行时,如果线程数多于CPU核心(websphere就是这种情况),则需要调度线程并轮流运行,这就是您看到批量记录的websphere消息的原因。

最后,使用jdk API的速度来衡量应用服务器的性能并没有任何意义。更准确的做法是测量服务器启动时间或请求/秒(tomcat几乎肯定会在小规模测试中胜出,因为它的重量轻)。这就像比较摩托车和半卡车一样,它们在性能上有不同的优势。

更有趣的比较是tomcat与websphere自由,这是更传统的websphere更轻量级版本。