標籤:
參考: https://www.ibm.com/developerworks/linux/library/j-zerocopy/
這篇文章介紹了 zerocopy技術來提高Linux平台上的IO密集型的JAVA應用程式的效能.
zerocopy技術能夠避免中間緩衝區中的冗餘資料複製以及減少Linux核心空間和使用者空間上下文交換的次數。
適用情境:Many Web applications serve a significant amount of static content, which amounts to reading data off of a disk and writing the exact same data back to the response socket.
應用程式從本地磁碟讀取資料,再將讀取的資料原封不動地發送給Socket。
不採用zerocopy技術時的資料轉送過程如下:
the kernel reads the data off of disk and pushes it across the kernel-user boundary to the application, and then the application pushes it back across the kernel-user boundary to be written out to the socket. In effect, the application serves as an inefficient intermediary that gets the data from the disk file to the socket.
資料先從本地磁碟讀取到核心空間中,再通過緩衝區由使用者程式得到,使用者程式再通過緩衝區將資料發送到Socket。
Each time data traverses the user-kernel boundary, it must be copied, which consumes CPU cycles and memory bandwidth. Fortunately, you can eliminate these copies through a technique called — appropriately enough — zero copy.
每次資料轉送到 核心-使用者 緩衝區時,必須進行複製,這消耗了CPU和記憶體,而通過 zerocopy技術 可以去掉複製操作。
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.
使用者程式通過zerocopy請求使得資料直接從核心發送到Socket。
JAVA類庫通過java.nio.channels.FileChannel. transferTo()方法支援zerocopy技術。
You can use the transferTo() method to transfer bytes directly from the channel on which it is invoked to another writable byte channel, without requiring data to flow through the application。
JAVA NIO 中的 zerocopy 技術提高IO效能