Zero Copy: A Green Approach
to Data Transfer
Pramod B Nagaraja
IBM India Pvt LTD
Agenda

Zero Copy

Data Transfer : Age-Old Practice

Data Transfer : Best Practice

Performance Comparison

Applicati...
What is Zero Copy ?
•
Data transfer from disk to user buffers without
an intermediate copy into OS Kernel buffers
•
Comput...
What is Zero Copy ?
•
Fewer intermediate Data Copies, fewer
context switches
•
Linux :: sendfile, sendfile64
Agenda

Zero Copy

Data Transfer : Age-Old Practice

Data Transfer : Best Practice

Performance Comparison

Applicati...
Application Scenario
Data Transfer : Age-Old Practice
File.read(fd, buf, len);
Socket.send(socket, buf, len);
inputStream = new FileInputStream...
Data Transfer : Age-Old Practice

4 Data Copies
Data Transfer : Age-Old Practice

4 Context Switches
Agenda

Zero Copy

Data Transfer : Age-Old Practice

Data Transfer : Best Practice

Performance Comparison

Applicati...
Data Transfer : Best Practice

FileChannel Approach
java.nio.channels.FileChannel.transferTo(pos, cnt, writableChannel);
...
Data Transfer : Best Practice
 3 Data Copies
Data Transfer : Best Practice
 2 Context Switches
Agenda

Zero Copy

Data Transfer : Age-Old Practice

Data Transfer : Best Practice
•
Performance Comparison

Applicati...
Performance Comparison
• ~ 65% Performance Boost up !
0
2000
4000
6000
8000
10000
12000
14000
16000
18000
63
M B
350
M B
1...
Agenda

Zero Copy

Data Transfer : Age-Old Practice

Data Transfer : Best Practice

Performance Comparison
•
Applicati...
Application Scenario

FTP Servers

Web Servers

Mail Servers

Any Applications serving static content
Agenda

Zero Copy

Data Transfer : Age-Old Practice

Data Transfer : Best Practice

Performance Comparison

Applicati...
Theoretically Speaking there is no difference
b/w Theory and Practice .. but in Practice
there is !!
Limitations

Suitable only for static content

Not suitable if Data to be transferred needs to
be modified/appended with...
References

More details can be found @
http://www.ibm.com/developerworks/library/j-
zerocopy/index.html

http://www.lin...
Q&A
Thank You !!!!
Upcoming SlideShare
Loading in...5
×

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

3,991

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 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,991
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
62
Comments
0
Likes
4
Embeds 0
No embeds

No notes for slide

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

  1. 1. Zero Copy: A Green Approach to Data Transfer Pramod B Nagaraja IBM India Pvt LTD
  2. 2. Agenda  Zero Copy  Data Transfer : Age-Old Practice  Data Transfer : Best Practice  Performance Comparison  Application Scenario  Limitations  Conclusion
  3. 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. 4. What is Zero Copy ? • Fewer intermediate Data Copies, fewer context switches • Linux :: sendfile, sendfile64
  5. 5. Agenda  Zero Copy  Data Transfer : Age-Old Practice  Data Transfer : Best Practice  Performance Comparison  Application Scenario  Limitations  Conclusion
  6. 6. Application Scenario
  7. 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. 8. Data Transfer : Age-Old Practice  4 Data Copies
  9. 9. Data Transfer : Age-Old Practice  4 Context Switches
  10. 10. Agenda  Zero Copy  Data Transfer : Age-Old Practice  Data Transfer : Best Practice  Performance Comparison  Application Scenario  Limitations  Conclusion
  11. 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. 12. Data Transfer : Best Practice  3 Data Copies
  13. 13. Data Transfer : Best Practice  2 Context Switches
  14. 14. Agenda  Zero Copy  Data Transfer : Age-Old Practice  Data Transfer : Best Practice • Performance Comparison  Application Scenario  Limitations  Conclusion
  15. 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. 16. Agenda  Zero Copy  Data Transfer : Age-Old Practice  Data Transfer : Best Practice  Performance Comparison • Application Scenario • Limitations • Conclusion
  17. 17. Application Scenario  FTP Servers  Web Servers  Mail Servers  Any Applications serving static content
  18. 18. Agenda  Zero Copy  Data Transfer : Age-Old Practice  Data Transfer : Best Practice  Performance Comparison  Application Scenario • Limitations • Conclusion
  19. 19. Theoretically Speaking there is no difference b/w Theory and Practice .. but in Practice there is !!
  20. 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. 21. References  More details can be found @ http://www.ibm.com/developerworks/library/j- zerocopy/index.html  http://www.linuxjournal.com/article/6345
  22. 22. Q&A
  23. 23. Thank You !!!!
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×