4 Replies Latest reply on Feb 23, 2010 10:19 AM by mariqn nenchev

    Tracking total requests to servlet deployed in multiple jboss clusters

    mariqn nenchev Novice
      Hi,  I have web app with ejbs deployed as ear in 4 jboss clusters. My client wants the purchases for every x minutes (period) to be counted and if their count exceed the maximum count then every purchase has to go in the admin approval screen.  If the app was running in single web container i would put a static count in my servlet that is reinitialized to 0  at the end of every period(some timer), but i actually have 4 deployed servlets, one in every cluster. And i do not know how to count the total count of requests coming in every servlet. The other problem is if i use timer how could it be one for the four servlets. Any ideas how to implement this? Regars.
        • 1. Re: Tracking total requests to servlet deployed in multiple jboss clusters
          Francesco Marchioni Apprentice

          Hello,

          if I understand your requirements you can add a persistence layer to your web application ( Hibernate if you don't want/cannot use an EJB container)

          and store the amount of purchases there, which will be shared by the cluster.

          Alternatively, if you want to set up a timer cluster-aware to monitor the sales, this can be done as well:

          http://community.jboss.org/wiki/DeployingEJB3TimersInCluster

          Hope this helps

          Francesco

          JBossTutorials

          • 2. Re: Tracking total requests to servlet deployed in multiple jboss clusters
            mariqn nenchev Novice
            Hi, i do have persistence layer using JPA and i use ejbs for my business&persistence logic. The problem is that my client wants every purchase request to be under 100ms and i can't afford to hit the data base.
            • 3. Re: Tracking total requests to servlet deployed in multiple jboss clusters
              Francesco Marchioni Apprentice

              Hello,

              if you cannot afford hitting the DB, then you could use the HTTP Session to share the data across the cluster or, as an alternative, use an HA Singleton.

              Hope it helps.

              Francesco

              JBossTutorials

              • 4. Re: Tracking total requests to servlet deployed in multiple jboss clusters
                mariqn nenchev Novice
                Hi, i can't use HA singleton. And the  data is not only per user - i can't keep the trucking count in the user's session. I will try to explain more what i want to do: The app has a collection of assets that may be from 1 to n; A user can place a purchase over an asset. My client wants "the purchase" to become manual (manual means the purchase must be confirmed by the admin who i watching a screen of manual purchase and process them) if for the current period(this must be scheduled by single timer  in the cluster and on expire all counts will be reinitialized to 0): 1) the purchases for this asset are more than MAX_ASSET_PURCHASE_COUNT or if the sum of the purchases prices for the asset is more than MAX_ASSET_PURCHASES_PRICE. 2) the purchases for the user are more than MAX_USER_PURCHASE_COUNT(user specific) or if the sum of the purchases prices for the user is more than MAX_USER_PURCHASES_PRICE(user specific) 3) like 1) but not per asset and for all assets together. 4) like 2) but not per user and for all users together.  The idea for one timer that is scheduled only by one of the jboss instances is great, but i can't make it to work, every thing is fine but when i kill the first jboss instance the second does not start the timer bean and does not schedule the timer(but i can see that it is deployed).So assuming i can make this to work in some way. I will make a service method that starts this timer from the jmx-console.  I have external memcache that is visible from all instances. The purchases will be frequent like about 1000+ per minute. So i cant afford to update the memcache for every purchase. I was thinking about in memory cache for every jboss instance that tracks the counts and when the timer expires i get the counts from every inmemory cache and update the memcache and reinitialize the inmemory cache. The purchase servlet reads the memcache before purchase is done and decides over the above thresholds if the purchase has to go manual or not.  So, any ideas? :) Regards.