optimize performance of i/o-intensive java applications using zero copy
TRANSCRIPT
![Page 1: Optimize Performance of I/O-intensive Java applications Using Zero Copy](https://reader034.vdocuments.site/reader034/viewer/2022042817/55a1d7341a28ab00328b4805/html5/thumbnails/1.jpg)
Zero Copy: A Green Approach to Data Transfer
Pramod B Nagaraja
IBM India Pvt LTD
![Page 2: Optimize Performance of I/O-intensive Java applications Using Zero Copy](https://reader034.vdocuments.site/reader034/viewer/2022042817/55a1d7341a28ab00328b4805/html5/thumbnails/2.jpg)
Agenda Zero Copy Data Transfer : Age-Old Practice Data Transfer : Best Practice Performance Comparison Application Scenario Limitations Conclusion
![Page 3: Optimize Performance of I/O-intensive Java applications Using Zero Copy](https://reader034.vdocuments.site/reader034/viewer/2022042817/55a1d7341a28ab00328b4805/html5/thumbnails/3.jpg)
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
![Page 4: Optimize Performance of I/O-intensive Java applications Using Zero Copy](https://reader034.vdocuments.site/reader034/viewer/2022042817/55a1d7341a28ab00328b4805/html5/thumbnails/4.jpg)
What is Zero Copy ?
• Fewer intermediate Data Copies, fewer context switches
• Linux :: sendfile, sendfile64
![Page 5: Optimize Performance of I/O-intensive Java applications Using Zero Copy](https://reader034.vdocuments.site/reader034/viewer/2022042817/55a1d7341a28ab00328b4805/html5/thumbnails/5.jpg)
Agenda Zero Copy Data Transfer : Age-Old Practice Data Transfer : Best Practice Performance Comparison Application Scenario Limitations Conclusion
![Page 6: Optimize Performance of I/O-intensive Java applications Using Zero Copy](https://reader034.vdocuments.site/reader034/viewer/2022042817/55a1d7341a28ab00328b4805/html5/thumbnails/6.jpg)
Application Scenario
![Page 7: Optimize Performance of I/O-intensive Java applications Using Zero Copy](https://reader034.vdocuments.site/reader034/viewer/2022042817/55a1d7341a28ab00328b4805/html5/thumbnails/7.jpg)
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);
}
![Page 8: Optimize Performance of I/O-intensive Java applications Using Zero Copy](https://reader034.vdocuments.site/reader034/viewer/2022042817/55a1d7341a28ab00328b4805/html5/thumbnails/8.jpg)
Data Transfer : Age-Old Practice
4 Data Copies
![Page 9: Optimize Performance of I/O-intensive Java applications Using Zero Copy](https://reader034.vdocuments.site/reader034/viewer/2022042817/55a1d7341a28ab00328b4805/html5/thumbnails/9.jpg)
Data Transfer : Age-Old Practice
4 Context Switches
![Page 10: Optimize Performance of I/O-intensive Java applications Using Zero Copy](https://reader034.vdocuments.site/reader034/viewer/2022042817/55a1d7341a28ab00328b4805/html5/thumbnails/10.jpg)
Agenda Zero Copy Data Transfer : Age-Old Practice Data Transfer : Best Practice Performance Comparison Application Scenario Limitations Conclusion
![Page 11: Optimize Performance of I/O-intensive Java applications Using Zero Copy](https://reader034.vdocuments.site/reader034/viewer/2022042817/55a1d7341a28ab00328b4805/html5/thumbnails/11.jpg)
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);
![Page 12: Optimize Performance of I/O-intensive Java applications Using Zero Copy](https://reader034.vdocuments.site/reader034/viewer/2022042817/55a1d7341a28ab00328b4805/html5/thumbnails/12.jpg)
Data Transfer : Best Practice
3 Data Copies
![Page 13: Optimize Performance of I/O-intensive Java applications Using Zero Copy](https://reader034.vdocuments.site/reader034/viewer/2022042817/55a1d7341a28ab00328b4805/html5/thumbnails/13.jpg)
Data Transfer : Best Practice
2 Context Switches
![Page 14: Optimize Performance of I/O-intensive Java applications Using Zero Copy](https://reader034.vdocuments.site/reader034/viewer/2022042817/55a1d7341a28ab00328b4805/html5/thumbnails/14.jpg)
Agenda Zero Copy Data Transfer : Age-Old Practice Data Transfer : Best Practice• Performance Comparison Application Scenario Limitations Conclusion
![Page 15: Optimize Performance of I/O-intensive Java applications Using Zero Copy](https://reader034.vdocuments.site/reader034/viewer/2022042817/55a1d7341a28ab00328b4805/html5/thumbnails/15.jpg)
Performance Comparison
• ~ 65% Performance Boost up !
0
2000
4000
6000
8000
10000
12000
14000
16000
18000
63MB
350MB
1GB
Traditional
FileChannel
Measurements take on Linux (xi32) with 2.6 kernel
![Page 16: Optimize Performance of I/O-intensive Java applications Using Zero Copy](https://reader034.vdocuments.site/reader034/viewer/2022042817/55a1d7341a28ab00328b4805/html5/thumbnails/16.jpg)
Agenda Zero Copy Data Transfer : Age-Old Practice Data Transfer : Best Practice Performance Comparison• Application Scenario• Limitations• Conclusion
![Page 17: Optimize Performance of I/O-intensive Java applications Using Zero Copy](https://reader034.vdocuments.site/reader034/viewer/2022042817/55a1d7341a28ab00328b4805/html5/thumbnails/17.jpg)
Application Scenario
FTP Servers Web Servers Mail Servers Any Applications serving static content
![Page 18: Optimize Performance of I/O-intensive Java applications Using Zero Copy](https://reader034.vdocuments.site/reader034/viewer/2022042817/55a1d7341a28ab00328b4805/html5/thumbnails/18.jpg)
Agenda Zero Copy Data Transfer : Age-Old Practice Data Transfer : Best Practice Performance Comparison Application Scenario• Limitations• Conclusion
![Page 19: Optimize Performance of I/O-intensive Java applications Using Zero Copy](https://reader034.vdocuments.site/reader034/viewer/2022042817/55a1d7341a28ab00328b4805/html5/thumbnails/19.jpg)
Theoretically Speaking there is no difference b/w Theory and Practice .. but in Practice
there is !!
![Page 20: Optimize Performance of I/O-intensive Java applications Using Zero Copy](https://reader034.vdocuments.site/reader034/viewer/2022042817/55a1d7341a28ab00328b4805/html5/thumbnails/20.jpg)
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.
![Page 21: Optimize Performance of I/O-intensive Java applications Using Zero Copy](https://reader034.vdocuments.site/reader034/viewer/2022042817/55a1d7341a28ab00328b4805/html5/thumbnails/21.jpg)
References
More details can be found @ http://www.ibm.com/developerworks/library/j-zerocopy/index.html
http://www.linuxjournal.com/article/6345
![Page 22: Optimize Performance of I/O-intensive Java applications Using Zero Copy](https://reader034.vdocuments.site/reader034/viewer/2022042817/55a1d7341a28ab00328b4805/html5/thumbnails/22.jpg)
Q&A
![Page 23: Optimize Performance of I/O-intensive Java applications Using Zero Copy](https://reader034.vdocuments.site/reader034/viewer/2022042817/55a1d7341a28ab00328b4805/html5/thumbnails/23.jpg)
Thank You !!!!