7 Replies Latest reply on Apr 28, 2014 8:54 AM by ataylor

    Client Session concurrent usage in 2.4.1.Final

    yairogen

      I have a use-case where I am using the ClientSession instance concurrently (e.g. sending in parallel using the same producer).

       

      I thought that's the way to go as indicated in "8.1.8. ClientProducer" section in the manual:

      Please note that ClientSession, ClientProducer and ClientConsumer instances are designed to be re-used

      .

      However, I keep seeing these warnings:

       

      WARN:  HQ212051: Invalid concurrent session usage. Sessions are not supposed to be used by more than one thread concurrently.

      [Exception: java.lang.Exception: trace

       

      So - what's the best practice here? I thought consumers and producers are designed as thread-safe objects - hence I should be able to reuse them. Am I supposed to create a producer/consumer per thread?

        • 1. Re: Client Session concurrent usage in 2.4.1.Final
          ataylor

          no they are not thread safe, tret them the same way you would use JMS sessions etc.

           

          By re use we mean that you should not create a new one every time you need to send/receive a message etc.

          • 2. Re: Client Session concurrent usage in 2.4.1.Final
            yairogen

            So basically, I have to create a session+consumer+producer trio on a thread local to verify they are single threaded. correct?

            • 3. Re: Client Session concurrent usage in 2.4.1.Final
              ataylor

              well that's an architectural choice for your application, just make sure you dont have the same thread accessing the same session at any one time.

              • 4. Re: Client Session concurrent usage in 2.4.1.Final
                yairogen

                I am sure it is a common problem? Is having hundreds or more instances of sessions, producers and consumers in a single process considered to be ok?

                • 5. Re: Client Session concurrent usage in 2.4.1.Final
                  ataylor

                  sessions are heavy weight objects so if you can use a single session with multiple producers/consumers then do that, if you are trying to maximize throughput then remember that if you create many sessions from the same connection factory then they will use the same underlying connection so you wouldnt see much advantage. as to how many connections/sessions you can create well this is dependent on your underlying resources, memory,sockets etc etc

                  • 6. Re: Client Session concurrent usage in 2.4.1.Final
                    yairogen

                    Assume I;m running in a Http Container. I am running with multiple threads by design. So - if my http server is configured with 4000 threads, I will probably hold 5000 sessions (from the same connection factory).

                     

                    Will this affect my application by Memory consumption only or in other ways as well?

                    • 7. Re: Client Session concurrent usage in 2.4.1.Final
                      ataylor

                      Assume I;m running in a Http Container. I am running with multiple threads by design. So - if my http server is configured with 4000 threads, I will probably hold 5000 sessions (from the same connection factory).

                      This is why Application Servers have connection pooling provided by JCA. you would need to add something similar. you probably need to provide something similar.

                      Will this affect my application by Memory consumption only or in other ways as well?

                      if its only 1 connection you are using then probably not altho there may be contention on the wire, if you are creating 5000 connections then these will have sockets open.