JAVA NIO 中的 zerocopy 技術提高IO效能

來源:互聯網
上載者:User

標籤:

參考: 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效能

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.