changeset 937:7bcc6765c209

improved runtime statistics
author robcast
date Wed, 21 Dec 2011 19:18:16 +0100
parents 172079f9a398
children 0ba8358e2198
files common/src/main/java/digilib/io/DocuDirCache.java common/src/main/java/digilib/io/DocuDirectory.java servlet3/src/main/java/digilib/servlet/DigilibServletConfiguration.java servlet3/src/main/java/digilib/servlet/Initialiser.java webapp/src/main/webapp/server/dlConfig.jsp
diffstat 5 files changed, 47 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/common/src/main/java/digilib/io/DocuDirCache.java	Wed Dec 21 17:57:30 2011 +0100
+++ b/common/src/main/java/digilib/io/DocuDirCache.java	Wed Dec 21 19:18:16 2011 +0100
@@ -27,6 +27,7 @@
 import java.util.List;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.atomic.AtomicInteger;
 
 import org.apache.log4j.Logger;
 
@@ -51,13 +52,13 @@
 	private FileClass[] fileClasses = null;
 
 	/** number of files in the whole cache (approximate) */
-	long numFiles = 0;
+	protected AtomicInteger numImgFiles = new AtomicInteger(0);
 
 	/** number of cache hits */
-	long hits = 0;
+	protected AtomicInteger hits = new AtomicInteger(0);
 
 	/** number of cache misses */
-	long misses = 0;
+	protected AtomicInteger misses = new AtomicInteger(0);
 
 	/** the root directory element */
 	public static Directory ROOT = null;
@@ -111,7 +112,7 @@
 			logger.warn("Duplicate key in DocuDirCache.put -- ignoring!");
 			return olddir;
 		}
-		numFiles += newdir.size();
+		numImgFiles.addAndGet(newdir.size(FileClass.IMAGE));
 		return newdir;
 	}
 
@@ -193,7 +194,7 @@
 		dd = map.get(fn);
 		if (dd == null) {
 			// cache miss
-			misses++;
+			misses.incrementAndGet();
 			/*
 			 * see if fn is a directory
 			 */
@@ -228,14 +229,14 @@
 					}
 				} else {
 					// it was not a real cache miss
-					misses--;
+					misses.decrementAndGet();
 				}
 				// get the file's index
 				n = dd.indexOf(f.getName(), fc);
 			}
 		} else {
 			// cache hit
-			hits++;
+			hits.incrementAndGet();
 		}
 		dd.refresh();
 		if (dd.isValid()) {
@@ -263,7 +264,7 @@
 		dd = map.get(fn);
 		if (dd == null) {
 			// cache miss
-			misses++;
+			misses.incrementAndGet();
 			// see if it's a directory
 			File f = new File(baseDirNames[0], fn);
 			if (f.isDirectory()) {
@@ -289,7 +290,7 @@
 						}
 					} else {
 						// not a real cache miss then
-						misses--;
+						misses.decrementAndGet();
 					}
 				} else {
 					// it's not even a file :-(
@@ -298,7 +299,7 @@
 			}
 		} else {
 			// cache hit
-			hits++;
+			hits.incrementAndGet();
 		}
 		dd.refresh();
 		if (dd.isValid()) {
@@ -315,13 +316,6 @@
 	}
 
 	/**
-	 * @return long
-	 */
-	public long getNumFiles() {
-		return numFiles;
-	}
-
-	/**
 	 * Sets the baseDirNames.
 	 * 
 	 * @param baseDirNames
@@ -331,18 +325,25 @@
 		this.baseDirNames = baseDirNames;
 	}
 
+    /**
+     * @return long
+     */
+    public int getNumFiles() {
+        return numImgFiles.get();
+    }
+
 	/**
 	 * @return long
 	 */
-	public long getHits() {
-		return hits;
+	public int getHits() {
+		return hits.get();
 	}
 
 	/**
 	 * @return long
 	 */
-	public long getMisses() {
-		return misses;
+	public int getMisses() {
+		return misses.get();
 	}
 
 	/**
--- a/common/src/main/java/digilib/io/DocuDirectory.java	Wed Dec 21 17:57:30 2011 +0100
+++ b/common/src/main/java/digilib/io/DocuDirectory.java	Wed Dec 21 19:18:16 2011 +0100
@@ -228,7 +228,7 @@
 		}
 		// update number of cached files if this was the first time
 		if (dirMTime == 0) {
-			cache.numFiles += size();
+			cache.numImgFiles.addAndGet(size(FileClass.IMAGE));
 		}
 		dirMTime = dir.lastModified();
 		// read metadata as well
--- a/servlet3/src/main/java/digilib/servlet/DigilibServletConfiguration.java	Wed Dec 21 17:57:30 2011 +0100
+++ b/servlet3/src/main/java/digilib/servlet/DigilibServletConfiguration.java	Wed Dec 21 19:18:16 2011 +0100
@@ -51,6 +51,12 @@
  */
 public class DigilibServletConfiguration extends DigilibConfiguration {
 
+    /** time the webapp (i.e. this class) was loaded */
+    public final Long webappStartTime = System.currentTimeMillis();
+    
+    /** counter for HttpRequests (mostly for debugging) */
+    public AtomicInteger webappRequestCnt = new AtomicInteger(0);
+
     /** counter for open HttpRequests (mostly for debugging) */
     public AtomicInteger openRequestCnt = new AtomicInteger(0);
 
--- a/servlet3/src/main/java/digilib/servlet/Initialiser.java	Wed Dec 21 17:57:30 2011 +0100
+++ b/servlet3/src/main/java/digilib/servlet/Initialiser.java	Wed Dec 21 19:18:16 2011 +0100
@@ -212,6 +212,7 @@
 
     @Override
     public void requestInitialized(ServletRequestEvent arg0) {
+        dlConfig.webappRequestCnt.incrementAndGet();
         int i = dlConfig.openRequestCnt.incrementAndGet();
         logger.debug("ServletRequest created. (cnt="+i+")");
     }
--- a/webapp/src/main/webapp/server/dlConfig.jsp	Wed Dec 21 17:57:30 2011 +0100
+++ b/webapp/src/main/webapp/server/dlConfig.jsp	Wed Dec 21 19:18:16 2011 +0100
@@ -81,22 +81,35 @@
     <td>currently running</td><td><b><%= imageProcessor.getRunningJobs() %></b></td>
     <td></td>
   </tr>
+</table>
+
+<h2>Webapp</h2>
+
+<table>
   <tr>
     <td>currently open requests</td><td><b><%= dlConfig.openRequestCnt.get() %></b></td>
     <td>(including this)</td>
   </tr>
+  <tr>
+    <td>total requests</td><td><b><%= dlConfig.webappRequestCnt.get() %></b></td>
+    <td></td>
+  </tr>
+  <tr>
+    <td>total runtime </td><td><b><%= (System.currentTimeMillis() - dlConfig.webappStartTime)/1000 %></b></td>
+    <td>seconds</td>
+  </tr>
 </table>
 
 <h2>Directory cache</h2>
 
 <table>
   <tr>
-	<td>size (directories)</td><td><b><%= dirCache.size() %></b></td>
-    <td></td>
+	<td>size</td><td><b><%= dirCache.size() %></b></td>
+    <td>directories</td>
   </tr>
   <tr>
-	<td>numFiles</td><td><b><%= dirCache.getNumFiles() %></b></td>
-    <td></td>
+    <td></td><td><b><%= dirCache.getNumFiles() %></b></td>
+    <td>image files (approximately)</td>
   </tr>
   <tr>
 	<td>hits</td><td><b><%= dirCache.getHits() %></b></td>