Java websphere比Tomcat慢的原因是什么

Java websphere比Tomcat慢的原因是什么,java,performance,tomcat,websphere,Java,Performance,Tomcat,Websphere,相同的POJO代码使用非常基本的JDK math api,与持久性层无关,只是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(

相同的POJO代码使用非常基本的JDK math api,与持久性层无关,只是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
}

for(int i=0;i首先,通过在每次计算后打印到日志中,您测量的是log4j的性能,而不是jdk math API的性能。如果您想正确执行,请在开始和结束时分别使用
System.currentTimeInMillis()
打印差异

第二,当多线程应用程序在线程多于CPU内核的情况下运行时(websphere就是这种情况),需要调度线程并轮流运行,这就是为什么您会看到批量记录websphere消息的原因

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


一个更有趣的比较是tomcat与websphere liberty,后者是websphere traditional的较新、更轻量级的版本。

您在每种情况下都使用相同的JDK吗?您是如何测量时间的?您是精确地测量for循环还是服务器启动时间.Tomcat 6 vs Websphere 8.5。我使用log4j,我可以在Websphere的日志中看到。我已经更新了这个问题,希望能够稍微澄清一下情况。谢谢。感谢您的反馈。实际上我不是在评估应用程序服务器性能,只是试图找到一种方法,使相同的代码在Tomcat中工作得像在Tomcat中一样快。关于第二个问题重点是,我安装在8核cpu上,内存为16g,部署了单个应用程序,在处理上述POJO math时只有一个线程在运行……仍然可以看到“批处理”时间戳的不同。是的,我确实使用Log4J,这是可能的原因吗?我知道websphere本质上对Log4J不是很友好,而不是普通的日志记录?我不熟悉WAS上的Log4J性能,但因为它只是插入到产品中的第三方软件,我不明白为什么与使用任何日志记录的Log4J相比,WAS上的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
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