【问题标题】:What can be the cause that websphere is way slower than Tomcatwebsphere比Tomcat慢的原因可能是什么
【发布时间】:2016-12-06 03:10:02
【问题描述】:

相同的 POJO 代码使用非常基本的 JDK 数学 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
}

来自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 调优?

【问题讨论】:

  • 您在每种情况下都使用相同的 JDK 吗?你是如何测量时间的?您是在精确测量 for 循环还是服务器启动时间被拉入?
  • @aguibert 是相同的 JDK (JDK7)。 Tomcat 6 与 Websphere 8.5。我使用 log4j,我可以从 websphere 中看到日志。我已经更新了这个问题,希望可以稍微澄清一下情况。谢谢。

标签: java performance tomcat websphere


【解决方案1】:

首先,您通过在每次计算后打印到日志来衡量 log4j 的性能,而不是 jdk 数学 API 的性能。如果你想把它做对,请在开始和结束时使用System.currentTimeInMillis() 并打印差异。

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

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

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

【讨论】:

  • 感谢您的反馈。实际上,我并不是在评估应用服务器的性能,只是想找到一种方法让相同的代码在 WAS 中像在 Tomcat 中一样快地运行。关于第二点,我在具有 16g 内存的 8 核 cpu 上安装了 WAS,部署了单个应用程序,并且在处理上述 POJO 数学时只运行了一个线程......仍然可以看到时间戳的“批处理”差异。是的,我确实使用 Log4J 是可能的原因吗?我知道 websphere 天生对 Log4j 而不是普通日志记录不太友好?
  • 我不熟悉 WAS 上的 Log4j 性能,但由于它只是插入到产品中的第三方软件,我不明白为什么它在 WAS 上会比使用 Log4j 慢其他软件。无论如何,我在第一段中提出的建议仍然应该是衡量事物的有效方法。
猜你喜欢
  • 2011-08-05
  • 2019-05-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-02-16
  • 2021-09-01
  • 2012-01-01
  • 2020-09-09
相关资源
最近更新 更多