optimize performance of i/o-intensive java applications using zero copy

23
Zero Copy: A Green Approach to Data Transfer Pramod B Nagaraja IBM India Pvt LTD

Upload: indicthreads

Post on 12-Jul-2015

3.904 views

Category:

Technology


6 download

TRANSCRIPT

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

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

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

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

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

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

Application Scenario

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

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

Data Transfer : Age-Old Practice

4 Data Copies

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

Data Transfer : Age-Old Practice

4 Context Switches

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

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

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

Data Transfer : Best Practice

3 Data Copies

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

Data Transfer : Best Practice

2 Context Switches

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

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

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

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

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

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

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

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

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

Q&A

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

Thank You !!!!