You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by ea...@apache.org on 2008/07/22 22:01:36 UTC
svn commit: r678876 - in
/incubator/uima/sandbox/branches/uima-as-post1st/uimaj-as-core/src/main/java/org/apache/uima/aae:
controller/ handler/input/ jmx/
Author: eae
Date: Tue Jul 22 13:01:35 2008
New Revision: 678876
URL: http://svn.apache.org/viewvc?rev=678876&view=rev
Log:
UIMA-1104 Commit JC patch 12
Modified:
incubator/uima/sandbox/branches/uima-as-post1st/uimaj-as-core/src/main/java/org/apache/uima/aae/controller/AggregateAnalysisEngineController_impl.java
incubator/uima/sandbox/branches/uima-as-post1st/uimaj-as-core/src/main/java/org/apache/uima/aae/controller/AnalysisEngineController.java
incubator/uima/sandbox/branches/uima-as-post1st/uimaj-as-core/src/main/java/org/apache/uima/aae/controller/BaseAnalysisEngineController.java
incubator/uima/sandbox/branches/uima-as-post1st/uimaj-as-core/src/main/java/org/apache/uima/aae/controller/PrimitiveAnalysisEngineController_impl.java
incubator/uima/sandbox/branches/uima-as-post1st/uimaj-as-core/src/main/java/org/apache/uima/aae/handler/input/ProcessRequestHandler_impl.java
incubator/uima/sandbox/branches/uima-as-post1st/uimaj-as-core/src/main/java/org/apache/uima/aae/jmx/ServicePerformance.java
Modified: incubator/uima/sandbox/branches/uima-as-post1st/uimaj-as-core/src/main/java/org/apache/uima/aae/controller/AggregateAnalysisEngineController_impl.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/branches/uima-as-post1st/uimaj-as-core/src/main/java/org/apache/uima/aae/controller/AggregateAnalysisEngineController_impl.java?rev=678876&r1=678875&r2=678876&view=diff
==============================================================================
--- incubator/uima/sandbox/branches/uima-as-post1st/uimaj-as-core/src/main/java/org/apache/uima/aae/controller/AggregateAnalysisEngineController_impl.java (original)
+++ incubator/uima/sandbox/branches/uima-as-post1st/uimaj-as-core/src/main/java/org/apache/uima/aae/controller/AggregateAnalysisEngineController_impl.java Tue Jul 22 13:01:35 2008
@@ -119,10 +119,9 @@
private Object counterMonitor = new Object();
-// protected List childControllerList = new ArrayList();
- private List childControllerList = new ArrayList();
+ protected List childControllerList = new ArrayList();
+// private List childControllerList = new ArrayList();
-// protected Map delegateStats = new HashMap();
private Map delegateStats = new HashMap();
private AggregateServiceInfo serviceInfo = null;
Modified: incubator/uima/sandbox/branches/uima-as-post1st/uimaj-as-core/src/main/java/org/apache/uima/aae/controller/AnalysisEngineController.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/branches/uima-as-post1st/uimaj-as-core/src/main/java/org/apache/uima/aae/controller/AnalysisEngineController.java?rev=678876&r1=678875&r2=678876&view=diff
==============================================================================
--- incubator/uima/sandbox/branches/uima-as-post1st/uimaj-as-core/src/main/java/org/apache/uima/aae/controller/AnalysisEngineController.java (original)
+++ incubator/uima/sandbox/branches/uima-as-post1st/uimaj-as-core/src/main/java/org/apache/uima/aae/controller/AnalysisEngineController.java Tue Jul 22 13:01:35 2008
@@ -178,4 +178,11 @@
public long getIdleTimeBetweenProcessCalls(int msgType);
public long getCpuTime();
+
+ public long getAnalysisTime();
+
+ public void incrementSerializationTime(long cpuTime);
+
+ public void incrementDeserializationTime(long cpuTime);
+
}
Modified: incubator/uima/sandbox/branches/uima-as-post1st/uimaj-as-core/src/main/java/org/apache/uima/aae/controller/BaseAnalysisEngineController.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/branches/uima-as-post1st/uimaj-as-core/src/main/java/org/apache/uima/aae/controller/BaseAnalysisEngineController.java?rev=678876&r1=678875&r2=678876&view=diff
==============================================================================
--- incubator/uima/sandbox/branches/uima-as-post1st/uimaj-as-core/src/main/java/org/apache/uima/aae/controller/BaseAnalysisEngineController.java (original)
+++ incubator/uima/sandbox/branches/uima-as-post1st/uimaj-as-core/src/main/java/org/apache/uima/aae/controller/BaseAnalysisEngineController.java Tue Jul 22 13:01:35 2008
@@ -169,7 +169,7 @@
private long totalWaitTimeForCAS = 0;
private long lastCASWaitTimeUpdate = 0;
-
+
private Map<Long, AnalysisThreadState> threadStateMap =
new HashMap<Long,AnalysisThreadState>();
@@ -1781,8 +1781,6 @@
// This is called every time a request comes
public void beginProcess(int msgType )
{
-
-
// Disregard GetMeta as it comes on a non-process thread
if ( validMessageForSnapshot( msgType ) )
{
@@ -1800,7 +1798,7 @@
}
else
{
- threadStateMap.put(Thread.currentThread().getId(), new AnalysisThreadState());
+ threadStateMap.put(Thread.currentThread().getId(), new AnalysisThreadState(Thread.currentThread().getId()));
threadState = threadStateMap.get(Thread.currentThread().getId());
threadState.setIdle(false);
@@ -1819,23 +1817,11 @@
{
synchronized( mux )
{
- AnalysisThreadState threadState;
-
- if ( this instanceof AggregateAnalysisEngineController )
- {
- Set<Long> set = threadStateMap.keySet();
- Iterator<Long> it = set.iterator();
- threadState = threadStateMap.get(it.next());
- }
- else
- {
- threadState = threadStateMap.get(Thread.currentThread().getId());
- }
+ AnalysisThreadState threadState = getThreadState();
threadState.setLastUpdate(System.nanoTime());
threadState.setIdle(true);
threadState.setLastMessageDispatchTime();
}
-
}
}
public long getIdleTimeBetweenProcessCalls(int msgType)
@@ -1844,18 +1830,7 @@
{
synchronized( mux )
{
-
- AnalysisThreadState threadState = null;
- if ( threadStateMap.containsKey(Thread.currentThread().getId()))
- {
- threadState = threadStateMap.get(Thread.currentThread().getId());
- }
- else
- {
- Set<Long> set = threadStateMap.keySet();
- Iterator<Long> it = set.iterator();
- threadState = threadStateMap.get(it.next());
- }
+ AnalysisThreadState threadState = getThreadState();
return threadState.getIdleTimeBetweenProcessCalls();
}
}
@@ -1865,11 +1840,10 @@
{
synchronized( mux )
{
- int howManyThreads = 0;
long now = System.nanoTime();
long serviceIdleTime = 0;
Set<Long> set = threadStateMap.keySet();
- howManyThreads = threadStateMap.size();
+ int howManyThreads = threadStateMap.size();
// Iterate over all processing threads to calculate the total amount of idle time
for(Long key: set )
{
@@ -1928,21 +1902,166 @@
{
if ( ManagementFactory.getPlatformMBeanServer() != null )
{
- //ManagementFactory.getRuntimeMXBean().getVmVersion();
ThreadMXBean bean = ManagementFactory.getThreadMXBean( );
return bean.isCurrentThreadCpuTimeSupported( ) ? bean.getCurrentThreadCpuTime( ) : System.nanoTime();
}
return System.nanoTime();
}
+ private synchronized long getCpuTime(long threadId)
+ {
+ if ( ManagementFactory.getPlatformMBeanServer() != null )
+ {
+ ThreadMXBean bean = ManagementFactory.getThreadMXBean( );
+ return bean.isCurrentThreadCpuTimeSupported( ) ? bean.getThreadCpuTime(threadId): System.nanoTime();
+ }
+ return System.nanoTime();
+ }
+
+ private AnalysisThreadState getFirstThreadState()
+ {
+ Set<Long> set = threadStateMap.keySet();
+ Iterator<Long> it = set.iterator();
+ return threadStateMap.get(it.next());
+ }
+ /**
+ * Returns the {@link AnalysisThreadState} object associated with the current thread.
+ *
+ * @return
+ */
+ private AnalysisThreadState getThreadState()
+ {
+ AnalysisThreadState threadState;
+ if ( this instanceof AggregateAnalysisEngineController )
+ {
+ threadState = getFirstThreadState();
+ }
+ else
+ {
+ threadState = threadStateMap.get(Thread.currentThread().getId());
+ if ( threadState == null )
+ {
+ // This may be the case if the thread processing
+ // FreeCASRequest is returning an input CAS to the client.
+ // This thread is different from the process thread, thus
+ // we just return the first thread's state.
+ threadState = getFirstThreadState();
+ }
+ }
+ return threadState;
+ }
+
+ /**
+ * Returns the total CPU time all processing threads spent in analysis.
+ * This method subtracts the serialization and de-serialization time from
+ * the total. If this service is an aggregate, the return time is a sum
+ * of CPU utilization in each colocated delegate.
+ */
+ public long getAnalysisTime()
+ {
+ Set<Long> set = threadStateMap.keySet();
+ Iterator<Long> it = set.iterator();
+ long totalCpuProcessTime = 0;
+ // Iterate over all processing threads
+ while( it.hasNext())
+ {
+ long threadId = it.next();
+ synchronized( mux )
+ {
+ // Fetch the next thread's stats
+ AnalysisThreadState threadState = threadStateMap.get(threadId);
+ // If an Aggregate service, sum up the CPU times of all collocated
+ // delegates.
+ if ( this instanceof AggregateAnalysisEngineController_impl )
+ {
+ // Get a list of all colocated delegate controllers from the Aggregate
+ List<AnalysisEngineController> delegateControllerList =
+ ((AggregateAnalysisEngineController_impl)this).childControllerList;
+ // Iterate over all colocated delegates
+ for( int i=0; i < delegateControllerList.size(); i++)
+ {
+ // Get the next delegate's controller
+ AnalysisEngineController delegateController =
+ (AnalysisEngineController)delegateControllerList.get(i);
+ if ( delegateController != null && !delegateController.isStopped())
+ {
+ // get the CPU time for all processing threads in the current controller
+ totalCpuProcessTime += delegateController.getAnalysisTime();
+ }
+ }
+ }
+ else // Primitive Controller
+ {
+ // Get the CPU time of a thread with a given ID
+ totalCpuProcessTime += getCpuTime(threadId);
+ }
+ // Subtract serialization and deserialization times from the total CPU used
+ if ( totalCpuProcessTime > 0 )
+ {
+ totalCpuProcessTime -= threadState.getDeserializationTime();
+ totalCpuProcessTime -= threadState.getSerializationTime();
+ }
+ }
+ }
+ return totalCpuProcessTime;
+ }
+ /**
+ * Increments the time this thread spent in serialization of a CAS
+ */
+ public void incrementSerializationTime(long cpuTime)
+ {
+ synchronized( mux )
+ {
+ AnalysisThreadState threadState = getThreadState();
+ threadState.incrementSerializationTime(cpuTime);
+ }
+ }
+ /**
+ * Increments the time this thread spent in deserialization of a CAS
+ */
+ public void incrementDeserializationTime(long cpuTime)
+ {
+ synchronized( mux )
+ {
+ AnalysisThreadState threadState = getThreadState();
+ threadState.incrementDeserializationTime(cpuTime);
+ }
+ }
private class AnalysisThreadState
{
+ private long threadId;
+
private boolean isIdle = false;
private long lastUpdate = 0;
private long totalIdleTime = 0;
// Measures idle time between process CAS calls
private long idleTimeSinceLastProcess = 0;
private long lastMessageDispatchTime = 0;
+
+ private long serializationTime = 0;
+ private long deserializationTime = 0;
+
+ public AnalysisThreadState( long aThreadId )
+ {
+ threadId = aThreadId;
+ }
+
+ public long getThreadId()
+ {
+ return threadId;
+ }
+ public long getSerializationTime() {
+ return serializationTime;
+ }
+ public void incrementSerializationTime(long serializationTime) {
+ this.serializationTime += serializationTime;
+ }
+ public long getDeserializationTime() {
+ return deserializationTime;
+ }
+ public void incrementDeserializationTime(long deserializationTime) {
+ this.deserializationTime += deserializationTime;
+ }
public boolean isIdle() {
return isIdle;
}
Modified: incubator/uima/sandbox/branches/uima-as-post1st/uimaj-as-core/src/main/java/org/apache/uima/aae/controller/PrimitiveAnalysisEngineController_impl.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/branches/uima-as-post1st/uimaj-as-core/src/main/java/org/apache/uima/aae/controller/PrimitiveAnalysisEngineController_impl.java?rev=678876&r1=678875&r2=678876&view=diff
==============================================================================
--- incubator/uima/sandbox/branches/uima-as-post1st/uimaj-as-core/src/main/java/org/apache/uima/aae/controller/PrimitiveAnalysisEngineController_impl.java (original)
+++ incubator/uima/sandbox/branches/uima-as-post1st/uimaj-as-core/src/main/java/org/apache/uima/aae/controller/PrimitiveAnalysisEngineController_impl.java Tue Jul 22 13:01:35 2008
@@ -311,6 +311,7 @@
{
return;
}
+
boolean inputCASReturned = false;
boolean processingFailed = false;
// This is a primitive controller. No more processing is to be done on the Cas. Mark the destination as final and return CAS in reply.
@@ -343,7 +344,11 @@
long time = super.getCpuTime();
long totalProcessTime = 0; // stored total time spent producing ALL CASes
+
+// super.beginAnalysis();
CasIterator casIterator = ae.processAndOutputNewCASes(aCAS);
+// super.endAnalysis();
+
// Store how long it took to call processAndOutputNewCASes()
totalProcessTime = ( super.getCpuTime() - time);
long sequence = 1;
@@ -354,25 +359,21 @@
{
long timeToProcessCAS = 0; // stores time in hasNext() and next() for each CAS
hasNextTime = super.getCpuTime();
+// super.beginAnalysis();
if ( !casIterator.hasNext() )
{
moreCASesToProcess = false;
// Measure how long it took to call hasNext()
timeToProcessCAS = (super.getCpuTime()-hasNextTime);
totalProcessTime += timeToProcessCAS;
- break;
+// super.endAnalysis();
+ break; // from while
}
// Measure how long it took to call hasNext()
timeToProcessCAS = (super.getCpuTime()-hasNextTime);
getNextTime = super.getCpuTime();
-
- // Get the next CAS. Aggregate time spent waiting for the CAS
- //getServicePerformance().beginGetNextWait();
CAS casProduced = casIterator.next();
- //getServicePerformance().endGetNextWait();
-
- //long delta = super.getCpuTime() - getNextTime;
-
+// super.endAnalysis();
// Add how long it took to call next()
timeToProcessCAS += (super.getCpuTime()- getNextTime);
// Add time to call hasNext() and next() to the running total
@@ -445,7 +446,7 @@
// Store total time spent processing this input CAS
getCasStatistics(aCasReferenceId).incrementAnalysisTime(totalProcessTime);
// Aggregate total time spent processing in this service. This is separate from per CAS stats above
- getServicePerformance().incrementAnalysisTime(totalProcessTime);
+// getServicePerformance().incrementAnalysisTime(totalProcessTime);
synchronized( cmOutstandingCASes )
{
if ( cmOutstandingCASes.size() == 0)
Modified: incubator/uima/sandbox/branches/uima-as-post1st/uimaj-as-core/src/main/java/org/apache/uima/aae/handler/input/ProcessRequestHandler_impl.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/branches/uima-as-post1st/uimaj-as-core/src/main/java/org/apache/uima/aae/handler/input/ProcessRequestHandler_impl.java?rev=678876&r1=678875&r2=678876&view=diff
==============================================================================
--- incubator/uima/sandbox/branches/uima-as-post1st/uimaj-as-core/src/main/java/org/apache/uima/aae/handler/input/ProcessRequestHandler_impl.java (original)
+++ incubator/uima/sandbox/branches/uima-as-post1st/uimaj-as-core/src/main/java/org/apache/uima/aae/handler/input/ProcessRequestHandler_impl.java Tue Jul 22 13:01:35 2008
@@ -158,7 +158,7 @@
XmiSerializationSharedData deserSharedData = new XmiSerializationSharedData();
UimaSerializer.deserializeCasFromXmi(xmi, cas, deserSharedData, true, -1);
long timeToDeserializeCAS = getController().getCpuTime() - t1;
-
+ getController().incrementDeserializationTime(timeToDeserializeCAS);
LongNumericStatistic statistic;
if ( (statistic = getController().getMonitor().getLongNumericStatistic("",Monitor.TotalDeserializeTime)) != null )
{
Modified: incubator/uima/sandbox/branches/uima-as-post1st/uimaj-as-core/src/main/java/org/apache/uima/aae/jmx/ServicePerformance.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/branches/uima-as-post1st/uimaj-as-core/src/main/java/org/apache/uima/aae/jmx/ServicePerformance.java?rev=678876&r1=678875&r2=678876&view=diff
==============================================================================
--- incubator/uima/sandbox/branches/uima-as-post1st/uimaj-as-core/src/main/java/org/apache/uima/aae/jmx/ServicePerformance.java (original)
+++ incubator/uima/sandbox/branches/uima-as-post1st/uimaj-as-core/src/main/java/org/apache/uima/aae/jmx/ServicePerformance.java Tue Jul 22 13:01:35 2008
@@ -152,7 +152,22 @@
public double getAnalysisTime()
{
- return (double)analysisTime/(double)1000000;
+// return (double)analysisTime/(double)1000000;
+
+ if ( controller != null )
+ {
+ return ((double)controller.getAnalysisTime()/(double) 1000000);
+ }
+ else
+ {
+ synchronized( sem )
+ {
+ return (double)analysisTime/(double)1000000;
+ }
+
+ }
+
+
}
public long getRawAnalysisTime()