The performance gain is not related to the nature of the buffer; I mean writing to an HeapBuffer vs writing to a DirectBuffer but related to writing the buffer to the socket: if you write an HeapBuffer to a socket, my guess is that it will be copied to a DirectBuffer before it gets written to the socket which is not the case for a DirectBuffer
Jeff On Thu, Jan 10, 2013 at 10:47 AM, Steve Ulrich <steve.ulr...@proemion.com>wrote: > Hi! > > I saw some benchmarks of direct vs. heap buffers - but I can't remember a > single one where direct buffers were a *big* performance gain. If you're > copying the buffers just to make it perform better, you'll probably get a > huge performance penality caused by the copy-logic itself. > > Maybe it's possible to remove the copy-logic by using a "duplicate()" of > the original buffer. This copies only the ByteBuffer-Wrapper, not the > underlying array. > There is still a tradeoff: Application logic must make sure to not change > the buffers content anymore! If it does, it gets really ugly. > Shouldn't be a problem for Encoders, but may be if the application reuses > the buffer (IMHO a bad Idea, anyway) > > regards > > Steve Ulrich > > > > Emmanuel Lécharny [mailto:elecha...@gmail.com] wrote: > > > > Le 1/9/13 11:54 AM, Jeff MAURY a écrit : > > > The problem I see if you choose to copy the user buffer into a > > DirectBuffer > > > is that your memory consumption will double even if the DirectBuffer > > is not > > > allocated on the heap, it may be problematic > > It will double only the time necessary to copy the buffer. Then you can > > discard the HeapBuffer... > > > > All in all, this is currently what happens behind the curtain, as NIO > > copies the HeapBuffer into a HeapBuffer. Doing it on our layer gives us > > some control. > > > > -- > > Regards, > > Cordialement, > > Emmanuel Lécharny > > www.iktek.com > > > > > > > > -------------------------------------------------------------------------- > PROEMION GmbH > > Steve Ulrich > > IT Development (IT/DEV) > > Donaustrasse 14 > D-36043 Fulda, Germany > Phone +49 (0) 661 9490-601 > Fax +49 (0) 661 9490-333 > > http://www.proemion.com > > Geschäftsführer: Dipl. Ing. Robert Michaelides > Amtsgericht-Registergericht-Fulda: 5 HRB 1867 > -------------------------------------------------------------------------- > E-mail and any attachments may be confidential. If you have received this > E-mail and you are not a named addressee, please inform the sender > immediately by E-mail and then delete this E-mail from your system. If you > are not a named addressee, you may not use, disclose, distribute, copy or > print this E-mail. Addressees should scan this E-mail and any attachments > for viruses. No representation or warranty is made as to the absence of > viruses in this E-mail or any of its attachments. > > AKTUELLES: > http://www.proemion.de > > NEWS: > http://www.proemion.com > > > -- Jeff MAURY "Legacy code" often differs from its suggested alternative by actually working and scaling. - Bjarne Stroustrup http://www.jeffmaury.com http://riadiscuss.jeffmaury.com http://www.twitter.com/jeffmaury