1 2 Previous Next 19 Replies Latest reply on Dec 16, 2005 1:07 PM by Adrian Brock

    Lock Contention on org.jboss.ejb.BeanLockManager

    Clebert Suconic Master

      As for http://jira.jboss.com/jira/browse/JBAS-2428 the contention happens when we have a huge number of threads accessing a single EJB (on my testcase a Stateful Session Bean).

      We are doing this tests in a huge hardware, and that's why we are being able to hit more than 800 threads in a single box. But for scaling more in a single CPU we need to solve that contention.

      I have tried to change the code a little bit, but we are seeing better responses but the contention still exists:

       - private Map map = Collections.synchronizedMap(new HashMap());
       + private HashMap map = new HashMap();
      
      
      
      
       public BeanLock getLock(Object id)
       {
       if (id == null)
       throw new IllegalArgumentException("Attempt to get lock ref with a null object");
       BeanLock lock = (BeanLock) map.get(id);
      
      
       if (lock == null)
       {
       // to guarantee atomicity we will redo the map.get
       synchronized (this)
       {
       lock = (BeanLock)map.get(id);
       if (lock==null)
       {
       try
       {
       lock = (BeanLock) lockClass.newInstance();
       lock.setId(id);
       lock.setTimeout(txTimeout);
       lock.setContainer(container);
       if( trace )
       log.trace("Created lock: "+lock);
       }
       catch (Exception e)
       {
       // schrouf: should we really proceed with lock object
       // in case of exception ??
       log.warn("Failed to initialize lock:"+lock, e);
       }
       map.put(id, lock);
       }
       }
      
       }
       synchronized (lock)
       {
       lock.addRef();
       }
       if( trace )
       log.trace("Added ref to lock: "+lock);
      
       return lock;
       }
      
      
      >> on removeLockREf:
      
       synchronized (lock)
       {
       lock.removeRef();
       }
      
      
      
      >> on canPassivate:
      
       synchronized (lock)
       {
       return (lock.getRefs() <= 1);
       }
      



      An option would be to have more than one BeanLockManager per container (using some sort of parameter, like scallingFactor) and divide the data

        1 2 Previous Next