Friday, May 3, 2013

MDB throttling using Work Managers in Weblogic


A JMS Message Burst can result in a lot of threads created to process these messages. Because of this other applications/processes might not have threads to run or exhaust on data source connections etc..

One way to solve this is to use work Managers.
Work managers can be created globally or in the application scope.
1. Global Scoped Work Managers: These are accessible by every application running in the targeted server. These are created in the weblogic console
2. Application Scoped: These are defined in the application and are only available to the application.  They can be defined in weblogic-application.xml(the ear) or weblogic-ejb-jar.xml(module) or weblogic.xml(particular web application).

if you are defining in this in  weblogic-ejb-jar.xml
<weblogic-ejb-jar xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xsi:schemaLocation="http://www.bea.com/ns/weblogic/weblogic-ejb-jar/1.0/weblogic-ejb-jar.xsd"
                  xmlns="http://www.bea.com/ns/weblogic/weblogic-ejb-jar">
<weblogic-enterprise-bean>
<ejb-name>MyEJBBean</ejb-name>
  <message-driven-descriptor>
    <destination-jndi-name>jms/dq</destination-jndi-name>
    <connection-factory-jndi-name>jms/tqcf</connection-factory-jndi-name>
  </message-driven-descriptor>
  <dispatch-policy>WM1</dispatch-policy>
</weblogic-enterprise-bean>
<work-manager>
  <name>WM1</name>
  <min-threads-constraint>
    <name>wm2_mintc1</name>
    <count>0</count>
  </min-threads-constraint>
  <max-threads-constraint>
    <name>wm2_maxtc1</name>
    <count>3</count>
  </max-threads-constraint>
</work-manager>
</weblogic-ejb-jar>

You can also have the workmanager defined in the weblogic.xml or in weblogic-application.xml by having xml like this. and the MDB will refer the work manager in <dispatch-policy> tag.
work-manager>
  <name>WM1</name>
  <min-threads-constraint>
    <name>wm2_mintc1</name>
    <count>0</count>
  </min-threads-constraint>
  <max-threads-constraint>
    <name>wm2_maxtc1</name>
    <count>3</count>
  </max-threads-constraint>
</work-manager>

If you want to to define a global scoped work manager. You can do it in the weblogic console as below


image

If you want to throttle MDB threads by Database connection Pool Size. You can change the max constraint to have  pool-name tag instead of count tag. You fill the data source name here and not the jndi
work-manager>
  <name>WM1</name>
  <min-threads-constraint>
    <name>wm2_mintc1</name>
    <count>0</count>
  </min-threads-constraint>
  <max-threads-constraint>
    <name>wm2_maxtc1</name>
   <pool-name>OracleDS</pool-name>  </max-threads-constraint>
</work-manager>

9 comments:

  1. Dear Rohit,

    Nice post and very informative article for users like me as to how to configure Weblogic Work Manager.

    We are using Weblogic Server 12c

    Problem statement: Currently our application has 16 MDB threads to handle JMS requests. We need to increase it to 64 and 128 as performance needs.

    Kindly let me know if by just settting up Global Work Manager with Min and Max Thread constraint alone be sufficient to handle the above situation????

    Would this increased allotment of MDB threads be handled internally by Weblogic Global Work Manager??.

    Kindly let me know . Any help would be much appreciated.

    Thanks & Best Regards

    Harish

    ReplyDelete
  2. Hi Harish,

    Min and Max threads should be sufficient.
    But if you want to increase the threads to as high as 128 might want to watch out for availability of other resources like JDBC connections and any other resources used to process the messages.

    You can use a global work manager(I believe the server needs a restart for the change to work).

    Alternatively you can also use application level work managers. Min and Max too can be changed in the weblogic console application-> configuration->workload. After you save your configuration. You have to update your application in the "Deployments" page

    ReplyDelete
    Replies
    1. Hi Rohith,

      Thanks for your response. Much appreciated.

      The question I have now is that how do I validate through the Admin Console that after setting the Max thread Constraint value to say 64 or 128 for a Global Work Manager that the deployed app is really using that many threads to handle requests. As the purpose of increasing the thread count is to scale the application to handle more requests.

      Hope I am clear in my question. Thanks in Advance.

      Also as per WLS documentation that for configuring Application level Work Manager we have use weblogic-application.xml(the ear) or weblogic-ejb-jar.xml(module) or weblogic.xml(particular web application).

      And Admin console to select Work Manager and set constraints. You need both .Correct me if I am wrong.

      Reference: http://docs.oracle.com/cd/E24329_01/web.1211/e24432/self_tuned.htm#i1070661




      Best Regards

      Harish

      Delete
    2. 1. To monitor/validate, you can go to
      application - monitoring - workload
      in your weblogic console.


      2. Thats true, Application level Work Manager have to be in weblogic-application.xml. You can change the values in the admin console and update the application so it can take new values.


      Delete
    3. Thanks Rohith.

      I tried configuring application scoped Work Manager in weblogic-ejb-jar.xml as per your blog article above and it worked :-).

      Is there a way to know through admin console or through logs as to how many MDB threads are being currently used to handle requests?? This is when the application is running in say production.

      Best Regards

      Harish

      Delete
  3. Hi Rohith,

    We are currently conducting a performance testing and are using work managers for our MDBs. Following are the steps taken:

    1. Create a work manager through Environment > Work Managers
    2. Associate MaxThreadConstraint (250) and MinThreadConstraint (100) to the same.
    3. Update the weblogic-ejb-jar.xml of each of the MDBs by adding just the "dispatch-policy" element and redeploy.

    The thing is that when this was done, the thread count of none of the servers in the cluster went above 25 (defualt for Prod mode).

    Is the second "work-manager" element necessary in the weblogic-ejb-jar.xml file?

    Thanks,
    Vrushank

    ReplyDelete
  4. Hi Rohith,

    I have global workmanager defined in my weblogic console. I have set my max thread constarint to 4. Still the number of connections i snot getting rstricted. Am getting the below exception


    Any idea on the above error

    ReplyDelete
    Replies
    1. What error do you get?
      Did you also configure your application to use the workmanager defined in you weblogic?

      Delete
  5. Hi Rohith,

    we are getting unusual issue that we are able to increase max threads but rps is not increasing even though corresponding cpu is increasing.

    in summary increase mdb thread is increasing cpu but not increasing throughput.

    Could you please let us know what could be the issue?

    Following things already identified are non-issue:

    1. GC overhead
    2. DB
    3. DB/JDBC connection


    Regards,
    Shainesh

    ReplyDelete