incubator-esme-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r787397 - /incubator/esme/trunk/server/src/main/scala/bootstrap/liftweb/Boot.scala
Date Mon, 22 Jun 2009 20:57:48 GMT
Author: dpp
Date: Mon Jun 22 20:57:48 2009
New Revision: 787397

URL: http://svn.apache.org/viewvc?rev=787397&view=rev
Log:
Print memory usage every 10 minutes

Modified:
    incubator/esme/trunk/server/src/main/scala/bootstrap/liftweb/Boot.scala

Modified: incubator/esme/trunk/server/src/main/scala/bootstrap/liftweb/Boot.scala
URL: http://svn.apache.org/viewvc/incubator/esme/trunk/server/src/main/scala/bootstrap/liftweb/Boot.scala?rev=787397&r1=787396&r2=787397&view=diff
==============================================================================
--- incubator/esme/trunk/server/src/main/scala/bootstrap/liftweb/Boot.scala (original)
+++ incubator/esme/trunk/server/src/main/scala/bootstrap/liftweb/Boot.scala Mon Jun 22 20:57:48
2009
@@ -41,6 +41,8 @@
 import javax.servlet.http.{HttpServlet, HttpServletRequest , HttpServletResponse, HttpSession}
 import org.compass.core._
 import org.compass.core.config.CompassConfiguration
+import scala.actors.Actor
+import Actor._
 
 /**
  * A class that's instantiated early and run.  It allows the application
@@ -160,6 +162,9 @@
      */
     LiftRules.ajaxEnd =
     Full(() => LiftRules.jsArtifacts.hide("ajax-loader").cmd)
+
+        // Dump information about session every 10 minutes
+    SessionMaster.sessionWatchers = SessionInfoDumper :: SessionMaster.sessionWatchers
   }
   private def makeUtf8(req: HttpServletRequest): Unit = {req.setCharacterEncoding("UTF-8")}
 }
@@ -250,3 +255,32 @@
   }
 }
 
+object SessionInfoDumper extends Actor {
+  private var lastTime = millis
+
+  val tenMinutes: Long = 10 minutes
+  def act = {
+    link(ActorWatcher)
+    loop {
+      react {
+        case SessionWatcherInfo(sessions) =>
+          if ((millis - tenMinutes) > lastTime) {
+            lastTime = millis
+            val rt = Runtime.getRuntime
+            rt.gc
+
+            val dateStr: String = timeNow.toString
+            Log.info("[MEMDEBUG] At "+dateStr+" Number of open sessions: "+sessions.size)
+            Log.info("[MEMDEBUG] Free Memory: "+pretty(rt.freeMemory))
+            Log.info("[MEMDEBUG] Total Memory: "+pretty(rt.totalMemory))
+          }
+      }
+    }
+  }
+
+  private def pretty(in: Long): String =
+  if (in > 1000L) pretty(in / 1000L)+","+(in % 1000L)
+  else in.toString
+
+  this.start
+}



Mime
View raw message