简体   繁体   English

如何在Servlet中改善org.apache.commons.io.FileUtils copyInputStreamToFile

[英]How to improve org.apache.commons.io.FileUtils copyInputStreamToFile in Servlet

I am working on a servlet which does receive attachments in a HTTP POST multipart message. 我正在使用一个servlet,它确实会收到HTTP POST多部分消息中的附件。 These files have to be stored to a mounted filesystem. 这些文件必须存储到已挂载的文件系统中。 It all does work well, only the performance is not what i would expect based on the IO tests i ran on the filesystem. 一切都很好,只是性能不是我在文件系统上运行的IO测试所期望的。

On my machine i have 2 filesystems, a local filesystem FSA and a CIFS filesystem FSB hosted on another host. 在我的机器上,我有2个文件系统,一个本地文件系统FSA和另一个主机上托管的CIFS文件系统FSB。 The FSB has to be used when going live, FSA i used for comparing the performance of FSB. 上线时必须使用FSB,FSA用于比较FSB的性能。 When i test throughput and latency of the filesystem with the following commands; 当我使用以下命令测试文件系统的吞吐量和延迟时;

througput dd if=/dev/zero of=$FS/test.img bs=1G count=1 oflag=dsync latency dd if=/dev/zero of=$FS/test.img bs=512 count=1000 oflag=dsync 吞吐量dd if=/dev/zero of=$FS/test.img bs=1G count=1 oflag=dsync延迟dd if=/dev/zero of=$FS/test.img bs=512 count=1000 oflag=dsync

i do get the following readings; 我确实得到以下读数;

  • FSA througput 844MB/s, latency 590MB/s FSA吞吐量844MB / s,延迟590MB / s
  • FSB througput 50,4MB/s, latency 116KB/s FSB吞吐量50,4MB / s,延迟116KB / s

To save the file to disk i do use the copInputStreamToFile method from org.apache.commons.io.FileUtils. 要将文件保存到磁盘,请使用org.apache.commons.io.FileUtils中的copInputStreamToFile方法。 There is no possibility to used JDK7 and higher and therefore java.nio is no option. 无法使用JDK7和更高版本,因此java.nio是不可选择的。

// Register starttime of FileIO
startTime = System.currentTimeMillis();

// Fastest way to write stream to file
FileUtils.copyInputStreamToFile(formFieldStream, newFile);
LOG.info(String.format("[Session: %s] [Operation: maakaan io] [File: %s] [%s ms]",
    sessionID, fileNaam,
    (System.currentTimeMillis() - startTime)));

When saving a 110MB file with this servlet to FSA it takes around 10 seconds, on FSB around 13 seconds. 使用此servlet将110MB文件保存到FSA时,大约需要10秒,而FSB则需要大约13秒。 So the filesystem of choice makes a difference, but the difference in writing speed does not correspond the measured througput differences. 因此,选择的文件系统会有所不同,但写入速度的差异并不对应于测得的吞吐量差异。 When using the designated filesystem FSB, writing a file from the Java code is with about 10MB/s still much slower then when writing it directly using dd. 当使用指定的文件系统FSB时,与直接使用dd直接写入文件相比,从Java代码写入文件的速度大约要慢10MB / s。 Since i am using a large file in the test, i chose to use the measured througput of the filesystems. 由于我在测试中使用的是大文件,因此我选择使用测量的文件系统吞吐量。

Are there any options to improve the writing speed of this servlet or how to determine what is causing the 'sluggishnes' 是否有任何选择可以提高此Servlet的写入速度,或者如何确定是什么原因导致了“缓慢”

Cheers, Peter 干杯,彼得

== Update 1 == ==更新1 ==

It seems that there is a buffer of 4K in the implementation of FileUtils.copyInputStreamToFile and org.apache.commons.fileupload. 在FileUtils.copyInputStreamToFile和org.apache.commons.fileupload的实现中似乎有4K的缓冲区。 I can also see this when making analyzing the flightrecording (JRockit). 在进行飞行记录(JRockit)分析时,我也可以看到这一点。 I have been able to increase the write buffer. 我已经能够增加写缓冲区。 Now working to see if i can workaround the buffer in fileUploader. 现在工作,看看我是否可以解决fileUploader中的缓冲区。

The I/O tests you ran on the file system using a virtual source are irrelevant. 使用虚拟源在文件系统上运行的I / O测试无关紧要。 The limiting factor here is the network, which is orders of magnitude slower than the file system, or the CPU, or Java, or IOUtils . 这里的限制因素是网络,它比文件系统,CPU,Java或IOUtils

暂无
暂无

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

相关问题 org.apache.commons.io.FileUtils-更改文本编码 - org.apache.commons.io.FileUtils - change text encodig 使用Netbeans 8.0.2,并希望使用org.apache.commons.io.FileUtils; 怎么样? - Using Netbeans 8.0.2 and want to use org.apache.commons.io.FileUtils; how? 引起原因:java.lang.ClassNotFoundException:org.apache.commons.io.FileUtils,maven pom.xml wa - Caused by: java.lang.ClassNotFoundException: org.apache.commons.io.FileUtils, maven pom.xml wa 我有导入org.apache.commons.io.FileUtils; 在我的代码中,它适用于eclipse但不适用于命令行 - I have import org.apache.commons.io.FileUtils; in my code and it works on eclipse but not in command line Java库,例如org.apache.commons.io.FileUtils,但包含实例方法而不是静态方法 - Java library like org.apache.commons.io.FileUtils but contains instance methods instead of static methods 使用org.apache.commons.io.FileUtils时Android内存泄漏 - Android memory leak when using org.apache.commons.io.FileUtils java.lang.NoSuchMethodError: org.apache.commons.io.FileUtils.copyInputStreamToFile(Ljava/io/InputStream;Ljava/io/File;) - java.lang.NoSuchMethodError: org.apache.commons.io.FileUtils.copyInputStreamToFile(Ljava/io/InputStream;Ljava/io/File;) org / apache / commons / io / FileUtils-NoClassDefFoundError - org/apache/commons/io/FileUtils - NoClassDefFoundError 在 org.apache.commons.io.FileUtils.copyURLToFile 上设置超时? - Set timeout on org.apache.commons.io.FileUtils.copyURLToFile? org.apache.commons.io.FileUtils.readFileToString 和文件路径中的空白 - org.apache.commons.io.FileUtils.readFileToString and blanks in filepath
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM