今天我遇到了一个行为相当奇怪的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,结果并没有改变。
发布于 2018-03-06 23:07:32
关于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从观察到的行为来看,似乎可以合理地假设,在IIS和FastCGI上使用PHP通过shell_exec创建新进程不会提供提供者sun.security.provider.Sun可以用来为使用加密函数生成足够的熵的任何东西,因此会暂停执行,直到创建了足够的熵。
https://stackoverflow.com/questions/49133729
复制相似问题