简体   繁体   English

为什么在Citrix上第一次调用java.io.File.createTempFile(String,String,File)需要5秒钟?

[英]Why does first call to java.io.File.createTempFile(String,String,File) take 5 seconds on Citrix?

While debugging slow startup of an Eclipse RCP app on a Citrix server, I came to find out that java.io.createTempFile(String,String,File) is taking 5 seconds. 在Citrix服务器上调试Eclipse RCP应用程序的缓慢启动时,我发现java.io.createTempFile(String,String,File)需要5秒钟。 It does this only on the first execution and only for certain user accounts. 它仅在第一次执行时才执行此操作,并且仅对某些用户帐户执行此操作。 Specifically, I am noticing it Citrix anonymous user accounts. 具体来说,我注意到它是Citrix匿名用户帐户。 I have not tried many other types of accounts, but this behavior is not exhibited with an administrator account. 我没有尝试过许多其他类型的帐户,但是管理员帐户没有出现这种现象。

Also, it does not matter if the user has access to write to the given directory or not. 同样,用户是否有权写入给定目录也没有关系。 If the user does not have access, the call will take 5 seconds to fail. 如果用户没有访问权限,则呼叫将花费5秒钟才能失败。 If they do have access, the call with take 5 seconds to succeed. 如果他们确实可以访问,则呼叫需要5秒钟才能成功。

This is on a Windows 2003 Server. 这是在Windows 2003 Server上。 I've tried Sun's 1.6.0_16 and 1.6.0_19 JREs and see the same behavior. 我尝试了Sun的1.6.0_16和1.6.0_19 JRE,并看到了相同的行为。

I googled a bit expecting this to be some sort of known issue, but didn't find anything. 我在Google上搜索了一下,期望这是某种已知问题,但没有发现任何东西。 It seems like someone else would have had to have run into this before. 似乎以前其他人可能不得不遇到过这种情况。

The Eclipse Platform uses File.createTempFile() to test various directories to see if they are writeable during initialization and this issue adds 5 seconds to the startup time of our application. Eclipse平台使用File.createTempFile()来测试各种目录,以查看它们在初始化期间是否可写,并且此问题使应用程序的启动时间增加了5秒。

I imagine somebody has run into this before and might have some insight. 我想象以前有人遇到过这种情况,也许会有一些见识。 Here is sample code I executed to see that it is indeed this call that is consuming the time. 这是我执行的示例代码,它确实是在浪费时间的此调用。 I also tried it with a second call to createTempFile and notice that subsequent calls return nearly instantaneously. 我还尝试了第二次调用createTempFile,并注意随后的调用几乎立即返回。

public static void main(final String[] args) throws IOException {
        final File directory = new File(args[0]);
        final long startTime = System.currentTimeMillis();
        File file = null;
        try {
            file = File.createTempFile("prefix", "suffix", directory);
            System.out.println(file.getAbsolutePath());
        } finally {
            System.out.println(System.currentTimeMillis() - startTime);
            if (file != null) {
                file.delete();
            }
        }
    }

Sample output of this program is the following: 该程序的示例输出如下:

C:\>java.exe -jar filetest.jar C:/Temp
C:\Temp\prefix8098550723198856667suffix
5093

It might be the intialisation of the secure random number generator which is causing the problem. 可能是安全随机数生成器的初始化导致了问题。 In particular if a secure random seed is not obtainable from the operating system, then the fall-back mechanism attempts to gain entropy. 特别是,如果无法从操作系统获得安全的随机种子,则回退机制将尝试获取熵。 IIRC, one of the things it does is to list temporary files, so if you have a large number of those that will not help start-up performance. IIRC的功能之一就是列出临时文件,因此,如果其中包含大量文件,将对启动性能没有帮助。

It looks like the slowness is due to the seeding of SecureRandom and only when the user is a member of the Guests group. 看来速度缓慢是由于SecureRandom的播种所致,并且仅当用户是Guests组的成员时才如此。

The SecureRandom seed initialization uses a Windows Crypto API which fails when the user is a guest as described here [1]. SecureRandom种子初始化使用Windows Crypto API,当用户为访客时,Windows Crypto API将失败,如此处所述[1]。 By setting the system property "java.security.debug" equal to "all", I can see the following when the program as run as a guest: 通过将系统属性“ java.security.debug”设置为等于“ all”,当该程序以访客身份运行时,我可以看到以下内容:

ProviderConfig: Loaded provider SUN version 1.6
provider: Failed to use operating system seed generator: java.io.IOException: Required native CryptoAPI features not available on this machine
provider: Using default threaded seed generator

When run as non-guest user, the output is this: 以非来宾用户身份运行时,输出为:

ProviderConfig: Loaded provider SUN version 1.6
provider: Using operating system seed generator

It appears the default threaded seed generator is quite slow. 似乎默认的线程种子生成器非常慢。 Here [2] is a very old bug logged to Sun about this. 这里[2]是一个非常老的错误,已记录到Sun上。

[1] http://www.derkeiler.com/Newsgroups/microsoft.public.platformsdk.security/2003-12/0349.html [1] http://www.derkeiler.com/Newsgroups/microsoft.public.platformsdk.security/2003-12/0349.html

[2] http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4210047 [2] http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4210047

I'm not a Citrix expert, but I know someone who is, and who conjectures: 我不是Citrix专家,但我知道是谁,并且谁猜想:

The accounts may be set up so that application reads/writes are redirected to non-local resources. 可以设置帐户,以便将应用程序读/写重定向到非本地资源。 The latency you're experiencing may be related to the initialization or performance of that resolution. 您遇到的延迟可能与该分辨率的初始化或性能有关。

Another possibility is that the application isolation may be in effect, which means file reads/writes happen on virtualized versions of resources. 另一种可能性是应用程序隔离可能有效,这意味着文件的读/写发生在资源的虚拟版本上。

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

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