Your SlideShare is downloading. ×
0
Optimize Performance of I/O-intensive Java applications Using Zero Copy
Optimize Performance of I/O-intensive Java applications Using Zero Copy
Optimize Performance of I/O-intensive Java applications Using Zero Copy
Optimize Performance of I/O-intensive Java applications Using Zero Copy
Optimize Performance of I/O-intensive Java applications Using Zero Copy
Optimize Performance of I/O-intensive Java applications Using Zero Copy
Optimize Performance of I/O-intensive Java applications Using Zero Copy
Optimize Performance of I/O-intensive Java applications Using Zero Copy
Optimize Performance of I/O-intensive Java applications Using Zero Copy
Optimize Performance of I/O-intensive Java applications Using Zero Copy
Optimize Performance of I/O-intensive Java applications Using Zero Copy
Optimize Performance of I/O-intensive Java applications Using Zero Copy
Optimize Performance of I/O-intensive Java applications Using Zero Copy
Optimize Performance of I/O-intensive Java applications Using Zero Copy
Optimize Performance of I/O-intensive Java applications Using Zero Copy
Optimize Performance of I/O-intensive Java applications Using Zero Copy
Optimize Performance of I/O-intensive Java applications Using Zero Copy
Optimize Performance of I/O-intensive Java applications Using Zero Copy
Optimize Performance of I/O-intensive Java applications Using Zero Copy
Optimize Performance of I/O-intensive Java applications Using Zero Copy
Optimize Performance of I/O-intensive Java applications Using Zero Copy
Optimize Performance of I/O-intensive Java applications Using Zero Copy
Optimize Performance of I/O-intensive Java applications Using Zero Copy
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Optimize Performance of I/O-intensive Java applications Using Zero Copy

3,816

Published on

This session explains how you can improve performance of I/O-intensive Java™ applications through a technique called zero copy. Zero copy lets you to avoid redundant data copies between intermediate …

This session explains how you can improve performance of I/O-intensive Java™ applications through a technique called zero copy. Zero copy lets you to avoid redundant data copies between intermediate buffers and reduces number of context switches between user and kernel space.

Background: Many applications [Web Servers, FTP-like services] serve a significant amount of static content, which amounts to reading data off of a disk and writing the exact data back to the response socket. Each time data traverses the user-kernel boundary; it must be copied, which consumes CPU cycles and memory bandwidth. Fortunately, we can eliminate these copies through a technique called — zero copy.

The Java class libraries support zero copy on Linux and UNIX systems through the transferTo() method in java.nio.channels.FileChannel.

Session Agenda: The session will initially focus on “Zero Copy” concept and its relevance in Data transfer applications. The traditional approach of transferring data b/w processes using File and Socket I/O will be explained in detail. It will demonstrate the overhead incurred when using traditional copy semantics, and will show how transferTo() achieves better performance. transferTo() API brings down the time 65% compared to traditional approach.

Summary
The Session demonstrates performance advantages of using transferTo() compared to the traditional approach. Intermediate buffer copies — even those hidden in the kernel — can have a measurable cost. In applications that do a great deal of copying of data between channels, zero-copy technique can offer a significant performance improvement.

Published in: Technology, Education
0 Comments
4 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
3,816
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
58
Comments
0
Likes
4
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Zero Copy: A Green Approach to Data Transfer Pramod B Nagaraja IBM India Pvt LTD
  • 2. Agenda  Zero Copy  Data Transfer : Age-Old Practice  Data Transfer : Best Practice  Performance Comparison  Application Scenario  Limitations  Conclusion
  • 3. What is Zero Copy ? • Data transfer from disk to user buffers without an intermediate copy into OS Kernel buffers • Computer operations in which CPU does not perform the task of copying data from one memory area to another • DMA • MMU
  • 4. What is Zero Copy ? • Fewer intermediate Data Copies, fewer context switches • Linux :: sendfile, sendfile64
  • 5. Agenda  Zero Copy  Data Transfer : Age-Old Practice  Data Transfer : Best Practice  Performance Comparison  Application Scenario  Limitations  Conclusion
  • 6. Application Scenario
  • 7. Data Transfer : Age-Old Practice File.read(fd, buf, len); Socket.send(socket, buf, len); inputStream = new FileInputStream(fname); output = new DataOutputStream(socket.getOutputStream()); byte[] b = new byte[4096]; long read = 0, total = 0; while((read = inputStream.read(b))>=0) { total = total + read; output.write(b); }
  • 8. Data Transfer : Age-Old Practice  4 Data Copies
  • 9. Data Transfer : Age-Old Practice  4 Context Switches
  • 10. Agenda  Zero Copy  Data Transfer : Age-Old Practice  Data Transfer : Best Practice  Performance Comparison  Application Scenario  Limitations  Conclusion
  • 11. Data Transfer : Best Practice  FileChannel Approach java.nio.channels.FileChannel.transferTo(pos, cnt, writableChannel); SocketChannel sc = SocketChannel.open(); sc.connect(sad); FileChannel fc = new FileInputStream(fname).getChannel(); long nsent = 0, curnset = 0; curnset = fc.transferTo(0, fsize, sc);
  • 12. Data Transfer : Best Practice  3 Data Copies
  • 13. Data Transfer : Best Practice  2 Context Switches
  • 14. Agenda  Zero Copy  Data Transfer : Age-Old Practice  Data Transfer : Best Practice • Performance Comparison  Application Scenario  Limitations  Conclusion
  • 15. Performance Comparison • ~ 65% Performance Boost up ! 0 2000 4000 6000 8000 10000 12000 14000 16000 18000 63 M B 350 M B 1 GB Traditio nal FileCha nnel Measurements take on Linux (xi32) with 2.6 kernel
  • 16. Agenda  Zero Copy  Data Transfer : Age-Old Practice  Data Transfer : Best Practice  Performance Comparison • Application Scenario • Limitations • Conclusion
  • 17. Application Scenario  FTP Servers  Web Servers  Mail Servers  Any Applications serving static content
  • 18. Agenda  Zero Copy  Data Transfer : Age-Old Practice  Data Transfer : Best Practice  Performance Comparison  Application Scenario • Limitations • Conclusion
  • 19. Theoretically Speaking there is no difference b/w Theory and Practice .. but in Practice there is !!
  • 20. Limitations  Suitable only for static content  Not suitable if Data to be transferred needs to be modified/appended with/appended to, etc  FileChannels can only be used to transfer data from File to File, File to Socket objects.
  • 21. References  More details can be found @ http://www.ibm.com/developerworks/library/j- zerocopy/index.html  http://www.linuxjournal.com/article/6345
  • 22. Q&A
  • 23. Thank You !!!!

×