简体   繁体   English

你如何在java中编写零副本? 主要区别是什么

[英]How do you write zero copy in java? What are the main differences

I was reading about how you can use the java nio library to take advantage of file transfer/buffering at the O/S level which is called 'zero copy'.我正在阅读有关如何使用 java nio 库来利用 O/S 级别的文件传输/缓冲(称为“零复制”)的信息。

What are the differences in how you create/write to files then?那么,您创建/写入文件的方式有何不同? Are there any drawbacks to using zero-copy?使用零拷贝有什么缺点吗?

zero copy means that your program will not transfer the data from the kernel space to the user space and so on.零拷贝意味着你的程序不会将数据从内核空间传输到用户空间等等。 this is faster nice article can be found here: http://www.ibm.com/developerworks/library/j-zerocopy/这是更快的好文章,可以在这里找到: http : //www.ibm.com/developerworks/library/j-zerocopy/

Zero copy is a technique where the application is no longer the 'middleman' in transferring data from a disk to the socket.零复制是一种技术,在这种技术中,应用程序不再是将数据从磁盘传输到套接字的“中间人”。 Applications that use zero copy request that the kernel copy the data directly from the disk file to the socket, without going through the application, which improves performance and reduces context switches.使用零复制的应用程序要求内核直接将数据从磁盘文件复制到套接字,而无需通过应用程序,从而提高性能并减少上下文切换。

It all depends on what the application will do with the data it reads from disks.这完全取决于应用程序将如何处理它从磁盘读取的数据。 If it is a web application serving a lot of static content by reading files and relaying them over sockets, then zero copy is the way to go in order to get better performance.如果它是一个通过读取文件并通过套接字中继它们来提供大量静态内容的 Web 应用程序,那么零复制是获得更好性能的方法。 However, if the application is using the data locally (either crunching it in some way and then writing it back, or displaying it locally without persisting it back), you would not use zero copy.但是,如果应用程序在本地使用数据(以某种方式对其进行处理然后将其写回,或者在本地显示而不将其持久化),则不会使用零复制。

This IBM DeveloperWorks article about zero copy is a good read.这篇关于零拷贝的IBM DeveloperWorks 文章值得一读。

Other ways of file I/O in java are via the use of Stream classes based on the type of file you would want to read/write. Java 中文件 I/O 的其他方式是通过使用基于您想要读/写的文件类型的 Stream 类。 This involves both buffered and unbuffered streams, although usually buffered streams promise better performance since they cause less I/O seek cycles and hence lesser context switches.这涉及缓冲和未缓冲的流,尽管通常缓冲的流承诺更好的性能,因为它们会导致更少的 I/O 寻道周期,因此更少的上下文切换。

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

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