On 8/29/07, Rob Butler <[EMAIL PROTECTED]> wrote: > > Hello all, > > I've a few quick questions regarding byte buffers and recycling in Mina. > > Let's say I've got two connections to a Mina server. I'm sending messages > consisting of a "header" and "body" and I want to move messages these > between the two connections. The header on the incoming message will be > stripped off and replaced with a new header before the message is sent to > the other connection. With fixed size headers I'd normally use scatter > gather operations to efficiently "parse" these messages into the two > parts. Is this still possible with Mina? How would I do this? > > The key to building an efficient server is to minimize GC.
Actually you really can't do too much with GC after setting the some parameters of JVM. I found out GC worked good unless you faced OOM problems with "memory leaks" caused by not proper coding. To build a efficient server is much more than minimizing GC, I believe. To that end, my initial though for passing messages between these two > connections is to simply take the byte buffer passed during messageReceived > and pass it to the other IoSession.write(..). But I don't think this will > work properly because of byte buffer recycling. The incoming byte buffer > could be "recycled" by mina before the outgoing IoSession.write(..) > happened. This would cause corruption of the data. Why data is corrupted? I believe if you need to change the header, you have to do something in your business logic, at least you need to find the outgoing connection. What is the best way to move bytes between two streams without > unnecessarily creating lots of short lived buffers or other objects? > > One of the benefits of NIO is moving bytes between streams "in the > kernel". I.E. you don't have to bring the data into "user space" to copy > it from one stream to another and this reduces kernel context switches. How > do I take advantage of this in Mina? > > Basically I'm looking for the most efficient way to move bytes from one > stream to another. These bytes will actually be "messages" with a header > and body. The header will be changed between reception and transmission. I > also need to perform some routing logic using the header. If necessary for > efficiency I could use a fixed size header, but would prefer not to. > > A rapid response would be greatly appreciated. > Thanks! > Rob > > > > > > > > > ____________________________________________________________________________________ > Moody friends. Drama queens. Your life? Nope! - their life, your story. > Play Sims Stories at Yahoo! Games. > http://sims.yahoo.com/ >
