为什么这个通过PHP / FastCGI在IIS中运行的java程序比在shell中慢得多?

问题描述 投票:0回答:1

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

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

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

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中花费5秒,在此期间java.exe占用一个完整的cpu线程。我试过运行FastCGI开启或关闭模拟,它不会改变结果。

java php performance iis
1个回答
0
投票

似乎有一些特定于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

从观察到的行为来看,假设使用带有FastCGI的IIS上的PHP通过shell_exec创建一个新进程并不能提供任何提供者sun.security.provider.Sun可以用来生成足够的熵以使用加密函数并因此停止执行直到创建足够的熵。

© www.soinside.com 2019 - 2024. All rights reserved.