【问题标题】:Why is this java program running in IIS via PHP/FastCGI much slower than in shell?为什么这个 java 程序通过 PHP/FastCGI 在 IIS 中运行比在 shell 中慢得多?
【发布时间】:2018-08-14 11:33:46
【问题描述】:

今天我遇到了一个行为相当奇怪的java程序。

在 cmd shell 中测试运行 java 程序会导致执行速度非常快(约 0.5 秒)。使用 PHP 脚本通过 IIS 访问相同的 java 会导致每个请求的等待时间为 5.5 秒。

我在 java 调用中添加了 -Xprof 以查看它的行为,并发现了这样的重复模式:

Flat profile of 0.25 secs (24 total ticks): SeedGenerator Thread

  Thread-local ticks:
100.0%    24             Blocked (of total)

最后我们得到以下时间结果:

  Thread-local ticks:
 91.4%   448             Blocked (of total)
  2.4%     1             Unknown: no last frame
lat profile of 5.04 secs (452 total ticks): SeedGenerator Thread

  Interpreted + native   Method                        
  0.2%     0  +     1    java.lang.Object.notifyAll
  0.2%     0  +     1    Total interpreted

     Compiled + native   Method                        
 99.6%    27  +   423    sun.security.provider.SeedGenerator$ThreadedSeedGenerator.run
 99.6%    27  +   423    Total compiled

         Stub + native   Method                        
  0.2%     0  +     1    java.lang.System.currentTimeMillis
  0.2%     0  +     1    Total stub


Global summary of 5.55 seconds:
100.0%   492             Received ticks
  1.8%     9             Compilation
  0.2%     1             Other VM operations
  0.6%     3             Unknown code

代码在 SeedGenerator 中花费了 5s,在此期间 java.exe 消耗了一个完整的 cpu 线程。 我试过在模拟打开或关闭的情况下运行 FastCGI,它不会改变结果。

【问题讨论】:

    标签: java php performance iis


    【解决方案1】:

    FastCGI 模块如何生成新线程似乎有一些非常具体的内容。我的第一个猜测是,为模拟创建用户环境需要很长时间,但如问题所示,这不是真的。 但是在搜索 SeedGenerator 的问题时,我遇到了这个答案:Simple Java program 100 times slower after plugging in USB hotspot

    使用建议的修复程序并更改 java.security 将执行时间降低到预期值:

    Global summary of 0.53 seconds:
    100.0%    43             Received ticks
     14.0%     6             Compilation
      4.7%     2             Class loader
      7.0%     3             Unknown code
    

    从观察到的行为来看,假设通过 shell_exec 在具有 FastCGI 的 IIS 上使用 PHP 创建一个新进程并没有提供提供程序 sun.security.provider.Sun 可以用来生成足够的熵以使用加密函数和因此会暂停执行,直到创建足够的熵。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-11-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多