Re: Exceptions in MINA
Michael Ossareh wrote: On Mon, Jun 8, 2009 at 3:10 PM, Emmanuel Lecharnyelecha...@apache.org wrote: Michael Ossareh wrote: On Mon, Jun 8, 2009 at 2:13 PM, David Rosenstrauchdar...@darose.net wrote: Michael Ossareh wrote: In the case above the code in messageReceived() cannot trigger assertion failures, the exception they throw is trapped by the framework and JUnit thinks the test passed. I'm using Assert.fail() because the test I'm doing isn't part of JUnit's base tests (though I understand I should start checking out the hamcrest matchers for my tests: http://stackoverflow.com/questions/958460/creating-a-assertclass-method-in-junit ) however using normal assertion fails suffer the same issue, for example assertEquals(1, 2) results in the test passing beacause junit doesn't ever see the exception. Clearly you'll see the power of this type of testing, the 20 or tests I have to write are all structured the same. Connect client to server, either client or server send data, ensure data is rendered same on the receiving side. I'm midway through building a solution to this, however some of it really reinventing the wheel and all because IoHandlerAdapter.messageReceived / sessionOpened / sessionCreated all throw Exception and/or the framework doesn't allow the ability to distinguish different Exceptions from this layer. mike A couple of suggestions: 1) I'd think you really shouldn't need to go through the whole process of fully starting up the server (with a socket listener listening on a port) and a client (opening a socket to the server) just to do testing. I don't know your code so well so perhaps I'm wrong here. But I'd think it should be sufficient to just *simulate* network communication by using a DummySession and sending a message down the server's filter chain and seeing what response - or lack thereof - gets generated. 2) If you follow along with that approach, then you won't be in the situation where your client is performing assertions inside the messageReceived method (which are obviously getting swallowed). If you look carefully at the code I posted, you'll see that what I'm doing is to add an OutputListener - a class that I use only to assist with testing - at the end of my filter chain when I test. The output listener, true to its name, listens to whatever output/response the server's filter chain processing generates, and saves it. Once that whole server filter chain interaction is complete, and I've saved the output from my communication with the server, only THEN do I go about issuing Asserts to verify that the output was what I expected. And since these asserts get done outside of the MINA filter chain processing they never get swallowed. Bottom line: I think you can do any type of JUnit testing you want against your MINA server, but you need to write your tests differently. HTH, DR Hi David, Thanks for your feedback. I noted your example and my reference to solution to this looks not to dissimilar from what you're doing (except I don't want to change the filter chain for fear of creating a difference between prod and dev). The same goes for dummy session. As I get more to grips with MINA I'm sure my assertions as to how to build the tests will change. I would add to the very sensitive proposals David have suggested that whatever you do in your unit tests, trying to keep them close to what you will have in prod by simulating the full stack (ie, with sockets and server) is probably impossible : it will just test that the loopback interface works well, with time conditions totally different to what you will have in prod anyway. This is a valid point for sure. In particular I'm trying to test some decoders and encoders that I've written to implement a custom binary protocol. It wasn't clear to me, and I appreciate that MINA is work in progress, how to get an entity to send an object through a filter chain, and then another entity decode that object. As an easier way of doing this I decided to fire up a server and a client. As far as my testing goes I now have a nice black box solution, the server and client deal with call backs where the assertions are trapped in the case of a failure and reported back once outside of the MINA framework. This is what is difficult when it comes to test a server : unit tests are just good enough to check the internal logic (ie, the encoder/decoder, the handler), but you need to build a bench with a real server, real injectors, etc. Note that testing your application with real sockets is also good to have, as you may encounter some weird conditions too. Thanks for using MINA, btw ! I'm extremely thankful for MINA! A number of years ago I tried to write an opensource java dhcpd - the point being to have web service calls at particular parts of the state machine to do things like mac address authentication, etc. Now with MINA I'm sure I can ressurect that
Re: MINA and threads
gonzalo diethelm wrote: Although not strictly necessary, I would have the expectation that, since MINA is based on NIO, it should be possible to build a single executable that listens on a port and connects to itself on that port, all from a single thread. Is this possible at all? No. As soon as you create an Acceptor, it spawns a new thread. Then as soon as you accep an incoming connection, at least one new thread is created to process the connection. What you see in the logs is just plain normal The Main thread may ends, but as you have at least one more existing thread. -- -- cordialement, regards, Emmanuel Lécharny www.iktek.com directory.apache.org
Re: MINA and threads
gonzalo diethelm wrote: Although not strictly necessary, I would have the expectation that, since MINA is based on NIO, it should be possible to build a single executable that listens on a port and connects to itself on that port, all from a single thread. Is this possible at all? No. As soon as you create an Acceptor, it spawns a new thread. Then as soon as you accept an incoming connection, at least one new thread is created to process the connection. What you see in the logs is just plain normal The Main thread may end, but as you have at least one more existing thread. Is this common practice in the Java NIO world? Because on the C/C++ side, there are good reasons why one would avoid using threads at all and move toward a non-blocking approach, even if it is more difficult to implement. Admittedly, using threads in Java may be more of a non-brainer; I admit that I can't help but feel a little disappointed that it is not possible to do all of this in MINA on a single thread (if one so wanted). Again, maybe I am too influenced by my previous C++ experience. Implementing everything with a single thread means that we use one selector to handle the accept and the session. possible, but then, why using MINA ? You can do that with a simple SocketServer, a selector and a few glue around it. The idea with MINA was to create a scalable NIO framework, easy enough to use. Doing that on a single thread would kill the initial design... Let me ask this in another way: could I build the mentioned example (single executable that listens on a port and connects to itself on that port, all from a single thread) by programming directly to Java NIO, totally bypassing MINA? I guess so. If the answer to the above is yes, then it would seem that MINA forces the choice of a concurrency / processing model (one thread per connection). Keep in mind that there is a whole gamut of choices here, ranging from single thread, non-blocking to thread per connection, blocking at the extremes, including the thread-pool, blocking or non-blocking right in the middle. Well, it's impossible to design a system which fits all the needs. Also I don't really see the problem you are trying to fix with this 'one thread to manage everything'. You are the first person on the mailing list in 3 years to expose such a need. Do you have some technical constraints that limit you to using only one thread ? -- -- cordialement, regards, Emmanuel Lécharny www.iktek.com directory.apache.org
Re: MINA and threads
gonzalo diethelm wrote: Implementing everything with a single thread means that we use one selector to handle the accept and the session. possible, but then, why using MINA ? You can do that with a simple SocketServer, a selector and a few glue around it. The idea with MINA was to create a scalable NIO framework, easy enough to use. Doing that on a single thread would kill the initial design... ... Well, it's impossible to design a system which fits all the needs. Also I don't really see the problem you are trying to fix with this 'one thread to manage everything'. You are the first person on the mailing list in 3 years to expose such a need. Do you have some technical constraints that limit you to using only one thread ? More than a need, I am trying to grasp the design objectives for MINA. I come from a C++ experience, where sometimes you will want to choose to have everything running in one single thread, doing all the multiplexing yourself, and sometimes you will want to use threads, maybe associating one thread with one connection, or pooling your threads because their creation and destruction can be expensive. Basically, MINA was designed as a SEDA based framework (even if this target has been lost in the meantime, somehow ...). Sicne then, it has aevolved a bit. The internal design was done in otder to decouple the concerns as much as possible. So you have a thread handling incoming connections, N processor, each of them having a selector, to process the incoming and outgoing events (read and write) each processor being associated with a thread, and as you can add an Executor filter in the chain, you can also have N threads to handle the load (this construction is the only remaining SEDA flavor in the framework). All those threads are intended to offer a better scalability, but that has still to be proven :) But more than that, and many persons are questioning the scalability, it's a damn simple framework when it comes to quickly design a server, letting you to focus on what matters : the codec and the handler. At some point in the future, though, considering other aspects than ease of use, we may have to tune the design to allow one user to select the best solution. We are far from this point ... :/ I have used the C++ ACE framework in the past, and it does give the designer the choice regarding which threading model to follow. Mind you, I am NOT saying that ACE is better than MINA, or that C++ is better than Java. I WANT to use MINA; I also would like to learn the extent of my choices / constraints set by the framework, and the reasons why it provides those choices /constraints, and not others. I hope I brought a bit of light in the dark :) fell free to ask more ! -- -- cordialement, regards, Emmanuel Lécharny www.iktek.com directory.apache.org
Re: MINA and threads
Christopher Popp wrote: I think you might be confusing the thread model a bit...with MINA you don't need a thread per client. There is one thread listening which handles accepting connections. There are then a configurable pool of I/O handling threads (defaulting to # of cores +1) which handle incoming messages. Optionally, you can specify an ExecutorFilter in your filter chain if you want another pool of threads available later in case you expect this would benefit your application logic. So...at a minimum, you could configure MINA to only use two threads (one for accepting, and one for processing I/O), and have that handle any number of connected clients. I would say three : main, the IoAcceptor thread and a IoProcessor thread. Not a big difference though :) -- -- cordialement, regards, Emmanuel Lécharny www.iktek.com directory.apache.org
Re: Server and Client at the same time
gonzalo diethelm wrote: From: gonzalo diethelm [mailto:gdieth...@dcv.cl] Sent: Thursday 11 Jun 2009 10:59 To: users@mina.apache.org Subject: Server and Client at the same time Hello again. I would like to gather opinions on how to implement a proof of concept for my requirements. [snip] I must apologize for seemingly asking a repeated question. I understand now that the Proxy example is a good way to approach my requirements, and this had already been answered previously. It is just that I do not see these requirements as implementing a proxy, I see them more as implementing nodes in a grid; hence my error. The Proxy is just an example with a server processing incoming requests and pushing them to a client. What's different with your grid approach, whatever it can be ? ( so far, I don't really see where you are heading to...) Also, for full disclosure: I posted a similar question on the Netty mailing list. I know next to nothing about MINA and Netty, and am trying to compare them for my purposes. Np at all. You should also have a look at Grizzly. -- -- cordialement, regards, Emmanuel Lécharny www.iktek.com directory.apache.org
Re: Clarification on use of IOBuffer
Yasdnil Zbib wrote: Hi I am just starting to get to grips with MINA 2.0, and have a question about the use of IOBuffer, which I hope someone can help me with. Apologies up front for the newbie status of this: When a ProtocolDecoder recieves an IOBuffer to decode I have read that my incoming message may not have been fully written, and it is up to the decoder to handle this, druing the translation to my POJO. right But, if my message has been fully written - is the buffer likely tohave another message in it ? absolutely For example: say the IOBuffer is 650 bytes in length (and assume non-auto-expanding). My inbound message is 300 bytes. Once I have read the 300 bytes and converted to a POJO - will I ever see a second message in the IOBuffer, following on ? you may have another message. -- -- cordialement, regards, Emmanuel Lécharny www.iktek.com directory.apache.org
Re: ProtocolDecoderException: java.nio.charset.MalformedInputException encountered in Apache mina 1.1.7
lasith haputhanthiri wrote: Exception caught: org.apache.mina.filter.codec.ProtocolDecoderException: java.nio.charset.MalformedInputException: Input length = 1 (Hexdump: 33 1C 33 1C 30 1C 30 1C 30 1C 30 1C 41 53 30 30 30 30 30 33 32 36 39 01 42 46 47 42 01 22 30 01 48 30 01 49 41 44 53 4D 01 4A 41 45 44 01 4B 32 01 4C 31 01 4D 35 30 30 01 4E 31 34 2E 30 01 4F 30 01 52 30 01 57 58 01 67 36 01 68 34 37 31 37 01 75 6E 75 6C 6C 32 01 79 44 42 46 53 5F 54 45 53 54 01 7A 30 01 34 39 2E 30 01 32 31 39 37 30 30 31 01 36 31 2E 30 01 39 30 01 21 30 01 7C 30 2E 30 01 23 30 01 2C 30 01 A7 01 0A) ^^--- A7 is not a valid UTF-8 encoded value. See http://en.wikipedia.org/wiki/UTF-8, section Description. Check your client. -- -- cordialement, regards, Emmanuel Lécharny www.iktek.com directory.apache.org
Re: Logging filter oddity
boB Gage wrote: Emmanuel, you're right I should be annoyed at the previous designer that tied our non-volunteer project with strictly defined deadlines to a volunteer-developed library tool set; not at the volunteers who never actually committed to support anything. well, it's always the same story : even if you have selected a close source API, even if you have paid a huge amount of money for it, it could still contain bugs, and you could still be stuck. We are really trying to do our best to deliver the best quality software, and it's not easy. Julien, for instance, is using MINA with the serial layer (he coded it) for its own usage. Obviously, he is ready to pay the price for it (ie, time on his own hours), not only because he needs it, but also because he sees the immediate benefits he can get from such a piece of software : a community around it which can help if he gets stuck in some part of the code. If I can send a message to all the users : it's really easy, and rewarding, to become a committer. It's a matter of participating by providing patches. Also note that we never spread the wrong signal that MINA 2.0 was ready. It's still a milestone, and designed as unstable. Yes, I know, it takes forever to get a release out... Problem is I've got umpteen different things that have to be fixed and added at our level of the application and this is neither the first, nor even the only active issue in our code likely caused by Mina. I've hesitated to mention the other active issue, so as to not muddy the waters -- one problem at a time. :-) Well, sometime, it's better to get the whole picture :) Unfortunately, I don't think the designer who decided on Mina realized that we were taking it places it apparently has never been before... What we needed was a cross-platform answer to a serial application; the tool he chose was Mina, whose serial-side is apparently new and I'm finding not overly bug-free. Our application is being used in a health care setting so should be as bullet-proof as possible. This is what we are targetting too. A slipery path, too... I'll have to ask my bosses about patches. It's really two questions. Do they want to pay me to fix Mina library? If so, are they willing to then give away those fixes to the community at large? I'm on someone else's payroll, so I don't make those decisions. You have two options here : - you can fork MINA, if for any legal reasons you can't or don't want to share the patches, - or you can grant the patches to The ASF I understand that's not as simple as willing to contribute to the project. boB PS... Okay, so say I do have to dig and fix this myself.How would I confirm my Mina svn repository matches the M4 code I'm using before I muck around with it? Or do I have to update to the latest Mina code first? (M2 to M4 got ugly; M4 to M5 looked horrible and was quickly reversed, been waiting for the real release ever since) Let be clear : M4 sucks, M5 is even worst. M6 is way better. Trunk will be (hopefully) even better. In any case, you can pick the milestone you prefer, in the tags/ directory : it's frozen. When you would like to move to a more recent version (say, M7 when ready), it's just a matter to merge your modification into the trunk. as we aren't modifying the code a lot atm (we are just in bug fix mode), that should not be a problem. Hope it helps (a bit ;) -- -- cordialement, regards, Emmanuel Lécharny www.iktek.com directory.apache.org
Re: Logging filter oddity
Christopher Popp wrote: Yep, after taking the second glance at it, it looks like the message sent event should occur every time the write occurs later on in the method. I just took a glance quick, and it looks like they tag each of their releases, so you should be able to checkout the 2.0.0-M4 tagged version and get a suitable codebase to try from. It looks like that code hasn't changed between M4 and now: http://svn.apache.org/viewvc/mina/tags/2.0.0-M4/transport-serial/src/main/java/org/apache/mina/transport/serial/SerialSessionImpl.java?revision=724773 I urge you to use M6. M4 is using a non-thread safe Circular queue causing to some message loss when under heavy load, M5 ExecutorFilter is broken. All this has been fixed in M6, so far. In any case, serial hasen't change since M4. Christopher H, I see the code in question, but I'm not sure I can test it.I've got an old svn checkout, that I thought was M4-ish in timeframe. But when I build it it's calling itself RC2. That's a mistake we made. Just a bad tag. -- -- cordialement, regards, Emmanuel Lécharny www.iktek.com directory.apache.org
Re: JIRA
boB Gage wrote: Have entered JIRA tickets with details of the recent issues I've brought to the list. DIRMINA-719 --Serial Filter Chain Broken For Outbound Data DIRMINA-720 -- Hardware Flow Control Disables Serial Port on Windows Platform Saw that. I have added a comment on 719 I have also updated our project to use 2.0.0-M6. I have not (yet?) noticed any differences in behaviour. At least, it's not worst :) -- -- cordialement, regards, Emmanuel Lécharny www.iktek.com directory.apache.org
Re: NIO performance
David Rosenstrauch wrote: David Rosenstrauch wrote: Mark Webb wrote: This was discussed in length on this mailing list back when the article was posted. I vaguely remember the discussion, other than it happened. Checking the archives should give you what you are looking for. --Mark Ah, didn't realize. Will go RTFM. Sorry for the noise. DR Tried to search through the gmane archives (as well as my local disk archives) on both Tyma and mailinator but didn't turn up anything. Would you happen a pointer? http://www.mail-archive.com/d...@mina.apache.org/msg07525.html Dev list. -- -- cordialement, regards, Emmanuel Lécharny www.iktek.com directory.apache.org
Re: Handling variable length request/response in MINA
Chowdhury, Shubhankar [WHQKA] wrote: o o the whole format got garbled - let me try in plain text -- -- This might be a very dumb post but please help. I have already used MINA for a few projects mainly using the CumulativeProtocolDecoder and RequestResponseFilter for the client applications and using TextlineCodec for a few server instances. But my next attempt is a bit complex where the data that comes is a structured data of variable length basically of the following format- Offset-LengthInByte-FieldName -- 0-8-application_id 8-2-Version 10-2-Type 12-2-message_id_number 14-2-Data_length 16-4-Reserved 20-data_length-Data The application would be a server listening to a port (TCP) and also would return back some response based on the type field. So the client would initiate by sending a login-request - in response we have to send accept or reject, then the data would be flowing, then log-out, keep-alive etc and all of them would follow the above structure. How do I handle this using MINA? Is there anyway I can use the CumulativeProtocolDecoder? Actually, it will easy. As you know the length of your message, it's just a matter of storing what has already been received in the session, until you got all the message. The decoder must be able to stop in the middle of an int, for instance, which is not that complicated, assuming that an int is a fixed size element. You just have to check that you have 4 bytes available in the buffer to decode the int, otherwise, you just store the buffer in the session, and wait for the next bytes to come. Sounds complicated, but it's not. The real issue is if you have very long messages : in this case, you may want to stream to a file the incoming data, to avoid a OOM. When you have received everything, then you can push the resulting eleme,t to your handler (if of course you built a data structure on the fly). Hope it helps. -- -- cordialement, regards, Emmanuel Lécharny www.iktek.com directory.apache.org
Re: Handling variable length request/response in MINA
David Rosenstrauch wrote: I do something similar, using a binary protocol where messages vary in length based on data-length values in the message. And yes, I use a custom subclass of CumulativeProtocolDecoder for this. The code's a bit ugly, but it works. Essentially your decoder needs to handle 3 possible cases: * full, syntactically correct message received * part of a syntactically correct message received, and * syntactically incorrect message received I would add a forth case : * more than one complete message in a single buffer. In this case, you have to loop until you have decoded all the messages, calling the next filter for each decoded message. This is what we do in Apache Directory to decode LDAP requests. -- -- cordialement, regards, Emmanuel Lécharny www.iktek.com directory.apache.org
Re: Handling variable length request/response in MINA
Chowdhury, Shubhankar [WHQKA] wrote: Thanks Emanuel but actually I the message lengths vary in each message - that's part of the message itself. If you see the message format 14-2-Data_length - so starting at 14th byte and I will have an short value giving me the data length. This is cover but my explaination : as soon as you are able to decode the length, you know how many bytes to get to have a complete portion of your full message. The only problem is that the length, stored as four bytes (if its an int, for instance), has to be decoded itself. But at least, you know that you expect 4 bytes to decode an int. Once I receive the whole message then only I can apply the byte off-sets to extract the message body and header etc. This is not the right way to decode your message. Here, you assume you already have received the full message. Just consider that your message can arrive byte by byte, you just have to make your decoder happy with that. Once you cand deal with such a flow of separated bytes, every other cases are just simple. but with in.available() I would have to know the message length before hand isn't it? Am I missing something? yep. You are missing the fact that you can decode what you have already received. Thanks, Shubhankar 847-700-4452 -Original Message- From: Emmanuel Lecharny [mailto:elecha...@gmail.com] On Behalf Of Emmanuel Lecharny Sent: Friday, June 19, 2009 5:46 PM To: users@mina.apache.org Subject: Re: Handling variable length request/response in MINA Chowdhury, Shubhankar [WHQKA] wrote: o o the whole format got garbled - let me try in plain text -- -- This might be a very dumb post but please help. I have already used MINA for a few projects mainly using the CumulativeProtocolDecoder and RequestResponseFilter for the client applications and using TextlineCodec for a few server instances. But my next attempt is a bit complex where the data that comes is a structured data of variable length basically of the following format- Offset-LengthInByte-FieldName -- 0-8-application_id 8-2-Version 10-2-Type 12-2-message_id_number 14-2-Data_length 16-4-Reserved 20-data_length-Data The application would be a server listening to a port (TCP) and also would return back some response based on the type field. So the client would initiate by sending a login-request - in response we have to send accept or reject, then the data would be flowing, then log-out, keep-alive etc and all of them would follow the above structure. How do I handle this using MINA? Is there anyway I can use the CumulativeProtocolDecoder? Actually, it will easy. As you know the length of your message, it's just a matter of storing what has already been received in the session, until you got all the message. The decoder must be able to stop in the middle of an int, for instance, which is not that complicated, assuming that an int is a fixed size element. You just have to check that you have 4 bytes available in the buffer to decode the int, otherwise, you just store the buffer in the session, and wait for the next bytes to come. Sounds complicated, but it's not. The real issue is if you have very long messages : in this case, you may want to stream to a file the incoming data, to avoid a OOM. When you have received everything, then you can push the resulting eleme,t to your handler (if of course you built a data structure on the fly). Hope it helps. -- -- cordialement, regards, Emmanuel Lécharny www.iktek.com directory.apache.org
Re: Handling variable length request/response in MINA
David Rosenstrauch wrote: I would add a forth case : * more than one complete message in a single buffer. In this case, you have to loop until you have decoded all the messages, calling the next filter for each decoded message. This is what we do in Apache Directory to decode LDAP requests. Hmmm ... I might not actually be handling this case. I'll have to check my code. I just mentionned it because we have been hit by this problem ;) -- -- cordialement, regards, Emmanuel Lécharny www.iktek.com directory.apache.org
Re: Handling variable length request/response in MINA
David Rosenstrauch wrote: David Rosenstrauch wrote: Emmanuel Lecharny wrote: I would add a forth case : * more than one complete message in a single buffer. In this case, you have to loop until you have decoded all the messages, calling the next filter for each decoded message. This is what we do in Apache Directory to decode LDAP requests. Hmmm ... I might not actually be handling this case. I'll have to check my code. Thanks much for the heads up. DR Question: So say in my decoder I do as follows: public class BinaryProtocolDecoder extends CumulativeProtocolDecoder { protected boolean doDecode(IoSession session, IoBuffer in, ProtocolDecoderOutput out) { ... MyMessage msg = decodeOneMessage(in); return true; } } i.e., I decode one message from out of the buffer, and leave any remaining bytes that are part of the next message left unread in the buffer. Are those remaining bytes from the next message lost? And if they're not lost, will the CumulativeProtocolDecoder then immediately call my doDecode method again to try to decode that message? They won't be lost, it's just that the buffer will keep them until it receives more bytes. It has a bad side effect that you may wait forever if you receive 3 messages in two byte buffer : - the first message will be processed, and the first part of the second message will remain in the buffer - when receiving the second part of the second message plus the third message, you will process the second message, and the third will remain for ever in the buffer (until the session is killed) DR -- -- cordialement, regards, Emmanuel Lécharny www.iktek.com directory.apache.org
Re: Handling variable length request/response in MINA
Yongxing Wang wrote: If not implicitly covered in the case of more than one complete message in a single buffer, we also need to deal with the case where a sing buffer contains several complete messages AND an incomplete one. if fact, all the cases are listed here : * a buffer with an incomplet message * a buffer with a message, nothing less, nothing more * a buffer with N complete messages, nothing more * a buffer with N complete messages, and some extra bytes. -- -- cordialement, regards, Emmanuel Lécharny www.iktek.com directory.apache.org
Re: Handling variable length request/response in MINA
David Rosenstrauch wrote: DR Hmmm ... yeah, that's a problem. I'll have to fix this. Thanks for the heads up. Just keep me informed if this is not anymore a problem... May be we should document this kind of decoding on the web site too... It can e helpfull ! DR -- -- cordialement, regards, Emmanuel Lécharny www.iktek.com directory.apache.org
Re: Handling variable length request/response in MINA
Yongxing Wang wrote: I wrote a simple unit test case where one single buffer contains two messages, using the DummySession. After calling decode, it delivers me two messages: IoBuffer in = IoBuffer.wrap(bytesData); = contains two encoded msgs decoder.decode(session, in, session.getDecoderOutput()); assertEquals(2, session.getDecoderOutputQueue().size()); Also, looking at the CumulativeProtocolDecoder(which is one I am using), for (;;) { int oldPos = buf.position(); boolean decoded = doDecode(session, buf, out); if (decoded) { if (buf.position() == oldPos) { throw new IllegalStateException( doDecode() can't return true when buffer is not consumed.); } if (!buf.hasRemaining()) { break; } } else { break; } } doDecode will be called again if there are any remaining bytes in the event of successfully decoding one message If I am not terribly wrong, David, your algorithm is fine. Thanks a lot for having checked ! -- -- cordialement, regards, Emmanuel Lécharny www.iktek.com directory.apache.org
Re: Handling variable length request/response in MINA
Maarten Bosteels wrote: It's in the javadocs: doDecode() is invoked repeatedly until it returns false So there is no need to have a loop in your doDecode implementation for decoding multiple messages. http://mina.apache.org/report/trunk/apidocs/org/apache/mina/filter/codec/CumulativeProtocolDecoder.html#doDecode(org.apache.mina.core.session.IoSession,%20org.apache.mina.core.buffer.IoBuffer,%20org.apache.mina.filter.codec.ProtocolDecoderOutput) Maarten Thanks for the clarification, Maarten, my bad : we don't extend the CumulativeProtocolDecoder in Directory, thus my confusion. We *have* to loop on a buffer just because of that. -- -- cordialement, regards, Emmanuel Lécharny www.iktek.com directory.apache.org
Re: Question about mina - deadlock?
Brian Parkinson wrote: Emmanuel writes: ---x8 snip 2. I've noticed one recurring error in my log files - in my HttpRequestDecoder (extends MessageDecoderAdapter), I am throwing an exception trying to parse up the headers - the code ends up getting partial line headers (for example, the decoder attempts to parse a line Content-Ty with nothing else on the line) - it seems like the HTTP packet is not complete - should I be concerned about this? An exception is thrown, and the caller will re-send anyways, but the error is seen a fair bit throughout the logs, and I'm wondering if this might be contributing to the lock up issue (?). You have no guarantee that the messages sent by a client will be received fully. They can even been sent one byte at a time. It's up to you to gather all the incoming bytes until you have enough bytes to decode your protocol. In your case, however, you can use the TextLineDecoder which waits for a line feed to forward the decoded message to your handler. ---x8 snip I am using a custom HttpRequestDecoder (which subclasses MessageDecoderAdaptor). The 'decodable' method looks correct, but then when 'decode' gets called, the buffer is incomplete - I can't figure that out. Almost invariably, the 'decode' method fails on an incomplete header line - I see a truncated header 'Content-Ty' repeatedly in the logs. Can you post your decodable() and doDecode() methods ? -- -- cordialement, regards, Emmanuel Lécharny www.iktek.com directory.apache.org
Re: ByteBuffer problem
On Fri, Jun 26, 2009 at 10:51 AM, Anand Boraanand.b...@aricent.com wrote: Hi all, I'm facing a weird issue. I'm trying to find out the current length of the ByteBuffer which is filled with data. I tried to use the position() function but the problem is it increments the position also. What is the exact function which can give me the filled up length, if any? 1) I guess that you submitted this message 3 times by mistake... Thanks to be careful : it's not because it does not appears in the list that it has not been received. You probably use a mail system which adds a stupid DISCLAIMER which requires us to moderate it by hand, otherwise the mail might be considered as Spam. 2) *always* mention the software version you are using. ByteBuffer can be either the java ByteBuffer or the MINA 1.1.x ByteBuffer. Here, I assume you are using MINA 1.1.x. 3) When you write ...the problem is it increments the position also what *exactly* do you mean ? ByteBuffer.position() gives you the *current* position on the buffer. It does not gives you the number of elements present on the buffer. It's all explained in the Javadoc, btw, so a bit of reading could help at this point... -- Regards, Cordialement, Emmanuel Lécharny www.iktek.com
Re: NEWBIE : Writing Protocol Codecs
Linz RB wrote: Just looking for some confirmation on my thoughts (and understanding) of writing ProtocolCodecs Before I start - congratulations to the MINA team - MINA 2,0 is great and the separation of repsonsibilities is a joy to work with. I am primarily concerned with the construction of decoder codecs (as converting a POJO to an IO Buffer is straight forward). I have three protocols that I am looking at - and planning to convert to using MINA. These are DHCP, TFTP, and a bespoke protocol. So DHCP: I took a look at the codec provided for Apache DS - but was not confident that it would work. The decoder codec seems to assume that an entire DHCP message would be present in the IOBuffer. But from what I have read - you cannot make this assumption. Have I understoodd this correctly ? I suspect you are right. I have not checked the ApacheDS DHCP codec though, so I trust you on that. So I have implemented a version that uses an internal state machine (not the mina-statemachine - learning one thing at a time!) that process as much of the received DHCP message as possible in stages : for example - process the 'static' part (first 236 bytes), then the magic cookie and lastly options (variable length). Sounds the way to go. So TFTP: Again - I have read the 'static' portion of the message header - and then process the rest of the message. The rest of the message is 0 byte terminated - so I have to look at the IOBuffer - at the limit() position for a 0 - which indicates that the entire message is available and can be processed (since TFTP is a strict handshake style protocol I do no have to worry about a second message in the buffer - I think !!) Sounds ok too How am I doing so far ? Is my approach incorrect - and not what MINA gurus would recommend. Well, that's the way I would have handled those protocol. May be someone else has a better idea ? I am getting the feeling that it would be helpful to find a way to describe a protocol and then provide a codec framework that is a close fit - is this intention of MINA ? - so, codecs for synchronous (handshake) based protocols (where you can only every expect a single message per IOBuffer) v asynchronous (streaming-like) protocols (where you may find more than one message per IOBUffer). There are a few interesting approaches so far to solve this problem, and some peeps have developped some Codec generators. One of them is based on Google Protocol Buffer (thomasz blachowicz). I have also thought that we should have an ASN.1 compiler generating code for any kind of codec, but it's a very long task ... Last, not least, we discussed a bit about creating a codec library, containing the most well known protocols (as we already have a few of them, it should not be a problem) So this is still an open area, where those who want to play can join us ! -- -- cordialement, regards, Emmanuel Lécharny www.iktek.com directory.apache.org
Re: Fwd: Need Code support
Kumar Phani wrote: I want to know how to configure the ThreadPool Executor in Acceptor,exactly what I need is acceptor needs to take 'n' requests simultaneoulsy. Ok, so when you define your acceptor, you can provide a number of IoProcessor to use, depending on the number of processor you have. The Executor is a bit different beast : it's used if you have a long processing part somewhere in your chain, and want to decople this part from the processing of faster request. Not sure that you need it, it all depends on your application. Basically, the number of IoProcessor defaults to Nb CPU * 2 + 1. You can change that by using the NioSocketAcceptor( int nbProcessor ) if you want to have more processor in the pool. You have to know that a processor is associated with a Selector, so once a session has been registred within a IoProcessor, eveery message received or sent on this session will be processed by this IoProcessor. If you have some lengthly operation affecting one special message, then this IoProcessor will wait until this processing is done before processing the next incoming or outgoing event. However, all the other sessions associated with another IoProcessor will be processed in parallel. Last, not least, if you want an IoProcessor not to be stuck while processing a request, just add an executor in the chain, so a pool of thread will be used to process the messages, instead of the IoProcessor thread. In any case, before using an Executor, I would engage you to make your server working with the default configuration, because it's most likely be enough for your need. Once you have reach a point where your needs aren't met with the default config, then either increase the number of IoProcessor, or add an executor to the chain : filterChainBuilder.addLast(threadPool, *new* ExecutorFilter http://mina.apache.org/report/trunk/xref/org/apache/mina/filter/executor/ExecutorFilter.html(Executors.newCachedThreadPool())); // Here, we use an ubound thread pool. Hope it helps. On Tue, Jun 30, 2009 at 2:58 PM, Emmanuel Lecharny elecha...@apache.orgwrote: Kumar Phani wrote: Hi , Now I am using the Apache Mina Framework.But I want to enhance the Code to handle multiple requests by the Server(which is implemented in MINA for communication).Its very urgent so quick response is appreciable. Hey, you can post as many time as you want, but you won't get any help with such a vague question... -- -- cordialement, regards, Emmanuel Lécharny www.iktek.com directory.apache.org -- -- cordialement, regards, Emmanuel Lécharny www.iktek.com directory.apache.org
Re: questions about AsyncWeb Client sub project
Hi, On Wed, Jul 8, 2009 at 9:18 PM, Sitao Yangsitao.y...@gmail.com wrote: Hi, I'm interested in trying out AsyncWeb Client in my project. I have several questions: 1. where can I find either latest and stable source code or binary package for this project? The source is only available through SVN. Have a look at http://mina.apache.org/sources.html, there is some direction about how to check out syncWeb code. 2. where can I find javadoc for this project? I searched in apache site but didn't find any. You will have to generate them :/ But you'd better check the code directly ! Any help would be appreciated. Hope it helps ... -- Regards, Cordialement, Emmanuel Lécharny www.iktek.com
Re: How I use more than one codec filter with one acceptor
You can't use two codec filters in the chain, due to the way the data are passed from one filter to another one (we use IoBuffer for that). This will be modified in 3.0, but don't expect this version to be out soon. In the mean time, the only option is to wrap the textline codec into the JSON codec. Not that easy, but not that complex too. On Thu, Jul 16, 2009 at 7:04 PM, elf.chengelf.ch...@browan.com wrote: I'am using a JSON based Protcol in my server program based on mina.To deal with json string,I write codecs to decode from string or encode to string.I used this codecfactory like the following: acceptor.getFilterChain().addLast(logger, new LoggingFilter()); acceptor.getFilterChain().addLast(codec_txt, new ProtocolCodecFilter(new TextLineCodecFactory(Charset.forName(UTF-8; acceptor.getFilterChain().addLast(codec_json, new ProtocolCodecFilter(new JsonCodecFactory())); but the filter codec_json dose not work! who can tell me why? elf.cheng -- Regards, Cordialement, Emmanuel Lécharny www.iktek.com
Re: How I use more than one codec filter with one acceptor
Sorry, Ashish, after having refreshed my memory by looking at the code, just discard what I have said. MessageReceived() get an Object as a parameter, not a IoBuffer. So as soon as you *know* what type the message type is, it should be plain ok. Sorry for the confusion. -- Regards, Cordialement, Emmanuel Lécharny www.iktek.com
Re: How I use more than one codec filter with one acceptor
On Thu, Jul 16, 2009 at 11:24 AM, Emmanuel Lecharnyelecha...@apache.org wrote: You can't use two codec filters in the chain, due to the way the data are passed from one filter to another one (we use IoBuffer for that). This is plain BS, now that I had time to check on the code. MessageReceived() method manipulates an Object, not an IoBuffer. Sorry for the confusion. -- Regards, Cordialement, Emmanuel Lécharny www.iktek.com
Re: Question about SslFilter FileRegion
Adam Brown wrote: While adding SSL support to our project using SslFilter, I ran into the problem where SslFilter does not handle writes of FileRegions. SslFilter.filterWrite() casts the message in the WriteRequest to an IoBuffer. However, this doesn't work for FileRegions (leading to a ClassCastException). Has anyone else run afoul of this issue? Apart from sticking another IoFilter in the chain before the SslFilter to convert the FileRegion into an equivalent IoBuffer, is there another/better solution? Well, as the SSLFilter is the first one in the chain, it has to send byte[] to the client. Not sure that it implies it should receive an IoBuffer, as in your case it would have made sense that it was able to accept FileRegion... Sadly, it's currently a limitation. You have to add a converter, or you can extend the current SSLFilter to handle a FileRegion instead of a IoBuffer. I guess you will just have to overload the filterWrite() method, calling its super.filterWite() when the conversion is done. A bit of a hack, but ... Hope it helps. -- -- cordialement, regards, Emmanuel Lécharny www.iktek.com directory.apache.org
Re: mina client side question
刘尚�� wrote: 哈哈.原来有chinese 在上面 can you please full english when posting to this mailing list? Thanks ! -- -- cordialement, regards, Emmanuel Lécharny www.iktek.com directory.apache.org
ApacheCON US 2009 Travel Assistance
The Travel Assistance Committee is taking in applications for those wanting to attend ApacheCon US 2009 (Oakland) which takes place between the 2nd and 6th November 2009. The Travel Assistance Committee is looking for people who would like to be able to attend ApacheCon US 2009 who may need some financial support in order to get there. There are limited places available, and all applications will be scored on their individual merit. Applications are open to all open source developers who feel that their attendance would benefit themselves, their project(s), the ASF and open source in general. Financial assistance is available for flights, accommodation, subsistence and Conference fees either in full or in part, depending on circumstances. It is intended that all our ApacheCon events are covered, so it may be prudent for those in Europe and/or Asia to wait until an event closer to them comes up - you are all welcome to apply for ApacheCon US of course, but there should be compelling reasons for you to attend an event further away that your home location for your application to be considered above those closer to the event location. More information can be found on the main Apache website at http://www.apache.org/travel/index.html - where you will also find a link to the online application and details for submitting. Applications for applying for travel assistance will open on 27th July 2009 and close of the 17th August 2009. Good luck to all those that will apply. Regards, The Travel Assistance Committee -- -- cordialement, regards, Emmanuel Lécharny www.iktek.com directory.apache.org
Re: Message processing issue with MINA
Bruno, I want to give you some result we get on Apache Directory Server, which is based on MINA. Currenly on my laptop, a 2Ghz centrino, I'm able to process around 4000 search requests per second. That mean a request is handled in *less than a 1/4 millisecond*. And trust me on that, the processing is quite complex. Whatever you do with currentMillis on the message level is irrelevant. Measuring the execution time for a single message will at best gives you a consistent duration only when the message is stuck for more than a few tens of ms. Otherwise, you will get a random value between 0 and 20 ms, depending on your platform. There is of course no guarantee that every message will be processed in less than 200 ms, this is Java... It's just that statistically, it will be the case for 99,999% of the messages. So the best you can do to measure the time it takes to process a single message is to do what you are doing, but only gather times when a message is processed in more than, say, 50 ms. Otherwise, simply consider that the message has been processed 'fast enough'. When you'll get the number of messages processed in more than 50 ms, you will also see if this is acceptable from your PoV. last thing, as Joshua Bloch says in his book Effective Java : ...Finally, note that System.nanoTime is used to time the activity rather than System.currentTimeMillis. For interval timing, always use System.nanoTime in preference to System.currentTime-Millis. System.nanoTime is both more accurate and more precise, and it is not affected by adjustments to the system’s real-time clock (Item 69, page 276) Bruno de Carvalho wrote: Meanwhile, I've updated the code and implemented another flag, SEQUENTIAL. With this flag, packet N+1 will only be sent to the server after packet N has been received. With this flag enabled you will better grasp what I'm experiencing - sequential mode has equal global and per-packet averages, while on non-sequential mode this doesn't happen. The update file is at http://bruno.factor45.org/LifetimeIssues.java I'll try to dig into MINA's code and see what I can come up with. Best regards, Bruno On Fri, Jul 24, 2009 at 3:18 PM, Christopher Poppchristopherp...@yahoo.com wrote: Hello, Speaking in numbers, executing the test multiple times, I get a constant global average of ~1ms lifetime, but individual lifetime measurement averages ranges 40~80ms. I downloaded your code and gave it a run...it printed out the following with the defaults (no sleep). [SERVER] Binding Server to localhost/127.0.0.1:20002 TCP [SERVER] Bound to localhost/127.0.0.1:20002 [SERVER] Session created: /127.0.0.1:2598 [CLIENT] Session created: localhost/127.0.0.1:20002 [CLIENT] Session opened: localhost/127.0.0.1:20002 [CLIENT] Connected to server, sending message. [SERVER] Session opened: /127.0.0.1:2598 [SERVER] Test completed, took 63ms to receive 100 packets (63ms after sleep discounts). [SERVER] Calculated average lifetime was 00.63ms. [SERVER] Individual average lifetime was 3.03ms. [CLIENT] Session closed: localhost/127.0.0.1:20002 [SERVER] Session closed: /127.0.0.1:2598 [SERVER] Received a total of 5300b Maybe I am missing something, but it seems pretty reasonable to me. I ran it under Windows XP on a laptop with a dual core processor. Chris -- -- cordialement, regards, Emmanuel Lécharny www.iktek.com directory.apache.org
Re: reconnect the server?
阳建军 wrote: Hi, I wirte a Long connection client, it's sample code as: public void startClient() throws Exception { NioSocketConnector socketConnector = new NioSocketConnector(); socketConnector.setHandler(...); . ConnectFuture future = socketConnector.connect(new InetSocketAddress(ip , port)); future.awaitUninterruptibly(); } I implement IoHandler interface, in sessionClosed method, I try to reconnect the server side, it works, but still print reconnect characters, Looking at your code, this is expected... It's not because the session as been connected that the sessionClosed() method will not execute the rest of its code... -- -- cordialement, regards, Emmanuel Lécharny www.iktek.com directory.apache.org
Re: problem with FileRegionWriteFilter
Adam Brown wrote: i'm currently using a FileRegionWriteFilter 'before' an SslFilter to breakup FileRegion objects into chunks that SslFilter can handle (since SslFilter doesn't handle them directly). however, this filter chain also has IoBuffers written to the same IoSession. the problem i'm seeing appears to be that the IoBuffer is not being sent by MINA (with messageSent() being sent back up the chain and IoHandler) before the first IoBuffer generated by the FileRegionWriteFilter is written. because of this ordering, my IoBuffer (not the ones created by FileRegionWriteFilter) is lost to the chain and never has messageSent() called on it. in addition to the messageSent() call made with the FileRegion, some of the IoBuffers generated by FileRegionWriteFilter escape and have messageSent() called on them, passing them up the filter chain (and ultimately to my IoHandler). so really, i've got two problems :-). Are you using an ExecutorFilter? If so, which kind of threadPool are you using ? Can you push a very simple piece of code demonstrating the problem so that we can debu it and understand what's going on ? Thanks ! PS: MINA version, etc... That helps ! -- -- cordialement, regards, Emmanuel Lécharny www.iktek.com directory.apache.org
Re: Understanding DemuxingProtocolCodec
Daryl Ayres wrote: boB, Based on what you've said, it sounds like I would need to have a ThrowawayDecoder as the last decoder in my ProtocolCodecFactory to consume or clear those packets in the protocol I'm not currently handling. I'll create one and give it a go. This would be the approach I would implement. Basically, decoding all the messages, and throwing away those I don't want to pass to the handler. -- -- cordialement, regards, Emmanuel Lécharny www.iktek.com directory.apache.org
Re: how implement MulticastSocket Server over Mina ?
Survivant 00 wrote: Anybody can give me a hint ? It's something we have in the pipe for MINA 3.0, but it's not available in MINA 2.0 atm. I have 3 cases that I want to replace by MINA. #1 - Send a UDP message using MulticastSocket and close the socket. #2 - Send a UDP message using DatagramSocket but wait for a response (wait until TTL) #3 - Listen for UDP message using MulticastSocket (while(true)) -- -- cordialement, regards, Emmanuel Lécharny www.iktek.com directory.apache.org
Re: Decoding embedded packets
boB Gage wrote: I'm running into an issue decoding both packets from a device that embeds commands inside it's responses. Everything is flagged with start/stop bytes and can be parsed without problems. The problem is, at the point in the code that I'm parsing this, I'm in the guts of a specific packet-type Decoder object. This particular object cannot decode the embedded packet (it's a different type) so I need to push the embedded packet data back into Mina's framework in such a way that it's treated as new incoming data and runs through the standard decodable() sequences to find the right decoder object. It would be a bit overkilling ... If I understand correctly, you get a message like : startopaque dataend with opaqueObject = some decodable data, using another decoder We have that in ADS, and we handle this differently. Basically, this is a two level decoder, encapsulated in the protocolDecoder we have implemented. If you consider that the decoder is *not* a part of MINA (it's just called through a callback by MINA), you can do whatever you want once you have read your opaque data, including calling another decoder from your decoder. That would probably be the easier way to deal with such messages. -- -- cordialement, regards, Emmanuel Lécharny www.iktek.com directory.apache.org
Re: Why there is no explicit SessionEvent class in MINA?
Christian Migowski wrote: On Mon, Aug 24, 2009 at 8:23 AM, Emmanuel Lecharnyelecha...@apache.org wrote: Christian Migowski wrote: (and more actively developed). FUD. you are easily scared, hm? ;) Look, I'm very happy that Trustin has found a place he can have fun in. What he has done in the past, and what he is doing now is just a proof he is a talented coder. So I'm very happy that Netty 3 is successful, and so with Grizzly. Everyone has its own little place in this ecosystem. Now, I don't see any value added in spreading FUD. This is just childish. -- -- cordialement, regards, Emmanuel Lécharny www.iktek.com directory.apache.org
Re: StateMachine deadlock on StateContext synchronization
Rafael Marins wrote: Hi folks, Hi ! I've found a deadlock at StateMachine#handle(StateMachine.java:129) and StateMachineProxyBuilder$MethodInvocationHandler.invoke(StateMachineProxyBuilder.java:253), when using two layered state machines in pipeline. It get into deadlock because both methods seems to be called concurrently. Can you fill a JIRA with the thread dump attached so that we don't forget about this issue ? Many thanks ! -- -- cordialement, regards, Emmanuel Lécharny www.iktek.com directory.apache.org
Re: Examples of IoEventQueueThrottle use?
Daniel John Debrunner wrote: I'm seeing hangs when I use an IoEventQueueThrottle as below. I read the comments in the javadoc about requiring an executor in the filter chain. I get no hangs if I do not add writeThrottle into the chain (my app is currently throttling by waiting for every 100th write to complete). // Setup NioSocketConnector connector = new NioSocketConnector(); connector.getFilterChain().addFirst(executor, new ExecutorFilter(1)); connector.getFilterChain().addLast(writeThrottle, new WriteRequestFilter(new IoEventQueueThrottle(10))); // message sennding IoBuffer buf = prepareBuffer(); WriteFuture wf = session.write(buf); Are there any examples of how to use IoEventQueueThrottle for write throttling? The problem is that you probably have a slow client. Even if you use a throttling mechanism, you will block one thread until all the write is done. By using an executor, the writes are put into a queue, and the thread is freed, and able to accept another client interaction. Now, if you have many slow clients, at some point, the executor will become a bottleneck. Also you can quickly saturate the memory if you are writing huge messages to slow clients, as they will remain in the queue for a long time. A way to manage this is to split the message in small chunks (say, 1kb), and wait until the selector is ready for the next submission. Alas, you don't have a hand on the selector, but you can manage the MessageSent event. So if your application, you split your message in small parts, manage the MessageSent event, deal with the overhead, add an executor, you can handle any kind of scenario, including a DOS by slow reader (you will just have to set a timeout or manage idleconnection) That would be good for sure to have such a mechanism implemented in MINA... This is not exactly what does the IoEventQueueThrottler : it does limit the size of data sent to the client to a certain size, limiting the throughput. Probably not what you want. Hope it helps Thanks, Dan. -- -- cordialement, regards, Emmanuel Lécharny www.iktek.com directory.apache.org
Re: Examples of IoEventQueueThrottle use?
Daniel John Debrunner wrote: Emmanuel Lecharny wrote: Daniel John Debrunner wrote: I'm seeing hangs when I use an IoEventQueueThrottle as below. I read the comments in the javadoc about requiring an executor in the filter chain. I get no hangs if I do not add writeThrottle into the chain (my app is currently throttling by waiting for every 100th write to complete). // Setup NioSocketConnector connector = new NioSocketConnector(); connector.getFilterChain().addFirst(executor, new ExecutorFilter(1)); connector.getFilterChain().addLast(writeThrottle, new WriteRequestFilter(new IoEventQueueThrottle(10))); // message sennding IoBuffer buf = prepareBuffer(); WriteFuture wf = session.write(buf); Are there any examples of how to use IoEventQueueThrottle for write throttling? The problem is that you probably have a slow client. Even if you use a throttling mechanism, you will block one thread until all the write is done. I don't think so. Without the writeThrottle in the filter chain I see 8000-2/sec messages sent from the above code to a mina server (2.0 M6). Hmmm. So wrong assumption from my side : you don't have a slow client. Adding the writeThrottle leads to a hang, no messages seen by the client. That would be good for sure to have such a mechanism implemented in MINA... This is not exactly what does the IoEventQueueThrottler : it does limit the size of data sent to the client to a certain size, limiting the throughput. Probably not what you want. So the threshold parameter to IoEventQueueThrottler constructor is number of bytes, not number of messages? Number of bytes. Here is the portion of code which does that : public void offered(Object source, IoEvent event) { int eventSize = estimateSize(event); int currentCounter = counter.addAndGet(eventSize); logState(); if (currentCounter = threshold) { block(); } } FYI, the counter is *never* decreased. To be frank, this is not a piece of code I know, but from what I see, it's *extremly* dubious that id does something useful, and most likely to block forever. I would suggest not to use this, and to fill a JIRA reporting the problem. Sorry for that... -- -- cordialement, regards, Emmanuel Lécharny www.iktek.com directory.apache.org
Re: help !! Socket operation on nonsocket
rzo wrote: Hello, Looking further into this issue, I found out that the server has 2 network cards with teaming - load balancing - turned on. Could this lead be the cause ? Is this a windows, java or windows issue ? MINA version ? JVM version ? OS ? Code ? Thanks ... -- -- cordialement, regards, Emmanuel Lécharny www.iktek.com directory.apache.org
Re: backend permanent connection
Aleksandar Lazic wrote: The easiest way to do that is to have a class in your application that extends the IoHandler interface : it will handle the messageReceived event. I have a used the IoHandlerAdapter isn't it enough? It's ok, as this Adapter implements IoHandler. I use the IoHandler, I yust want to reuse the connection which I have created at server startup time. Which connection ? The connection to your backend (whatever it is, but let's assume it's a JDBC connection, even if it's not) ? If so, as soon as the messageReceived() method can have access to this connection, then you are all set. -- -- cordialement, regards, Emmanuel Lécharny www.iktek.com directory.apache.org
Re: IoSession.getCreationTime() in milliseconds instead of nanoseconds
Adam Brown wrote: Unless I'm missing something, despite what the Javadoc for 2.0-M6 says, AbstractIoSession.getCreationTime() returns the creation time in milliseconds, not nanoseconds. Is the plan to switch from millis to nanos, or is the Javadoc wrong? -adam The javadoc was incorrect. It is fixed now, thanks to your report. -- -- cordialement, regards, Emmanuel Lécharny www.iktek.com directory.apache.org
Re: IoSession.getCreationTime() in milliseconds instead of nanoseconds
Adam Brown wrote: Unless I'm missing something, despite what the Javadoc for 2.0-M6 says, AbstractIoSession.getCreationTime() returns the creation time in milliseconds, not nanoseconds. Is the plan to switch from millis to nanos, or is the Javadoc wrong? -adam Th eJavadoc is wrong. It's fixed now. We can't provide nanoseconds in Java, at least it's not reliable. -- -- cordialement, regards, Emmanuel Lécharny www.iktek.com directory.apache.org
Re: help !! Socket operation on nonsocket
rzo wrote: oops sorry, and sorry for the delayed answer. I am using mina-2.0.0-M4 Switch to 2.0.0-M6. The message you get is probably due to the fact that the client has closed the socket before it has been accepted. Not exactly an error. -- -- cordialement, regards, Emmanuel Lécharny www.iktek.com directory.apache.org
Re: Newbie
Chenna Venkatasubbaiah-KRG637 wrote: Hello All - Recently while browsing I came to know about MINA. I am a Java/J2EE developer. I am working in wireless broad band and networking company and I have limited knowledge on networking domain. In our company we manufacture Wireles switches, Routers and Access Ports etc., And its softwares. I would like to know How MINA will be useful and what kind of business applications we can build using MINA. I have no idea. Do you have something more precise in mind ? Your question is pretty vague at this point. A bit like I have discovered Java, and I want to know what kind of business applications I can build using this language... In any case, reading http://mina.apache.org/testimonials.html could give you a clue about what people are using MINA for. -- -- cordialement, regards, Emmanuel Lécharny www.iktek.com directory.apache.org
Re: Mina concurrency issue in servicemix camel routing
Hi, you should really see MINA as a framework on top of NIA, ie what yu do with a single socket, you have to do the same with a MINA connection. The big difference is that a MINA session is associated with some context, but otherwise, it behaves the same. The message you got just indicates that the underlying socket has been closed by the server. You have to deal with this, either by re-openning the connection, or by understanding why the server has closed the connection (I don't now if the protocol close a connection for some reason like a bad message has been sent, but if this is the case, you have to check your codec). One thing is sure is that once the session has been terminated, you have to create a new one. At some point, analysing the bytes sent on the wire could help (wireshark to the rescue !) to check that you are sending a correct message. Btw, please when you post a message, tell us which MINA version you are using, with the java and OS version. It can help ! On Mon, Sep 14, 2009 at 8:40 AM, Alex, Hitha hitha.a...@sabre-holdings.com wrote: I am getting errors when trying to send more than one message to a legacy tcp/ip service using a Apache camel mina endpoint in camel 1.6. Everything works as expected when requests are send one at a time I am not sure, if the issue is due to remote host forcibly closing connection. My simple java socket client works fine by sending multiple concurrent transactions to the same legacy server. I have a feeling it is something in my mina configuration or codec setting. Does mina reuse connections for multiple messages? The legacy system is expecting separate connections per request. I am using an extension of CumulativeProtocolDecoder. Do I need to do something in dispose() method to forcibly close the connection or session? Any clues will be appreciated. Following is the error I am getting. Caused by: java.io.IOException: An existing connection was forcibly closed by the remote host at sun.nio.ch.SocketDispatcher.read0(Native Method) at sun.nio.ch.SocketDispatcher.read(SocketDispatcher.java:25) at sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:233) at sun.nio.ch.IOUtil.read(IOUtil.java:200) at sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:236) at org.apache.mina.transport.socket.nio.SocketIoProcessor.read(SocketIoProc essor.java:218) at org.apache.mina.transport.socket.nio.SocketIoProcessor.process(SocketIoP rocessor.java:198) Thanks, Hitha 682-605-1897 -- Regards, Cordialement, Emmanuel Lécharny www.iktek.com
Re: Question on Message writing
In any case, I would gather all the elements inorder to send only one message instead of many. It's more efficient. On Mon, Sep 14, 2009 at 7:28 AM, Christopher Popp christopherp...@yahoo.com wrote: 2)Does Mina keeps the order of the messages sending when replies are dispatched? In another words: if I do multiple IoSession.write(), do I receive the messageSent() in the same order I do the write ? I am really not sure on this, but I think it will, unless you have a Executor down in the Chain. Anyone? For each session, the order of messages being received should be the same as they are sent. The default behavior of the ExecutorFilter is to provide an OrderedThreadPoolExecutor, which will continue to maintain the order of events per session. Setting up the ExecutorFilter with an UnorderedThreadPoolExecutor would result in things possibly getting out of order. Chris Popp -- Regards, Cordialement, Emmanuel Lécharny www.iktek.com
Re: MINA User Guide - Chapter 2 ready for review
Ashish wrote: Folks, MINA User guide Chapter 2 - Basics is ready for review. Here is the link (http://cwiki.apache.org/confluence/display/MINA/Chapter+2+-+Basics) P.S. - I missed announcing chapter 1 updates in User ML I updated it in a little hurry, as I wanted to finish it before weekend. Would be great, if you can provide feedback, on the ways to improve it. Alternatively, would be great if you can drop your wishlist for documentation. What should be the next topic in User Guide - Filter's/Connectors? Any suggestions? Hi Ashish, I have added a comment on the first wiki page. I will review the other one asap. Thanks for the great job ! -- -- cordialement, regards, Emmanuel Lécharny www.iktek.com directory.apache.org
Re: Performance Boosting: Multiple Sessions or Multiple Ports or ... Both?
Sebastian Wagner wrote: I read in the docs that: 1 session == 1 Thread 1 *active* session ... ! You may have thousands of inactive sessions. So opening several Session in the Client should have an impact on the Performance. No, not unless you have many active sessions. -- -- cordialement, regards, Emmanuel Lécharny www.iktek.com directory.apache.org
Re: SSLFilter before ExecutorFileter?
Adi wrote: Hi all, Openfire ( a open source xmpp server) uses mina. They seem to be using version 1.1.8 of mina. In the code i did see this, comment. / /TODO Temporary workaround (placing SSLFilter before ExecutorFilter) to avoid deadlock. Waiting for // MINA devs feedback ioSession.getFilterChain().addBefore(org.apache.mina.common.ExecutorThreadModel, tls, filter); Can setting up the ssl filter before ExecutorThreadModel filter cause any problems? Or is it ok to leave this as is. Any insight is appreciated. The SSL filter has to be put at first position in the chain, as the handshake has to occur first. In fact, for MINA 3.0, we most certainly would remove the SSL layer from the filter chain, as it's not exactly a part of the data processing, but much more a negociation about the transport to use (should it be secure or not). Right now, for MINA 1.x and MINA 2.0, be sure to put it on the first place in the chain. -- -- cordialement, regards, Emmanuel Lécharny www.iktek.com directory.apache.org
Re: Null Character in Received Message/String
Sica, David (David) wrote: I have a process that is sending an ASCII string that contains a Null Character in the middle of the string. It seems that my MINA server is only receiving the string before the Null Character and then ignoring everything after. Does this seem consistent with how MINA should be handling it and if so how do I change it to be able to receive the entire string including text after the null character? You should check your decoder. MINA does not care about \0 bytes, they are just plain normal bytes to it. PS : Please when you post on this list, provide the MINA version you are using. -- -- cordialement, regards, Emmanuel Lécharny www.iktek.com directory.apache.org
Re: Understanding MINA 1.1.7. configuration
Hi, Darryl Pentz wrote: I'm trying to get my head around the way that MINA 1.1.7. configuration is meant to work. First, I think that you should switch to MINA 2.0.0-M6. The Thread model is much easier. Also consider that this version is mainained, and performances are better. That being said ... The current implementation I'm using is basically the default implementation. No arg SocketAcceptor() constructor, with no ExecutorFilter in the filter chain. This leads to the AnonymousIoService thread pool that I observe in the thread dumps. However if I look at this: http://mina.apache.org/configuring-thread-model.html it appears I am not using the correct strategy, and the suggestion is to disable the default threading model and instead specify separate Executor thread pools. If I understand it correctly, there appears to be 1 IoAcceptor thread, N IoProcessor threads (N being the number you specify, suggested to be #CPU's + 1) and then an executor threadpool to do the 'work'. What I'm struggling to understand is why the IoAcceptor requires a threadpool in addition to the ExecutorFilter threadpool. What is the IoAcceptor threadpool used for? If there's only 1 IoAcceptor threads, and (in my case) 3 IoProcessor threads, then what is the threadpool used for? Furthermore, what is the consequence of this approach using an ExecutorFilter over the current default approach I'm using. As we associate a session with an IoProcessor, when a message is processed by this IoProcessor, no other session can be processed by this IoProcessor. If the handler takes a while to process the event, then it will block potentially many other messages. Having an exectutor in the chain, you will allow more than one message to be processed by a single IoProcessor (what happens is that the message is dispateched to the Executor, and enqueued. This queue is handled by the ThreadPoolExecutor, but at the same time, the IoProcessor is able to process more messages). The executorFilter needs to know about the ThreadPool model you will use, and this is the information you provide. If you don't tell what kind of ThreadPool model to use, it will use an UnorderedThreadPool by default. There is no threadPool in the IoAcceptor btw. Hope it helps... -- -- cordialement, regards, Emmanuel Lécharny www.iktek.com directory.apache.org
Re: Socket sendBufferSize and receiveBufferSize
Ronen wrote: Thanks. By disabling naggle algorithm you mean setting the TCP_NODELAY? yep. On Wed, Sep 30, 2009 at 12:05 PM, Emmanuel Lecharny elecha...@apache.orgwrote: Ronen wrote: Hi, I'm trying to figure out what is the guideline for setting the values of sendBufferSize and receiveBuffersize on sockets. Is making them large as possible always the best practice? How does buffer size effect performance in general and in cases where clients have low bandwidth? Is there any benchmark somewhere? There is no simple response. It all depends on the size of you data. If they are small, the best is probably to have 1kb buffersize, as in any case, the size of your TCP (assuming you are using TCP) packets will be bounded to a bit less than 1500 bytes (depending on the MTU size). If you are using large messages, then you might want to use larger buffers. The idea is to limit the number of processing in the chain (with small buffers used fo long message, you will walk the chain once per buffer, probably not a good idea) Remember to disabled the naggle algorithm for small messages too, otherwise you might have horrible performance. Thanks, Ronen -- -- cordialement, regards, Emmanuel Lécharny www.iktek.com directory.apache.org -- -- cordialement, regards, Emmanuel Lécharny www.iktek.com directory.apache.org
Re: Push message from server to client with mina
A naive approach would be to do something like : while (true) { session.write ( your data to the client ); Thread.sleep( 1000L ); } it does the trick *IF* you don't have a lot of clients (and you'll have to add an Executor filter in the chain, otherwise you wo'nt be able to deal with more than the number of threads you have defined in the acceptor). However, this is not the best solution. The problem is that in order to process a request, a thread is selected, and released when you quit the handler (ie, once the message has been processed on the server side). A better solution would be, as suggested by mark, to have a separate thread having a list of all your client's IoSession. When the clock tiks, you get all the active sessions and you simply write a message into them : while ( true ) { for ( IoSession session : MySessions ) { if ( session.isConnected() ! session.isWriteSuspended()) { session.write( time to wake up ! ); } else { // some cleanup here, as the session has been closed. } } Thread.sleep( 1000L ); } Hope it helps too. Mark Wallsgrove wrote: Hey.. I haven't been using Mina for long, but what you could do is create a new object that runs on a thread that uses the filter chain to fire a event every x seconds. Your handler should then do the rest. Once the event has been fired the thread should then go back to sleep. I guess you could use the connection object to gather the sessions / filter chains? Hope this helps.. Best regards, Mark Wallsgrove On 10/3/09, CoolHedin coolhe...@yandex.ru wrote: Hi. I develop an application using your excellent library. But I had a difficulty. I need to send messages from server to clients, by timer. and I do not understand how to do it. for example, i send every 1 minutes 'Hi everyone' message to all conection -- Sincerely yours, Sergey Paramonov Adept Team, www.adept-project.com -- -- cordialement, regards, Emmanuel Lécharny www.iktek.com directory.apache.org
Re: Creating an SSL Client
Mark Wallsgrove wrote: Hey guys, I need to create a client which can read data of an HTTPS connection .. I have seen examples for SSL servers, but not clients. Could someone provide me with a really basic example? Surely it isn't too hard? Have a look at the chat client. http://mina.apache.org/report/trunk/xref/org/apache/mina/example/chat/Main.html -- -- cordialement, regards, Emmanuel Lécharny www.iktek.com directory.apache.org
Re: Which version of MINA to use?
I looked at the Apache cons slides and it seems that MINA exactly matches my requirements. I'm a bit unsure about the version to use. Since I start now version 2 might be ready when I need to freeze my code. How stable is the TCP client and server part of MINA 2? Version 2 is probably the one to use. We still have some bug pending, but not any that could block you except if you are using mina in some very special ways. We should be able to cut a release in october, I think... -- -- cordialement, regards, Emmanuel Lécharny www.iktek.com directory.apache.org
Re: 1.1.7 based client creates too many threads ...
Hi, instead of creating anew connector for each new connection, just connect using the same connector to the newly created InetSocketAddress. Alex Shneyderman wrote: Hi, all! I am trying to run load simulation agent, which will have to open up as many connections as it possibly can - I am trying to determine wht the upper limit will be on my laptop. I connect as follows: SocketConnectorConfig config = new SocketConnectorConfig(); config.getSessionConfig().setReuseAddress( true ); SocketConnector connector = new SocketConnector(); connector.getFilterChain().addLast( codecs, new ProtocolCodecFilter( new CAGProtocolCodecFactory() ) ); SocketAddress address = new InetSocketAddress( cagInfo.serverControlIp(), Integer.parseInt( cagInfo.serverControlPort() ) ); ConnectFuture future = connector.connect( address, new CAGIoHandler( this, csChannelEventListener ), config ); future.join(); I observe that for every connection I make MINA creates 3 threads. so, there is clearly a problem since even if I am able to open as many connections as I would want I am currently having problem with threads. I thought one of the ideas behind MINA project is an efficient handling of threads but my thread dump tells me: 795 [main] DEBUG CAGRunner - Thread[PooledByteBufferExpirer-0; true; true] 795 [main] DEBUG CAGRunner - Thread[SocketConnector-0; false; true] 795 [main] DEBUG CAGRunner - Thread[SocketConnectorIoProcessor-0.0; false; true] 795 [main] DEBUG CAGRunner - Thread[AnonymousIoService-1; true; true] 795 [main] DEBUG CAGRunner - Thread[SocketConnector-1; false; true] 795 [main] DEBUG CAGRunner - Thread[SocketConnectorIoProcessor-1.0; false; true] 795 [main] DEBUG CAGRunner - Thread[AnonymousIoService-2; true; true] 796 [main] DEBUG CAGRunner - Thread[SocketConnector-2; false; true] 796 [main] DEBUG CAGRunner - Thread[SocketConnectorIoProcessor-2.0; false; true] 796 [main] DEBUG CAGRunner - Thread[AnonymousIoService-3; true; true] 796 [main] DEBUG CAGRunner - Thread[SocketConnector-3; false; true] 796 [main] DEBUG CAGRunner - Thread[SocketConnectorIoProcessor-3.0; false; true] 796 [main] DEBUG CAGRunner - Thread[AnonymousIoService-4; true; true] 796 [main] DEBUG CAGRunner - Thread[SocketConnector-4; false; true] 796 [main] DEBUG CAGRunner - Thread[SocketConnectorIoProcessor-4.0; false; true] 796 [main] DEBUG CAGRunner - Thread[AnonymousIoService-5; true; true] 796 [main] DEBUG CAGRunner - Thread[SocketConnector-5; false; true] 796 [main] DEBUG CAGRunner - Thread[SocketConnectorIoProcessor-5.0; false; true] 796 [main] DEBUG CAGRunner - Thread[AnonymousIoService-6; true; true] 796 [main] DEBUG CAGRunner - Thread[SocketConnector-6; false; true] 796 [main] DEBUG CAGRunner - Thread[SocketConnectorIoProcessor-6.0; false; true] 796 [main] DEBUG CAGRunner - Thread[AnonymousIoService-7; true; true] 796 [main] DEBUG CAGRunner - Thread[SocketConnector-7; false; true] 796 [main] DEBUG CAGRunner - Thread[SocketConnectorIoProcessor-7.0; false; true] 796 [main] DEBUG CAGRunner - Thread[AnonymousIoService-8; true; true] 796 [main] DEBUG CAGRunner - Thread[SocketConnector-8; false; true] 796 [main] DEBUG CAGRunner - Thread[SocketConnectorIoProcessor-8.0; false; true] 797 [main] DEBUG CAGRunner - Thread[AnonymousIoService-9; true; true] 797 [main] DEBUG CAGRunner - Thread[SocketConnector-9; false; true] 797 [main] DEBUG CAGRunner - Thread[SocketConnectorIoProcessor-9.0; false; true] 797 [main] DEBUG CAGRunner - Thread[AnonymousIoService-10; true; true] 3 threads per connection. I tried 20 connections as well and the thread number went to 60. Is it possible to control the number of threads on the client side ? Thanks, Alex. -- -- cordialement, regards, Emmanuel Lécharny www.iktek.com directory.apache.org
Re: Mina and SSL
GERARD Vincent AWL-IT wrote: Hi all, Using Mina 1.1.7, I was busy testing the EchoServer example. I just wonder why do you extends ServerSocketFactory and SocketFactory ?? Is it necessary when you use SocketAcceptor or SocketConnector ? Are they called in the example (and where?). Related to this, I have find the Jira http://issues.apache.org/jira/browse/DIRMINA-650 . What is its status ? do you have more information about it ? Hi, to be frank, I'm not sure we will spend some time fixing 1.1.7 if there is a bug in it. We are just voting 2.0.0-RC1, expecting 2.0 to be out pretty soon after. Then 1.0 and 1.1 branches will be considered dead wood. It's just a question of time we can spend on the current code, and it's little for many of us... Anyway, have you tried 2.0.0-M6 ? It's most certainly way more stable than 1.1.7, more efficient, and probably has a better doco. Thanks ! Thanks Atos Worldline SA/NV - Chaussee de Haecht 1442 Haachtsesteenweg - 1130 Brussels - Belgium RPM-RPR Bruxelles-Brussel - TVA-BTW BE 0418.547.872 Bankrekening-Compte Bancaire-Bank Account 310-0269424-44 BIC BBRUBEBB - IBAN BE55 3100 2694 2444 The information contained in this e-mail and any attachment thereto is confidential and may contain information which is protected by intellectual property rights. This information is intended for the exclusive use of the recipient(s) named above. This e-mail does not constitute any binding relationship or offer toward any of the addressees. If you are not one of the addressees , one of their employees or a proxy holder entitled to hand over this message to the addressee(s), any use of the information contained herein (e.g. reproduction, divulgation, communication or distribution,...) is prohibited. If you have received this message in error, please notify the sender and destroy it immediately after. The integrity and security of this message cannot be guaranteed and it may be subject to data corruption, interception and unauthorized amendment, for which we accept no liability. -- -- cordialement, regards, Emmanuel Lécharny www.iktek.com directory.apache.org
Re: Unable to reset the writeIdeal time
binayakumar.pa...@wipro.com wrote: Hi, I am using Apache mina-core-2.0.0-M1. and Java 6 . I am unable to reset the write Ideal Time. .. The client is set by writeIdealTime(30) but when ever I received any message from server I have to reset the writeIdealtime. Thanks in advance for any support. Uh ??? What is writeIdealtime ? Can you please upgrade to 2.0.0-M6 at least ? -- -- cordialement, regards, Emmanuel Lécharny www.iktek.com directory.apache.org
Re: Configuring MINA 1.1.7 Acceptor - best practise
Darryl Pentz wrote: Hi all, Apologies for bumping this one - I was sure somebody would be able to respond to this. We're seeing some really poor performance on some of our higher load servers, but the problem is that to run profilers on them when they're under load is just not feasible. So I'd like to know whether if ~800 concurrent connections were pinging, would the below configuration be limited to the pool of 16 AnonymousIoService objects and would this result in pegging the CPU really high? Should I be switching to the manual threading model as per my second post on this thread? Very difficult to say. You have to understand that it all depends on the way you process messages in the codec and in the handler. MINA does not eat a lot of CPU itself. The number of thread you need to setup is impossible to define without any knowledge about your code. For instance, if you access a database in the handler, it's pretty obvious that the thread might be stuck for a few ms, and with 800 concurrent requests running, you will get awfull performances. At this point, it's all about decoupling the code run in handler from the MINA stack, using Executors. -- -- cordialement, regards, Emmanuel Lécharny www.iktek.com directory.apache.org
Re: Configuring MINA 1.1.7 Acceptor - best practise
Darryl Pentz wrote: Hi Emmanuel, Thanks very much for your reply. The number of thread you need to setup is impossible to define without any knowledge about your code. For instance, if you access a database in the handler, it's pretty obvious that the thread might be stuck for a few ms, and with 800 concurrent requests running, you will get awfull performances. That is exactly what happens. Virtually all calls that come in via a MINA connection are hitting our DB. So this being the case, do you recommend the approach documented here: http://mina.apache.org/configuring-thread-model.html At this point, it's all about decoupling the code run in handler from the MINA stack, using Executors. Would you mind looking at my second post which shows the implementation I have done using the configuration in the document indicated above, and letting me know whether that looks correct to you? I would really appreciate that. Just so I know I'm on the right track with the configuration section. As I said earlier, we are going with 2.0 in the next release, but I need to get out a patch release to buy us some time. AFAICT, sounds good to me. -- -- cordialement, regards, Emmanuel Lécharny www.iktek.com directory.apache.org
Re: Is it just me?
boB Gage wrote: Rats, I musta screwed something up on my endI hear RC2 will contain the only patch we've applied, so I'm thinking we'll just skip RC1 if I can't make the source build anymore... I just checked out a clean copy ( http://svn.apache.org/repos/asf/mina/trunk ) and ran ' mvn clean install ' and am still getting the same odd version failure Sometime, you also have to doom your .m2/repository directory before running a mvn clean install. Can you try that ? -- -- cordialement, regards, Emmanuel Lécharny www.iktek.com directory.apache.org
Re: Processing order of filters
Julien Vermillard wrote: Le Tue, 27 Oct 2009 10:44:30 +0100, pi...@dokom.net a écrit : Well, I use version 2.0M6 and I have trouble with the order of filters. I created a protocol encoder/decoder and some filters. The filters extend IoFilterAdapter and overwrite messageReceived/Sent. This works well for for inbound messages, the protocol is used first and than the filters are used on their order. The trouble starts outbound. I would expect that the filter chain is processed in the reverse order but id did not! The filters are called in the same order as the for the inbound messages. Is this the designed behaviour? Any ideas? The messageSent is a PITA, the filterWrite is in reverse order. Right, I forgot to mention that the write is done in reverse order. this is where it's even more confusing... -- -- cordialement, regards, Emmanuel Lécharny www.iktek.com directory.apache.org
Re: Processing order of filters
We have had the same issue in Apache Directory project, and we have had to implement the codec in a certain way in order to make it work, as it was a two stage decoder. Not really easy... Could you please explain? We have a two stages decoder. It's all done in one single codec, which is stateful. We store the current state in the IoSession, and when we receive more bytes, we resume the decoding exactly where it stopped. I must admit that the current impl is also a perfect maze... Debugging MINA is just requiring a very high IQ :/ Doesn't that make you think? Eh... Why do you think we started a 3.0 ??? Another thing I tried is the implementation of filterChain.getAllReverse() gives you the reverse ordered filters. But if you ask the retrieved list with getNextFilter() on you get the old order. I would assume that you get the reverse order too, but you will probably answer that it works as designed. I can't argue about this. All of this is quite frustrating, I think I have to create my own filter chain as handler. That's the only solution I see that matches my time frame. Probably... Sorry for that, the current code is not perfect, and this is the reason we are really impatient to start the 3.0 version. And again. I can not use a handler to implement my own filter chain. The handler (messageSent) is to late on the outbound side. What to filter if it's already sent? The MessageSent event is just produced when the message was actually *sent*. You can do a lot of thing with this information, like gathering stats, etc. Now, it may not have to be processed by a codec. In this case, you don't have to implement the method in your filters. Overall, I suggest you have a look at the many examples we provide, to see how MINA works in detail. There is probably something you have missed, due to the documentation which is not explicit enough. I understand that's a bit frustrating, but there is little I can do here to help you with your frustration except telling you that if you feel you can help building a better framework, then please, join us ! -- -- cordialement, regards, Emmanuel Lécharny www.iktek.com directory.apache.org
Re: please remove me from users list
Shiran wrote: Please follow the instructions on http://mina.apache.org/mailing-lists.html -- -- cordialement, regards, Emmanuel Lécharny www.iktek.com directory.apache.org
Re: TCP protocol acknowledgement delay(looks like piggybacking with the message response)
Erinc Arikan wrote: Thanks so much Emmanuel; I totally forgot to mention that I am using MINA 2.0 RC1. I gave it a try and It worked great, I see 2-3 seconds between ack and response now. Great ! One thing that I wonder is optimum number of threads for an executor. For now I set it to 10, But I don't think that I would need more than 2-3 threads at a time for a connection. Do you think that it would affect the performance drastically when I have 1 devices connected to my gateway. I think it does not matter too much, as soon as if your processing is fast, then the threads will be made available fast enough for other tasks. Now, if it takes, say, 100 ms to process a request, and if you have 100 simultaneous tasks running, then you definitively need 10 threads available in the pool (probably a few more in order to avoid bottlenecks). So if you have 1 devices doing one request every 5 seconds, and if it costs 100 ms to process a request, the the math is simple : you will have an average of 200 requests being processed simultaneously, so you'll need 200 threads. But a 100 ms processing time is HUGE. Note : when I say *simultaneous*, it means requests being processed *at the same time*. (people are often confusing requests per second and number of requests that can be processed simultaneous at a specific moment). -- -- cordialement, regards, Emmanuel Lécharny www.iktek.com directory.apache.org
Re: Problems using TextLineCodecFactory
Mark Wallsgrove wrote: Hi all, Hi, Is there a new line sent at the very end off your incoming message, so that the textLineDecoder can know that the message has been fully received ? I am having some problems with the TextLineCodecFactory Mina 2.0.0. For some reason when I try to receive some data as a client I get this: DEBUG [com.test.XMPPHandler] - Session Created DEBUG [com.test.XMPPHandler] - Message Sent: stream:stream xmlns=jabber:client to=jabber.org xmlns:stream=http://etherx.jabber.org/streams; xml:lang=en version=1.0 DEBUG [org.apache.mina.filter.codec.ProtocolCodecFilter] - Processing a MESSAGE_RECEIVED for session 1 DEBUG [com.test.XMPPHandler] - Session Idle The ProtocolCodecFilter claims that it is processing the data, but my handler never receives it. I managed to monitor the incoming data using Wireshark, and it looks as expected. I only have one codec which is added in the handler under the sessionOpened method like: session.getFilterChain().addLast(codec, new ProtocolCodecFilter(new TextLineCodecFactory(Charset.forName(UTF-8; What would be the reason for this? -- -- cordialement, regards, Emmanuel Lécharny www.iktek.com directory.apache.org
Re: The performance of mina
xmuysa wrote: Hi, In our project,we need the performance of socket more than 500tps, FYI, on my laptop, I get 4500 LDAP requests per second using Apache Directory Server, and we went up to 13 000 requests per second on a 4 way CPU computer. And trust me, LDAP is a pretty expensive protocol. (we are using MINA 2.0) Looking at your base config, I see nothing wrong about it. Now, you have many areas where you'll like to check : - Handler : no matter what you do with MINA, Handler is where the CPU is eaten. The ration Handler/MINA is probably something like 95%/5%. Check your handlers to see if this is not the place you can get some performance improvement - Network : slow network, firewall, badly configured routers, are also another performance killer. This is pretty much all I can tell you so far. But in any case, 500 Tps is basically not a problem for MINA *alone*. Check your own code or your network... -- -- cordialement, regards, Emmanuel Lécharny www.iktek.com directory.apache.org
Re: Multiple Messages being recieved at the same time..
Mark Wallsgrove wrote: Hey, Thanks for the quick replies. Surely this isn't due to fragmentation? Wouldn't fragmentation come down to multiple reads per network packet being sent? Which would be fine, but all the messages that are being sent fit within a single tcp/ip packet and are being received as a single packet. No. You have no reason to think that when you read a socket you will have only one single message in it. In fact, you have to iterate in your codec until you have nothing more to process. This is the very essence of TCP/IP. Deal with it... -- -- cordialement, regards, Emmanuel Lécharny www.iktek.com directory.apache.org
Re: Multiple Messages being recieved at the same time..
On Sat, Nov 14, 2009 at 2:44 PM, d...@xx d...@proxiflex.fr wrote: Well it is difficult to use Mina if you don't know how socket are working... When you buy a car, how to drive a car is not explained in the car documentation ! How strange ... ;-) -- Regards, Cordialement, Emmanuel Lécharny www.iktek.com
Re: Stackoverflow and inifinite loop when sending a message
Mathieu Sacrispeyre wrote: Hello, Hi, I have a project which is working fine with mina 2.00 M5 and serial transportation. I tried to update to rc1 but it do not work anymore. There is an handler that adds a protocol codec filter to the 2 placed by its superclass in the filterchain of the session. Something like this : connector.getFilterChain().addLast(PROTOCOL_NAME_TRANSPORT, new ProtocolCodecFilter(new TransportProtocolCodecFactory())); connector.getFilterChain().addLast(PROTOCOL_NAME_BUSINESS, new ProtocolCodecFilter(new BusinessProtocolCodecFactory())); Then in the child handler : connector.getFilterChain().addBefore(ADlMinaHandler.PROTOCOL_NAME_HIGH, PROTOCOL_NAME_INTERMEDIATE, intermediateProtocolCodecFilter); With the rc1 version when calling session.write, it ends with a stackoverflow iterating on these lines : at org.apache.mina.core.filterchain.DefaultIoFilterChain.callPreviousFilterWrite(DefaultIoFilterChain.java:508) at org.apache.mina.core.filterchain.DefaultIoFilterChain.access$7(DefaultIoFilterChain.java:502) at org.apache.mina.core.filterchain.DefaultIoFilterChain$EntryImpl$1.filterWrite(DefaultIoFilterChain.java:807) at org.apache.mina.filter.codec.ProtocolCodecFilter$ProtocolEncoderOutputImpl.flushWithoutFuture(ProtocolCodecFilter.java:435) at org.apache.mina.filter.codec.ProtocolCodecFilter.filterWrite(ProtocolCodecFilter.java:301) It seems that it is looping on the business and intermediate protocol filters without any call to the transport one : the content of the resulting filterchain or the way entries are iterated may have changed between the 2 versions...? Before having a deeper look at the issue, I wanted to know/confirm : - if this is a known issue (haven't seen something about that on this mailing list...) No, AFAICT - if the use of mina described here is correct Enqueueing two codecs is a bit courageous... It's difficult to say what's going on at this point. Can you create a JIRA and attach a minimal sample for us to test it ? Thanks ! -- -- cordialement, regards, Emmanuel Lécharny www.iktek.com directory.apache.org
Re: Stackoverflow and inifinite loop when sending a message
Mathieu Sacrispeyre wrote: I agree with you : my code is working well with the previous version so I would be disappointed not to be able to use it anymore In my case, passing an IoBuffer to the upper codec isn't so annoying even if it sounded a bit strange at the beginning. I have a patch for this problem, if anyone want to test it (applicable on 2.0-RC1) (remove the XXX lines ): start after this line Index: core/src/main/java/org/apache/mina/filter/codec/ProtocolCodecFilter.java === --- core/src/main/java/org/apache/mina/filter/codec/ProtocolCodecFilter.java (revision 881795) +++ core/src/main/java/org/apache/mina/filter/codec/ProtocolCodecFilter.java (working copy) @@ -53,10 +53,10 @@ private static final Class?[] EMPTY_PARAMS = new Class[0]; private static final IoBuffer EMPTY_BUFFER = IoBuffer.wrap(new byte[0]); -private static final AttributeKey ENCODER = new AttributeKey(ProtocolCodecFilter.class, encoder); -private static final AttributeKey DECODER = new AttributeKey(ProtocolCodecFilter.class, decoder); -private static final AttributeKey DECODER_OUT = new AttributeKey(ProtocolCodecFilter.class, decoderOut); -private static final AttributeKey ENCODER_OUT = new AttributeKey(ProtocolCodecFilter.class, encoderOut); +private final AttributeKey ENCODER = new AttributeKey(ProtocolCodecFilter.class, encoder); +private final AttributeKey DECODER = new AttributeKey(ProtocolCodecFilter.class, decoder); +private final AttributeKey DECODER_OUT = new AttributeKey(ProtocolCodecFilter.class, decoderOut); +private final AttributeKey ENCODER_OUT = new AttributeKey(ProtocolCodecFilter.class, encoderOut); /** The factory responsible for creating the encoder and decoder */ private final ProtocolCodecFactory factory; @@ -210,7 +210,7 @@ } IoBuffer in = (IoBuffer) message; -ProtocolDecoder decoder = getDecoder(session); +ProtocolDecoder decoder = getDecoder0(session); ProtocolDecoderOutput decoderOut = getDecoderOut(session, nextFilter); // Loop until we don't have anymore byte in the buffer, @@ -288,7 +288,7 @@ } // Get the encoder in the session -ProtocolEncoder encoder = getEncoder(session); +ProtocolEncoder encoder = getEncoder0(session); ProtocolEncoderOutput encoderOut = getEncoderOut(session, nextFilter, writeRequest); @@ -322,7 +322,7 @@ public void sessionClosed(NextFilter nextFilter, IoSession session) throws Exception { // Call finishDecode() first when a connection is closed. -ProtocolDecoder decoder = getDecoder(session); +ProtocolDecoder decoder = getDecoder0(session); ProtocolDecoderOutput decoderOut = getDecoderOut(session, nextFilter); try { @@ -488,16 +488,6 @@ } /** - * Get the decoder instance from a given session. - * - * @param session The associated session we will get the decoder from - * @return The decoder instance - */ -private ProtocolDecoder getDecoder(IoSession session) { -return (ProtocolDecoder) session.getAttribute(DECODER); -} - -/** * Dispose the decoder, removing its instance from the * session's attributes, and calling the associated * dispose method. @@ -534,6 +524,28 @@ return out; } +private ProtocolEncoder getEncoder0(IoSession session) throws Exception { +ProtocolEncoder encoder = (ProtocolEncoder) session +.getAttribute(ENCODER); +if (encoder == null) { +encoder = factory.getEncoder(session); +session.setAttribute(ENCODER, encoder); +} +return encoder; +} + +private ProtocolDecoder getDecoder0(IoSession session) throws Exception { +ProtocolDecoder decoder = (ProtocolDecoder) session +.getAttribute(DECODER); + +if (decoder == null) { +decoder = factory.getDecoder(session); +session.setAttribute(DECODER, decoder); +} + +return decoder; +} + private ProtocolEncoderOutput getEncoderOut(IoSession session, NextFilter nextFilter, WriteRequest writeRequest) { ProtocolEncoderOutput out = (ProtocolEncoderOutput) session.getAttribute(ENCODER_OUT); End before this line -- -- cordialement, regards, Emmanuel Lécharny www.iktek.com directory.apache.org
Re: Custom messageSent
Pavel Zdenek wrote: 2009/11/23, Emmanuel Lecharny elecha...@apache.org: Pavel Zdenek wrote: Greetings fellow min(a)ers! I understand the controversy over messageSent, because the feature of firing twice per each actual object being encoded is annoying me as well. Anyway, i do need such sort of event information in my current pet project, something has to happen in the persistent layer after the message delivery is confirmed. Unfortunately, the most recommended hack solution with waiting on WriteFuture is neither applicable, because i do physically send out a multiple IoBuffers for each abstract message written. I need to get the messageSent on the last one, not the first one (as it happens now). I am thinking about setting up a wait condition after session.write and signalling it from the correct messageSent. But i am too unfamiliar with the threading model of Mina, to say whether it's a good idea. Somebody with better understanding say? The way it works is that each 'message' is enqueued until it's sent. Then a MessageSent event is generated. Sadly, we don't associate a umber with each message, so it's difficult to correlate a MessageSent event with a given message, except that AFAIR, the IoBuffer is present in the messageSent event. If so, you may be able to compare the message content with what you know to be the last message sent (you can store it in the session for instance). This is from the top of my head... Fortunately my protocol is strictly synchronous request/response, so the message matching will be much easier. Safety question: may it happen, that the session handling (which writes a response object into the session) will be the same thread as the one which initiates messageSent? From my observation, this is not the case, but i prefer asking first and shoot a code later... It depends if you have an executor in your chain. If you don't, then every message processing for a session will be processed by a single thread : the one associated with the IoProcessor (as the IoProcessor holds the selctor, it makes sense). Now, if you have an executor, you may have a message processed by different threads, as the exector acts as a demultiplexer : it picks a thread in the pool and ask it to process the message. If your executor is used in both side (you can perfectly ask the executor not to be used when writing messages), then another thread will e used to write the message (not sure what will be the impact though ...) Is there any document describing the threading model of MINA? I remember seeing some comprehensive picture about Netty, long time ago... Time's flying ... There are a few slides available, not sure if they are accurate. At some point, we should write some samples to demonstrate the different use cases. Thanks a lot, Pavel Z. -- -- cordialement, regards, Emmanuel Lécharny www.iktek.com directory.apache.org
Re: Miserable performance results from MINA 1.1.7
Can you add this line in your server : ((SocketSessionConfig) acceptor.getSessionConfig()).setTcpNoDelay(false) and see if it makes any difference ? Zvika Gart wrote: Sorry, but Nagle doesn't have anything to do with this... Nagle is relevant at the *client side* when sending small buffers over the network. My client is a simple C# program (not MINA, so SocketConnector is irrelevant) that sends large buffers (100KB) at each call to Socket.Send() If Nagle was to blame then I would see the same bandwidth from both server implementations. This is not the case. On Tue, Nov 24, 2009 at 8:41 PM, Emmanuel Lecharny elecha...@apache.orgwrote: Damn Nagle ! ( http://en.wikipedia.org/wiki/Nagle_algorithm ) Check the FAQ : http://mina.apache.org/faq.html ( Why does SocketConnector send several messages as one message?) Zvika Gart wrote: Hello, Please help, as this is too strange to be true... I'm comparing two implementations of the most basic socket server - it listens for a client, and after accepting it just starts reading data from it. The first implementation using Java's plain old ServerSocket: ServerSocket srv = new ServerSocket(80); Socket s = srv.accept(); InputStream i = s.getInputStream(); byte[] buf = new byte[1024 * 8]; while (true) { i.read(buf); } The Second implementation using MINA 1.1.7 (which so simple that I can paste it here): First the Main class: package test; import java.net.InetSocketAddress; import org.apache.mina.common.ByteBuffer; import org.apache.mina.common.IoAcceptor; import org.apache.mina.common.SimpleByteBufferAllocator; import org.apache.mina.transport.socket.nio.SocketAcceptor; public class Main { public static void main(String[] args) throws Exception { // The following two lines don't help ByteBuffer.setUseDirectBuffers(false); ByteBuffer.setAllocator(new SimpleByteBufferAllocator()); IoAcceptor acceptor = new SocketAcceptor(); acceptor.bind(new InetSocketAddress(80), new MyHandler()); } } And the IoHandler: package test; import org.apache.mina.common.IoHandlerAdapter; public class MyHandler extends IoHandlerAdapter { } I wrote a simple client that connects to the server and pumps continuous data. Both client and server run on Amazon's EC2 on Debian Linux instances (64-bit, Java 1.6). Client is in Europe and server in USA. *The results:* Simple Java implementation - 5 Mbps MINA implementation - 750 Kbps Tried removing the setUseDirectBuffers lines; tried a simpler threading model by running the IoHandler on the IoProcessor threads... nothing helps - MINA is capped at 750 Kbps. What is going on here?! -- -- cordialement, regards, Emmanuel Lécharny www.iktek.com directory.apache.org -- -- cordialement, regards, Emmanuel Lécharny www.iktek.com directory.apache.org
Re: Miserable performance results from MINA 1.1.7
Zvika Gart wrote: The default is false... I tried disabling Nagle by setting TcpNoDelay to true. As expected, this didn't have any effect - the server doesn't send any data to the client, only receives data. Assuming that you are sending 8Kb buffers, anyway, it should not make any difference. Now, I don't have the code in MyHandler, so it's difficult to see what you do there. Also, have you tried with MINA 2.0.0-M6? -- -- cordialement, regards, Emmanuel Lécharny www.iktek.com directory.apache.org
Re: Miserable performance results from MINA 1.1.7
Zvika Gart wrote: This is the code of my handler. It doesn't do anything. That's the point. The server should just consume the data as fast as it can. Interesting. I have to test this code on my computer to see exactly what can be the impact. Can you add an executor in the filter cxhain to see if it improves the performance ? Strangely enough, Mina 2.0 performs even worse then 1.1.7 Is there some problem in using Java nio on Virtualized machines? Not that I know about. Anyone else ? -- -- cordialement, regards, Emmanuel Lécharny www.iktek.com directory.apache.org
MINA on Amazon EC2 : degraded performances observed, why ? (was Re: Miserable performance results from MINA 1.1.7)
Zvika Gart wrote: The default threading model in 1.1.7 is to use the executor filter. I also tried removing it. Both don't help. Ok. I tested this scenario using two PCs at the office connected with a crossover cable. The MINA server is reaching the 100 Mbps link speed limit. Why running on Amazon's instances yields such a poor performance?? Interesting. So MINA on a local network does works fine, and in Amazon, it's slow as a dog, when a standard ServerSocket is just plain ok. I changed the subject so that those who have already used MINA on EC2 can popup and give use some insight... -- -- cordialement, regards, Emmanuel Lécharny www.iktek.com directory.apache.org
Re: BufferUnderFlowException in org.apache.mina.filter.codec.ProtocolCodecFilter
Alexander Christian a écrit : Hi guys, snip/ I've no idea what causes this bufferunderflow. And i've no idea how to track down the root of this issue (the stack does only show mina classes ..). Unchecked exception thrown when a relative get operation reaches the source buffer's limit. Basically, you try to do a get()on the IoBuffer but there is nothing left into it. Remember that you may perfectly receive your message in small pieces, and you will have to reassemble them before being able to decode it.
Re: Who is the author of AbstractPollingIOProcessor.java?
Hi, more inline zswallow a ??crit : I use mina-2.0.0-RC1 to recv media data(TCP/IP) and immediately send it out. I set 2 NioProcessor, one is for recving data, the other is for sending the recved data. Hmmm... Can you post the code ? It's a bit strange, I don't see how you can dedicate a IoProcessor for send. Why aren't you using a Connector in this case ? snip/ if it is a bug? Difficult to tell, just create a JIRA and attach the offending code. Anyone can help me with this, or contact the author of AbstractPollingIOProcessor.java? You are on the right place. No need to contact someone specifically, as this code has been modified many times by many people (7 at least)...
Re: 2.0.0-RC1 bug? -- IoConnectot.dispose blocks forever?
Alexander Christian a écrit : Hey there, Am I the only one who faced this problem? No comments? No problems? Is it possible that you provide a piece of code that demonstrate the problem ? Thanks ! -- Regards, Cordialement, Emmanuel Lécharny www.nextury.com
Re: TCP half-open connection question
Srikanth J a écrit : Hi I am facing a problem with tcp half-open connection. Would really appreciate any thoughts on the issue The application uses mina tcp server (mina version - 1.1.7) with a MLLP codec (MLLP codec is provided by apache-camel). The problem is that this application runs behind a hardware load balancer which does a tcp half-open service ping to monitor if application is still available. The half-open involves load balancer sending a SYNC, receiving the ACK from mina server, but not sending a ACK back (not completing 3way hankshake) and then sending a Reset and FIN commands. This is resulting in the following exception being thrown every time half-open is done org.apache.camel.CamelException: java.io.IOException: Connection reset by peer (errno:232) at org.apache.camel.component.mina.MinaConsumer$ReceiveHandler.exceptionCaught(MinaConsumer.java:90) at org.apache.mina.common.support.AbstractIoFilterChain$TailFilter.exceptionCaught(AbstractIoFilterChain.java:564) at org.apache.mina.common.support.AbstractIoFilterChain.callNextExceptionCaught(AbstractIoFilterChain.java:345) at org.apache.mina.common.support.AbstractIoFilterChain.access$1000(AbstractIoFilterChain.java:53) at org.apache.mina.common.support.AbstractIoFilterChain$EntryImpl$1.exceptionCaught(AbstractIoFilterChain.java:643) at org.apache.mina.common.IoFilterAdapter.exceptionCaught(IoFilterAdapter.java:75) at org.apache.mina.common.support.AbstractIoFilterChain.callNextExceptionCaught(AbstractIoFilterChain.java:345) at org.apache.mina.common.support.AbstractIoFilterChain.access$1000(AbstractIoFilterChain.java:53) at org.apache.mina.common.support.AbstractIoFilterChain$EntryImpl$1.exceptionCaught(AbstractIoFilterChain.java:643) at org.apache.mina.filter.executor.ExecutorFilter.processEvent(ExecutorFilter.java:224) at org.apache.mina.filter.executor.ExecutorFilter$ProcessEventsRunnable.run(ExecutorFilter.java:264) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:650) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:675) at org.apache.mina.util.NamePreservingRunnable.run(NamePreservingRunnable.java:51) at java.lang.Thread.run(Thread.java:595) Caused by: java.io.IOException: Connection reset by peer (errno:232) at sun.nio.ch.FileDispatcher.read0(Native Method) at sun.nio.ch.SocketDispatcher.read(SocketDispatcher.java:21) at sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:233) at sun.nio.ch.IOUtil.read(IOUtil.java:200) at sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:207) at org.apache.mina.transport.socket.nio.SocketIoProcessor.read(SocketIoProcessor.java:218) at org.apache.mina.transport.socket.nio.SocketIoProcessor.process(SocketIoProcessor.java:198) at org.apache.mina.transport.socket.nio.SocketIoProcessor.access$400(SocketIoProcessor.java:45) at org.apache.mina.transport.socket.nio.SocketIoProcessor$Worker.run(SocketIoProcessor.java:485) ... 2 more Is this a known issue (i did look up the mail archive and did some googling, dint find much) or is this happening because of any possible wrong configuration of mina? Sounds to me plain normal, as soon as the load balanced send a badly crafted message to the stack. You want your handler to know that the connection has been brutally terminated, in order to close the session and free all the resources you have allocated for this session, no ? Check on the load balancer side to see if it can send something a bit smarter. Another possibility would be to tune the MLLP codec to handle such a terminaison. -- Regards, Cordialement, Emmanuel Lécharny www.nextury.com
Re: slow performance with large messages
Hi, please mention the MINA version you are using when psoting a question... Comments inline. Simmons, Aaron a écrit : I am implementing a mina server for a protocol that can sometimes send very large messages (250K). I've noticed that receiving these messages can be very slow (12s). This performance is surprising, as I can transfer a 250K file to this same server via scp or netcat in under 1.5s. There is an issue with the way we handle the sendBufferSize, it's initial size is small (8192 bytes), and should be set to the system default. See DIRMINA-651 for more information. You can change this value before opening the acceptor, by injecting the desired value in the SessionConfig object. Something like : final IoAcceptor acceptor = new NioSocketAcceptor(); acceptor.getSessionConfig().setSendBufferSize( whatever fits you ); ... -- Regards, Cordialement, Emmanuel Lécharny www.nextury.com
Re: slow performance with large messages
Simmons, Aaron a écrit : You can change this value before opening the acceptor, by injecting the desired value in the SessionConfig object. Something like : final IoAcceptor acceptor = new NioSocketAcceptor(); acceptor.getSessionConfig().setSendBufferSize( whatever fits you ); ... Hmm, according to the docs for ISessionConfig here http://mina.apache.org/report/trunk/apidocs/org/apache/mina/core/session/IoSessionConfig.html there's no setSendBufferSize. Perhaps you meant setReadBufferSize? As inconsistent it may sounds, the class you want to look at is SocketSessionConfig, not inheriting from IoSessionConfig... Don't ask my whay ;) -- Regards, Cordialement, Emmanuel Lécharny www.nextury.com
Re: slow performance with large messages
Simmons, Aaron a écrit : There is an issue with the way we handle the sendBufferSize, it's initial size is small (8192 bytes), and should be set to the system default. See DIRMINA-651 for more information. I looked up DIRMINA-651 (Data Race in org.apache.mina.core.session.AbstractIoSession). I'm not sure I see how this relates to the buffer size? Sorry, my pomcuter is dilesxic. http://issues.apache.org/jira/browse/DIRMINA-561 -- Regards, Cordialement, Emmanuel Lécharny www.nextury.com
Re: Client Inrush
Christopher Popp a écrit : Hi, Hi, comments inline I wanted to get some feedback. (MINA 2.0.0 M6). We're currently doing inrush testing of clients against our mina based application. We're able to have 1024 clients connect in roughly simultaneously (30 second window), however we're not able to get our system to stabilize when doing 2048 or 4096 simultaneous clients. On connection, there is an exchange of messages between the client and server, and a couple database calls that take place per client. Blind guess : a couple of database calls will most probably be the contention point in your system. From some tests I conducted with Oracle, a request/response loopback with a DB costs a few ms. Even f it sounds a small number, this is a clear limitation when you don't have tens of CPU... But this is just a blind guess. My advice here would be to use a profiler to check what's going on exactly. Another option would be to mockup the DB and see how MINA will behave when you have moved aside the potential costly operations. We also have application level keep-alives that we need to send out, otherwise the device will disconnect. Our keep-alive filter basically implements the sessionIdle method, and when it expires for the server, we write a keep-alive, and when it expires for the device, we disconnect the device. Based on a network trace, we are not seeing keep-alives sent out when they should be under this load. Our presumption is that this is due to mina's worker threads being too busy with database processing and such. acceptor = new NioSocketAcceptor(Runtime.getRuntime().availableProcessors() + 1); acceptor.getFilterChain().addLast(protocol, new ProtocolCodecFilter(new XXCodecFactory())); acceptor.getFilterChain().addLast(threadPool, new ExecutorFilter(workerThreadPool)); acceptor.getFilterChain().addLast(keepAlives, newXXKeepAliveFilter(new MTKeepAliveMessageFactory()); acceptor.setHandler(devHandler); During these tests we were using the default constructor for the ExecutorFilter, limiting us to 16 worker threads. We have since changed this to be configurable and will bump the number of threads up quite a bit. We're expecting this to improve the situation quite a bit. However, it seems that if for whatever reason this constant number of threads get tied up doing work, our keep alive processing will halt, and clients will disconnect which eventually could cause a cyclic destabilizing of the system. Again, profiling the application could help here. What would be nice is to be able to have a set of threads that are dedicated to handling keep-alives. One thing I thought of is to add another ExecutorFilter dedicated to handling SESSION_IDLE events, similar to what is shown in the javadocs for WRITE IoEvents in the javadocs. This way, a thread should still pass on the SESSION_IDLE events to the keep alive filter we have. Some questions about this though. If from the idle event in the keep alive filter I attempt to write the keep alive, will this end up being blocked due to the fact that there are no extra threads from the main executor available? (And hence, I actually need two extra executor filters...one for SESSION_IDLE and one for WRITE). And if I decide to add these extra executor filters, where should they go in the filter chain in relation to the other executor filter? It just seems that if an executor is out of threads, it would block the filter chain regardless of whether there is an executor earlier on in the chain that has contributed a thread. I would have to assume this is handled somehow though. Also, is there any benefit to increasing the number of IO processor threads to more than the number of cores + 1? I don't think so, as soon as you have an executor in the chain. The IoProcessor is the class which manage the selector, and I'm not sure that having many selectors can help. However, I have no metric on that ... I read that as the suggested starting point, but in the somewhat outdated documentation on the threading model, (http://mina.apache.org/configuring-thread-model.html), it is stated the a newCachedThreadPool is suggested for IoServices. yeah, it's totally outdated and need to be improved A LOT. In fact, we need to conduct some extensive tests and see what could be the best configuration for a different set of use cases... -- Regards, Cordialement, Emmanuel Lécharny www.nextury.com
Re: Some writes observed to stall until select times out
Ok. Create a JIRA, not sure someone can check the code in the next couple of days, so with a JIRA, it won't be forgotten ! Thanks ! On Wed, Dec 30, 2009 at 2:40 AM, John Fallows john.fall...@kaazing.comwrote: On Tue, Dec 29, 2009 at 3:10 PM, Emmanuel LŽcharny elecha...@gmail.com wrote: John Fallows a écrit : Folks, We have observed an issue in Mina 2.0-M4 where TCP writes are not flushed to the network even though the receiver is keeping up and CPU has low utilization. Please confirm that it's still an issue with 2.0-RC1. We have released 3 versions since M4... Confirmed, 2.0.0-RC1 exhibits the same behavior as 2.0.0-M4 for this scenario. The previously proposed 2.0.0-M4 fix of removing the needsWakeup check from AbstractPollingIoProcessor.flush() also resolves the issue for 2.0.0-RC1. Kind Regards, John Fallows -- | Kaazing Corporation | John Fallows | CTO | +1.650.960.8148 888 Villa St, Ste 410 | Mountain View, CA 94041, USA -- Regards, Cordialement, Emmanuel Lécharny www.iktek.com
Re: message process order
hakan eryargi a écrit : hi, how can i guarantee messages are processed in arrival order and sequantially (one is processed after previous is completed) for NioSocketAcceptor ? This is guaranteed, as soon as you don't inject an ExecutorFilter in your chain (see [1] for more info about this point). The way incoming messages are processed by MINA is pretty simple : each opened socket is associated with a selector, itself associated with a IoProcessor. IoProcessor uses a single thread to process this message, but to insure some scalability, we spawn more than one IoProcessor, and we also use a queue (the backlog) for messages waiting to be processed when the thread is busy. So the order will always be respected, as the next message can only be processed when the current message has been completely processed. The biggest issue with this approach is that each message is considered having the very same priority, and a message neeeding a long processing will block all the other messages. More important, you will block messages from other sessions too. That's painful, and this is one of the reason the ExecutorFilter has been added. i guess, as tcp guarantees packet order, for each IoSession message order is guaranteed. but if messages are passed to IoHandler in a multi-threaded manner there could be cases process order is different from arrival order. [1] This is where the ExecutorFilter comes into the picture : it creates a way to process more than one message at the time (or kind of...). The drawback is that you may have more than one message of a specific session being processed in parallel. This can be avoided by teling the ExecutorFilter to use a OrderedThreadPoolExecutor. Hope it helps. -- Regards, Cordialement, Emmanuel Lécharny www.nextury.com
Re: MINA hanging onto dead connections?
Laurent Cohen a écrit : Hello all, Typically, a technique that I've implemented was using the fact that, when the remote peer is disconnected for any reason, the corresponding SelectionKey on the server becomes readable(). Even when the client hasn't sent a FIN ? It is possible to use this when you know for example that the connection should be either idle or waiting for the server to send something. In this case, you just need to add OP_READ to the operations the key is interested in. For instance, if an idle connection becomes suddenly readable - as in SelectionKey.isReadable() - then it means it is disconnected. Well, I would rather bet that this means something has to be read. For this to apply, you also need to keep some state attached to the SelectionKey, so that you know that it is readable when it shouldn't. I'm not sure I grok what you says her, but may be I need a coffee or two... (just woke up). -- Regards, Cordialement, Emmanuel Lécharny www.nextury.com
Re: 2.0.0-RC1 bug? -- IoConnectot.dispose blocks forever?
https://issues.apache.org/jira/browse/DIRMINA-755 created :) You can add you as a follower, you'll receive any update on this issue automatically. -- Regards, Cordialement, Emmanuel Lécharny www.nextury.com
Re: mem leak?
David Rosenstrauch a écrit : On 01/13/2010 03:39 AM, Emmanuel Lcharny wrote: vagrant1984 a écrit : We are currently using MINA 2.0.0-M6. The current version is 2.0.0-RC1, please switch to this version as many bug fixes has been injected into the code. I've actually been holding off on upgrading us off of 2.0.0-M6 - since 2.0 is in release candidate mode, I figured that a true 2.0 was coming soon. Totally agree, if your program works. But if you have issues, then it's better to check with the most recent version to see if those issues are still present. Just wondering what the dev roadmap is and when a 2.0 release might be coming? We are trying to cleanup the remaining bugs atm - call it bug parade - in order to be able to vote a 2.0 (next week ?) -- Regards, Cordialement, Emmanuel Lécharny www.nextury.com
Re: Connection reset by peer
Ted Yu a écrit : Hi, I saw this snippet in our server log many times: snip/ java.io.IOException: Connection reset by peer /snip If someone has seen such stack trace, please share how to fix the problem. Very simple : stop accepting clients who evily disconnect without notice ! Bad, bad clients ... I *always* close a socket correctly, never slamming the door, even if my computer stops because of a power shutdown... More serioulsy, it's just an information that a client has quit brutally. There is nothing to fix here, except logging less. -- Regards, Cordialement, Emmanuel Lécharny www.nextury.com
Re: supporting multiple clients with MINA
Christopher Popp a écrit : Emmanuel Lcharny wrote: That would be crazy :) Really, MINA does that for you. One simpe rule: one client, one session. One hundred thousands clients, one hundred thousands sessions (it has been tested up to these numbers ;) Out of curiosity, how was a test of one hundred thousand clients performed on a machine with a 65k socket limit? You can handle more than 65k sockets on a server (at least on a Unix based server), I don't know about W$). Did the server bind to multiple addresses? We just had a test proceed with some success with 128k sessions across our cluster, but this is across 8 servers (16k sessions each) built on MINA, and each JVM sharing some information through Terracotta. I guess that if your servers get loaded, you must spread the sessions on multiple machines. What kind of oad do you see on those machines ? We've only ran into one problem that has eluded us so far that seemingly causes all of the sockets in use by our JVM to get messed up, causing MINA sessions, the Terracotta client connection, and our database connections to be lost. We're running the tests with instances on Amazon EC2, so one thing we're going to try is running it on some physical servers. Some blogs regarding network performance of Amazon EC2 have been less than stellar in their reviews of it, and we're being pretty tough on them. We certainly would be interested to get some numbers from 'the real world' :) If you can share some information on your MINA usage here, that would help us to see how far we can go with MINA : many people are asking us what kind of performance MINA can provide in such env. Thanks ! -- Regards, Cordialement, Emmanuel Lécharny www.nextury.com
Re: supporting multiple clients with MINA
Michael Clifford a écrit : Hello. I've started playing around with storing data as attributes in the session object. That's really useful. :-) And you had suggested storing the string that comes through in the session as a session attribute. What I'm wondering is if there might be a more efficient way to do this. When a session gets a received message, the messagereceived method receives both the session and an object containing the message. Is that object already part of the session, or was it already extracted? It's not part of the session. If it is still inside the session, maybe I can save myself the step of copying it to an attribute in the session. Really, I don't have a clue about what you are trying to do here. Keeping something as a Session's Attribute is just a convnien way to get it stored somewhere you can get it from when your application needs it. Now, it's up to you to store it on the file system or on any storage you want to use. -- Regards, Cordialement, Emmanuel Lécharny www.nextury.com
Re: BlacklistFilter
jose vilmar estacio de souza a écrit : One more question please. Looking at class BlackListFilter I saw that the locking mechanism was implemented in all routines, sessionCreated, sessionOpened, sessionClosed, sessionIdle, messageReceived and messageSent. I think that would be sufficient to implement in the method sessionCreated. Is it true or am I missing something? Assming you can block a session at any time sinc eit began, we have to check for this status for any message received. The question would be : should we close a session instead of bocking it ? -- Regards, Cordialement, Emmanuel Lécharny www.nextury.com
Re: MINA 2.0 RC code base stability?
Michael Clifford a écrit : I'm doing pretty well using the MINA 1.1 code base, but it looks like some of the examples require the use of 2.0. I'm a bit worried about the note that says that 2.0 is bleeding edge code though. That simply mean it's the code we are working on. There haven't been a patch on MINA 1.1 for more than one year now (almost 2), and no release too. I don't think there will be any in the next few years. How stable is it right now? Stable. No API modification, only bug releases. Am I likely to run into any problems using the 2.0 framework? It depends on which feature you use. For standard usage, it should work just fine. As far as I know, I don't need anything specific to 2.0 right now. However, I am trying to write a client to go with my server, and the client examples appear to require 2.0. So is it safe to use it? :-) yes. But there is nothing you can do with MINA 2.0 you can't do with MINA 1.1.7. You just have to convert the examples to MINA 1.1.7. Are any interfaces likely to change before release? NO (big no). API has been frozen. Are there any issues to be aware of at this point that would make it worth sticking with 1.1 instead? Not that I know. Some majot bugs have been fixed since %INA 1.1.7, and in any case, I would rather use MINA 2.0 than MINA 1.1.7. -- Regards, Cordialement, Emmanuel Lécharny www.nextury.com
Re: sorry, I'm not able to convert byte into myClass
Hi, in the first case, you can set the position in the byteBuffer using the position() method. However, you will have the exact same problem than in case 2 : you will get a BufferUnderflow for the same reason : a call to in.hasRemaining() does not tell you that you hace enough bytes to be able to decode a new BasicMessage. It just tells you that you have *some* bytes available. From the top of my head, I think you can call in.hasRemaining( expectedSize ) On Sun, Feb 7, 2010 at 11:48 AM, silviasignor...@libero.it silviasignor...@libero.it wrote: Dears, I've the same problem... I have a mina peer that communicate with myClass called BasicMessage. My problem is on decoder filter in fuction doDecode(), I convert the message into byte and receive the corret byte, but I'm not able to convert it into BasicMessage. I try two solution: FIRST SOLUTION My problem is that the program print line many times, I belive that host receive the message many times because array() will not move forward in the IoByteBuffer. Is there a fuction that cancel the IoByteBuffer? public class MessageDecoder extends CumulativeProtocolDecoder { protected boolean doDecode(IoSession session, IoBuffer in, ProtocolDecoderOutput out) throws Exception { byte[] byteVal = null; if (in.hasRemaining()){ byteVal = in.array(); BasicMessage m = createBasicMessage(byteVal); System.out.println(RICEVUTO DA + m.getSender() + \n); out.write(m); in.get(); return true; } else { return false; } } public static BasicMessage createBasicMessage(byte[] bytes){ Object object = null; try{ object = new java.io.ObjectInputStream(new java.io.ByteArrayInputStream (bytes)).readObject(); }catch(java.io.IOException ioe){ java.util.logging.Logger.global.log(java.util.logging.Level.SEVERE, ioe. getMessage()); }catch(java.lang.ClassNotFoundException cnfe){ java.util.logging.Logger.global.log(java.util.logging.Level.SEVERE, cnfe. getMessage()); } return (BasicMessage)object; } } SECOND SOLUTION In this case the receiver throws the exception org.apache. mina.filter.codec.ProtocolDecoderException: java.nio.BufferUnderflowException (Hexdump: AC ... 72). protected boolean doDecode(IoSession session, IoBuffer in, ProtocolDecoderOutput out) throws Exception { byte[] byteVal = new byte[in.capacity()]; if (in.hasRemaining()){ in.get(byteVal , 0, in.capacity()); BasicMessage m = createBasicMessage(byteVal); System.out.println(RECEIVED FROM + m.getSender() + \n); out.write(m); return true; } else { return false; } Thanks Sia -- Regards, Cordialement, Emmanuel Lécharny www.iktek.com
Re: mina 2.0 time estimate
On 2/8/10 12:33 PM, Harsha Sri-Narayana wrote: Is there a time estimate for when mina 2.0 will be released? H... When it's ready ! -- Regards, Cordialement, Emmanuel Lécharny www.nextury.com