Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #28627
| Newsgroups | comp.lang.java.programmer |
|---|---|
| Date | 2014-05-31 02:29 -0700 |
| References | <t24en9putph3mbnulkveghdjbrnisp105h@4ax.com> |
| Message-ID | <0f77f8c8-374b-4c3a-a915-2beda6b3e74e@googlegroups.com> (permalink) |
| Subject | Re: NIO not so hot |
| From | Rupert Smith <rupertlssmith@googlemail.com> |
On Saturday, May 17, 2014 12:28:19 PM UTC+1, Roedy Green wrote: > I did a benchmark to read a file of bytes in one I/O then convert it > > to a String a random sample data file of 419,430,400 chars > > 419,430,400 bytes UTF-8. > > // RandomAccess 1.46 seconds > > // InputStream 1.48 seconds > > // NIO 1.56 seconds > > > > NIO is great for grabbing bytes, but if you have to suck them out of > > the buffer, it does a get() call on every byte. > > > > The code is posted at http://mindprod.com/jgloss/nio.html > > > > -- > > Roedy Green Canadian Mind Products http://mindprod.com > > Young man, in mathematics you don't understand things. > > You just get used to them. > > ~ John von Neumann (born: 1903-12-28 died: 1957-02-08 at age: 53) Try using a direct byte buffer which has been pre-allocated. Direct buffers are allocated outside the Java heap (using malloc()?), so the allocation cost is high. They only really provide a performance boost when re-used. Also, if you dig into the internals you will find that a heap buffer reading a file or socket will copy bytes from a direct buffer anyway, and that Java does its own internal pooling/re-allocation of direct buffers. Often benchmarks will say heap buffers are faster, because they allocate buffer then read some data then allow buffer to be garbage collected. In the heap buffer case, the internal direct buffer pool is being used. In the direct buffer case, a new one is being allocated each time, which is slow. I may be wrong but... are the byte get()/set() calls not trapped by some compiler intrinsics and optimized away? I did a lot of performance testing around NIO working for a company that developed a FIX engine. Independent testing was carried out by Intel, and we were every bit as fast as the best C++ engines (once JIT compilation was done anyway). Developing your own pooling mechanism for direct buffers is definitely the way to go if you really want to make your code as fast as possible. Allocation costs and memory copying need to be avoided as much as possible. That said, zero copy IO is still largely a myth. Rupert
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
NIO not so hot Roedy Green <see_website@mindprod.com.invalid> - 2014-05-17 04:28 -0700
Re: NIO not so hot Robert Klemme <shortcutter@googlemail.com> - 2014-05-18 13:38 +0200
Re: NIO not so hot Robert Klemme <shortcutter@googlemail.com> - 2014-05-18 13:38 +0200
Re: NIO not so hot Robert Klemme <shortcutter@googlemail.com> - 2014-05-18 14:12 +0200
Re: NIO not so hot Robert Klemme <shortcutter@googlemail.com> - 2014-05-18 19:09 +0200
Re: NIO not so hot Roedy Green <see_website@mindprod.com.invalid> - 2014-05-26 00:51 -0700
Re: NIO not so hot Robert Klemme <shortcutter@googlemail.com> - 2014-05-26 20:14 +0200
Re: NIO not so hot Roedy Green <see_website@mindprod.com.invalid> - 2014-05-26 01:15 -0700
Re: NIO not so hot Roedy Green <see_website@mindprod.com.invalid> - 2014-05-26 01:24 -0700
Re: NIO not so hot Robert Klemme <shortcutter@googlemail.com> - 2014-05-26 23:50 +0200
Re: NIO not so hot Rupert Smith <rupertlssmith@googlemail.com> - 2014-05-31 02:29 -0700
Re: NIO not so hot Robert Klemme <shortcutter@googlemail.com> - 2014-06-01 12:15 +0200
Re: NIO not so hot Rupert Smith <rupertlssmith@googlemail.com> - 2014-06-02 07:37 -0700
Re: NIO not so hot Robert Klemme <shortcutter@googlemail.com> - 2014-06-03 23:07 +0200
Re: NIO not so hot Rupert Smith <rupertlssmith@googlemail.com> - 2014-06-06 01:32 -0700
Re: NIO not so hot Rupert Smith <rupertlssmith@googlemail.com> - 2014-06-02 07:46 -0700
csiph-web