我有一个方案,编制大约50名德国马克的档案。 在这一过程期间,该方案经常重写档案的章节,并迫使对磁盘的改动(按100次顺序排列)。 它使用传道和直接贝特德(......)、fc.write(......)和fc.force(......)。
www.un.org/Depts/DGACM/index_spanish.htm 新案文:
I have a better view on the problem now. The problem appears to be that I use three different JVMs to modify a file (one creates it, two others (launched from the first) write to it). Every JVM closes the file properly before the next JVM is started. The problem is that the cost of fc.write() to that file occasionally goes through the roof for the third JVM (in the order of 100 times the normal cost). That is, all write operations are equally slow, it is not just one that hang very long. Interestingly, one way to help this is to insert delays (2 seconds) between the launching of JVMs. Without delay, writing is always slow, with delay, the writing is slow aboutr every second time or so.
I also found this Stackoverflow: How to unmap a file from memory mapped using FileChannel in java? which describes a problem for mapped files, which I m not using.
What I suspect might be going on: Java does not completely release the file handle when I call close(). When the next JVM is started, Java (or Windows) recognizes concurrent access to that file and installes some expensive concurrency handler for that file, which makes writing expensive. Would that make sense?
问题出现在Windows 7上(Java 6和7,用两台机器测试),但并不在Ltlin下(SuSE 11.364)。
www.un.org/Depts/DGACM/index_spanish.htm 旧案文:
The problem: Starting the program from as a JUnit test harness from eclipse or from console works fine, it takes around 3 seconds. Starting the program through an ant task (or through JUnit by kicking of a separate JVM using a ProcessBuilder) slows the program down to 70-80 seconds for the same task (factor 20-30).
Using -Xprof reveals that the usage of force0 and pwrite goes through the roof from 34.1% (76+20 tics) to 97.3% (3587+2913+751 tics): Fast run:
27.0% 0 + 76 sun.nio.ch.FileChannelImpl.force0
7.1% 0 + 20 sun.nio.ch.FileDispatcher.pwrite0
[..]
Slow run:
Interpreted + native Method
48.1% 0 + 3587 sun.nio.ch.FileDispatcher.pwrite0
39.1% 0 + 2913 sun.nio.ch.FileChannelImpl.force0
[..]
Stub + native Method
10.1% 0 + 751 sun.nio.ch.FileDispatcher.pwrite0
[..]
GC和汇编可忽略不计。
More facts:
没有任何其他方法显示,----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
- It s either fast or very slow, never something in-between.
- Memory is not a problem, all test machines have at least 8GB, the process uses <200MB
- rebooting the machine does not help
- switching of virus-scanners and similar stuff has no affect
- When the process is slow, there is virtually no CPU usage
- It is never slow when running it from a normal JVM
- It is pretty consistently slow when running it in a JVM that was started from the first JVM (via ProcessBuilder or as ant-task)
- All JVMs are exactly the same. I output System.getProperty("java.home") and the JVM options via RuntimeMXBean RuntimemxBean = ManagementFactory.getRuntimeMXBean(); List arguments = RuntimemxBean.getInputArguments();
- I tested it on two machines with Windows7 64bit, Java 7u2, Java 6u26 and JRockit, the hardware of the machines differs, though, but the results are very similar.
- I tested it also from outside Eclipse (command-line ant) but no difference there.
- The whole program is written by myself, all it does is reading and writing to/from this file, no other libraries are used, especially no native libraries. -
我只是拒绝相信有任何意义的一些 facts的事实:
- Removing all class files and rebuilding the project sometimes (rarely) helps. The program (nested version) runs fast one or two times before becoming extremely slow again.
- Installing a new JVM always helps (every single time!) such that the (nested) program runs fast at least once! Installing a JDK counts as two because both the JDK-jre and the JRE-jre work fine at least once. Overinstalling a JVM does not help. Neither does rebooting. I haven t tried deleting/rebooting/reinstalling yet ...
- These are the only two ways I ever managed to get fast program runtimes for the nested program.
问题:
- What may cause this performance drop for nested JVMs?
- What exactly do these methods do (pwrite0/force0)? -