简体   繁体   English

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

[英]Why is this java program running in IIS via PHP/FastCGI much slower than in shell?

Today i came across a rather odd behaving java program. 今天,我遇到了一个行为异常的Java程序。

Testrunning the java program in cmd shell results in a very fast execution (~0.5s). 在cmd shell中测试运行Java程序会导致非常快速的执行(〜0.5s)。 Accessing the same java via IIS with a PHP script results in a wait time of 5.5s on every request. 通过IIS使用PHP脚本访问相同的Java,每个请求的等待时间为5.5s。

I added -Xprof to the java call to see how it behaves and found a recurring pattern like this: 我在Java调用中添加了-Xprof,以查看其行为,并发现了如下重复模式:

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

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

At the end we have the following time result: 最后,我们得到以下时间结果:

  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

The code is spending 5s in the SeedGenerator during which java.exe consumes one complete cpu thread. 代码在SeedGenerator中花费5秒钟,在此期间java.exe消耗了一个完整的cpu线程。 I've tried running FastCGI with either impersonation on or off, it doesn't change the result. 我尝试在启用或禁用模拟的情况下运行FastCGI,但不会更改结果。

There seems to be something very specific to how the FastCGI module spawns a new thread. FastCGI模块如何产生新线程似乎有一些特定的东西。 My first guess was that creating the user environment for the impersonation takes a long time but as indicated in the question this is not true. 我的第一个猜测是为模仿创建用户环境需要很长时间,但是正如问题所示,这是不正确的。 However searching for problems with SeedGenerator i came across this answer: Simple Java program 100 times slower after plugging in USB hotspot 但是,在寻找SeedGenerator的问题时,我遇到了以下答案: 插入USB热点后,简单Java程序的速度慢了100倍

Using the suggested fix with changing java.security brought the execution time down to expected values: 通过更改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

Judging from the observed behavior it seems reasonable to assume that creating a new process through shell_exec using PHP on IIS with FastCGI does not provide anything that provider sun.security.provider.Sun could use for generating enough entropy for using crypto functions and therefore stalls the execution until enough entropy is created. 从观察到的行为来看,似乎合理的假设是,在带有FastCGI的IIS上使用PHP在shell_exec上创建新进程不会提供任何提供程序sun.security.provider.Sun可用于生成足够的熵来使用加密函数的功能,因此会暂停执行直到创建足够的熵。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM