[jboss-svn-commits] JBL Code SVN: r29048 - in labs/jbosstm/trunk/ArjunaCore/arjuna/classes/com/arjuna/ats: internal/arjuna/coordinator and 1 other directory.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Tue Aug 25 09:12:17 EDT 2009
Author: jhalliday
Date: 2009-08-25 09:12:16 -0400 (Tue, 25 Aug 2009)
New Revision: 29048
Modified:
labs/jbosstm/trunk/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/coordinator/TransactionReaper.java
labs/jbosstm/trunk/ArjunaCore/arjuna/classes/com/arjuna/ats/internal/arjuna/coordinator/ReaperElement.java
Log:
Performance tuning of the transaction reaper. JBTM-611
Modified: labs/jbosstm/trunk/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/coordinator/TransactionReaper.java
===================================================================
--- labs/jbosstm/trunk/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/coordinator/TransactionReaper.java 2009-08-25 13:06:22 UTC (rev 29047)
+++ labs/jbosstm/trunk/ArjunaCore/arjuna/classes/com/arjuna/ats/arjuna/coordinator/TransactionReaper.java 2009-08-25 13:12:16 UTC (rev 29048)
@@ -153,7 +153,7 @@
try
{
final ReaperElement head = (ReaperElement) _transactions.first(); //_list.peak();
- return head._absoluteTimeout - System.currentTimeMillis();
+ return head.getAbsoluteTimeout() - System.currentTimeMillis();
}
catch (final NoSuchElementException nsee)
{
@@ -171,10 +171,10 @@
{
final ReaperElement head = (ReaperElement) _transactions.first(); //_list.peak();
if (head._status != ReaperElement.RUN) {
- long waitTime = head._absoluteTimeout - System.currentTimeMillis();
+ long waitTime = head.getAbsoluteTimeout() - System.currentTimeMillis();
if (waitTime < _checkPeriod)
{
- return head._absoluteTimeout - System.currentTimeMillis();
+ return head.getAbsoluteTimeout() - System.currentTimeMillis();
}
}
}
@@ -224,12 +224,12 @@
FacilityCode.FAC_ATOMIC_ACTION,
"com.arjuna.ats.arjuna.coordinator.TransactionReaper_2",
new Object[]
- { Long.toString(e._absoluteTimeout) });
+ { Long.toString(e.getAbsoluteTimeout()) });
}
final long now = System.currentTimeMillis();
- if (now < e._absoluteTimeout)
+ if (now < e.getAbsoluteTimeout())
{
// go back to sleep
@@ -268,8 +268,7 @@
{
_transactions.remove(e);
- e._absoluteTimeout =
- (System.currentTimeMillis() + _cancelWaitPeriod);
+ e.setAbsoluteTimeout((System.currentTimeMillis() + _cancelWaitPeriod));
_transactions.add(e);
}
@@ -311,8 +310,7 @@
{
_transactions.remove(e);
- e._absoluteTimeout =
- (System.currentTimeMillis() + _cancelWaitPeriod);
+ e.setAbsoluteTimeout((System.currentTimeMillis() + _cancelWaitPeriod));
_transactions.add(e);
}
@@ -343,8 +341,7 @@
{
_transactions.remove(e);
- e._absoluteTimeout =
- (System.currentTimeMillis() + _cancelFailWaitPeriod);
+ e.setAbsoluteTimeout((System.currentTimeMillis() + _cancelFailWaitPeriod));
_transactions.add(e);
}
@@ -788,7 +785,7 @@
* (This should never happen)
*/
if (_timeouts.containsKey(control)) {
- return false;
+ return false; // remove this, rewrite put instead.
}
ReaperElement e = new ReaperElement(control, timeout);
@@ -800,7 +797,7 @@
_timeouts.put(control, e);
boolean rtn = _transactions.add(e);
- if(_dynamic)
+ if(_dynamic && _transactions.first() == e)
{
notifyAll(); // force recalc of next wakeup time, taking into account the newly inserted element
}
@@ -893,7 +890,7 @@
else
{
// units are in milliseconds at this stage.
- timeout = reaperElement._absoluteTimeout - System.currentTimeMillis();
+ timeout = reaperElement.getAbsoluteTimeout() - System.currentTimeMillis();
}
if (tsLogger.arjLoggerI18N.isDebugEnabled()) {
@@ -991,7 +988,7 @@
{
e = (ReaperElement) iter.next();
- e._absoluteTimeout = 0;
+ e.setAbsoluteTimeout(0);
}
}
Modified: labs/jbosstm/trunk/ArjunaCore/arjuna/classes/com/arjuna/ats/internal/arjuna/coordinator/ReaperElement.java
===================================================================
--- labs/jbosstm/trunk/ArjunaCore/arjuna/classes/com/arjuna/ats/internal/arjuna/coordinator/ReaperElement.java 2009-08-25 13:06:22 UTC (rev 29047)
+++ labs/jbosstm/trunk/ArjunaCore/arjuna/classes/com/arjuna/ats/internal/arjuna/coordinator/ReaperElement.java 2009-08-25 13:12:16 UTC (rev 29048)
@@ -40,11 +40,11 @@
public class ReaperElement implements Comparable
{
- /*
- * Currently, once created the reaper object and thread stay around forever.
- * We could destroy both once the list of transactions is null. Depends upon
- * the relative cost of recreating them over keeping them around.
- */
+ /*
+ * Currently, once created the reaper object and thread stay around forever.
+ * We could destroy both once the list of transactions is null. Depends upon
+ * the relative cost of recreating them over keeping them around.
+ */
public ReaperElement(Reapable control, int timeout)
{
@@ -59,14 +59,18 @@
_control = control;
_timeout = timeout;
_status = RUN;
- _worker = null;
+ _worker = null;
/*
* Given a timeout period in seconds, calculate its absolute value from
* the current time of day in milliseconds.
*/
- _absoluteTimeout = timeout * 1000 + System.currentTimeMillis();
+ _absoluteTimeoutMills = (timeout * 1000) + System.currentTimeMillis();
+
+ // add additional variation to distinguish instances created in the same millisecond.
+ _bias = getBiasCounter();
+
}
public String toString ()
@@ -86,25 +90,45 @@
{
ReaperElement other = (ReaperElement)o;
- if(_absoluteTimeout == other._absoluteTimeout) {
- if(_control.get_uid().equals(other._control.get_uid())) {
- return 0;
- } else if (_control.get_uid().greaterThan(other._control.get_uid())) {
- return 1;
- } else {
- return -1;
- }
- } else {
- return (_absoluteTimeout > other._absoluteTimeout) ? 1 : -1;
- }
+ if(_absoluteTimeoutMills == other._absoluteTimeoutMills) {
+ if (_bias == other._bias) {
+ if(_control.get_uid().equals(other._control.get_uid())) {
+ return 0;
+ } else if (_control.get_uid().greaterThan(other._control.get_uid())) {
+ return 1;
+ } else {
+ return -1;
+ }
+ } else {
+ return (_bias > other._bias) ? 1 : -1;
+ }
+ } else {
+ return (_absoluteTimeoutMills > other._absoluteTimeoutMills) ? 1 : -1;
+ }
}
public Reapable _control;
- public long _absoluteTimeout;
+ private long _absoluteTimeoutMills;
+ private int _bias;
- public int _timeout;
+ // bias is used to distinguish/sort instances with the same _absoluteTimeoutMills
+ // as using Uid for this purpose is expensive. JBTM-611
+ private static int biasCounter = 0;
+
+ public static synchronized int getBiasCounter()
+ {
+ if(biasCounter >= 1000000-1) {
+ biasCounter = 0;
+ } else {
+ biasCounter++;
+ }
+ return biasCounter;
+ }
+
+ public int _timeout;
+
/*
* status field to track the progress of the reaper worker which is
* attempting to cancel the associated TX. this is necessary to ensure
@@ -248,4 +272,23 @@
return "UNKNOWN";
}
}
+
+ /**
+ * Returns absolute timeout in milliseconds
+ * @return
+ */
+ public long getAbsoluteTimeout()
+ {
+ return _absoluteTimeoutMills;
+ }
+
+ /**
+ * Sets the absolute timeout.
+ *
+ * @param absoluteTimeout value in milliseconds
+ */
+ public void setAbsoluteTimeout(long absoluteTimeout)
+ {
+ this._absoluteTimeoutMills = absoluteTimeout;
+ }
}
More information about the jboss-svn-commits
mailing list