From: Sasha Sherstnev Date: Tue, 24 Sep 2013 14:10:38 +0000 (+0100) Subject: Add measurement of execution time for servlets X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=b03d78f393289b6d54811023e851d13e650f4db3;p=jabaws.git Add measurement of execution time for servlets --- diff --git a/statpages/MonthlySummary.jsp b/statpages/MonthlySummary.jsp index ec06abf..ec99204 100644 --- a/statpages/MonthlySummary.jsp +++ b/statpages/MonthlySummary.jsp @@ -13,7 +13,15 @@ Date: May 2011
-

JABAWS Usage Statistics

+

JABAWS Usage Statistics. Time of execusion: ${timeexec} msec

+ + + diff --git a/statpages/ServicesStatus.jsp b/statpages/ServicesStatus.jsp index b3b60f0..bc1d873 100644 --- a/statpages/ServicesStatus.jsp +++ b/statpages/ServicesStatus.jsp @@ -18,12 +18,13 @@ TODO refactor

JABAWS Services Status


diff --git a/webservices/compbio/stat/collector/StatDB.java b/webservices/compbio/stat/collector/StatDB.java index 3af1b14..32b7fde 100644 --- a/webservices/compbio/stat/collector/StatDB.java +++ b/webservices/compbio/stat/collector/StatDB.java @@ -67,11 +67,6 @@ public class StatDB { conn = DriverManager.getConnection(protocol + statDBName + ";create=false"); conn.setAutoCommit(true); - /* - * Runtime.getRuntime().addShutdownHook(new Thread() { - * - * @Override public void run() { shutdownDBServer(); } }); - */ } catch (ClassNotFoundException e) { log.error(e.getMessage(), e); } @@ -111,11 +106,8 @@ public class StatDB { * @throws SQLException */ private void createStatTable() throws SQLException { - - /* - * Creating a statement object that we can use for running various SQL - * statements commands against the database. - */ + // Creating a statement object that we can use for running various SQL + // statements commands against the database. Statement s = conn.createStatement(); String create = "create table exec_stat(" + "number INT GENERATED ALWAYS AS IDENTITY," @@ -199,7 +191,6 @@ public class StatDB { if (exist) { date = res.getDate(1); } - res.close(); st.close(); return date; diff --git a/webservices/compbio/stat/servlet/AnnualStat.java b/webservices/compbio/stat/servlet/AnnualStat.java index 3ec55ce..26150de 100644 --- a/webservices/compbio/stat/servlet/AnnualStat.java +++ b/webservices/compbio/stat/servlet/AnnualStat.java @@ -40,6 +40,7 @@ public class AnnualStat extends HttpServlet { throws ServletException, IOException { try { + long startTime = System.nanoTime(); StatDB db = new StatDB(); Date earliestRec = db.getEarliestRecord(); if (earliestRec == null) { @@ -50,13 +51,13 @@ public class AnnualStat extends HttpServlet { writer.close(); return; } - Map monthlyTotals = StatCollection - .getStats(earliestRec); + Map monthlyTotals = StatCollection.getStats(earliestRec); + long endTime = System.nanoTime(); req.setAttribute("stat", monthlyTotals); req.setAttribute("total", Totals.sumOfTotals(monthlyTotals)); + req.setAttribute("timeexec", (endTime - startTime) / 1000000); - RequestDispatcher dispatcher = req - .getRequestDispatcher("statpages/MonthlySummary.jsp"); + RequestDispatcher dispatcher = req.getRequestDispatcher("statpages/MonthlySummary.jsp"); req.setAttribute("isAdmin", isAdmin(req)); dispatcher.forward(req, resp); diff --git a/webservices/compbio/stat/servlet/ServiceStatus.java b/webservices/compbio/stat/servlet/ServiceStatus.java index c31f15d..a0f5516 100644 --- a/webservices/compbio/stat/servlet/ServiceStatus.java +++ b/webservices/compbio/stat/servlet/ServiceStatus.java @@ -5,15 +5,18 @@ import java.io.PrintWriter; import java.io.StringWriter; import java.util.ArrayList; import java.util.List; +import java.util.Collections; import javax.servlet.RequestDispatcher; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import javax.servlet.ServletContext; import org.apache.log4j.Logger; +import compbio.stat.servlet.util.Totals; import compbio.ws.client.Services; import compbio.ws.client.WSTester; @@ -30,20 +33,64 @@ public class ServiceStatus extends HttpServlet { private final static Logger log = Logger.getLogger(ServiceStatus.class); + + private static String getURL(HttpServletRequest req) { + String scheme = req.getScheme(); // http + String serverName = req.getServerName(); // hostname.com + int serverPort = req.getServerPort(); // 80 + String contextPath = req.getContextPath(); // /mywebapp + String servletPath = req.getServletPath(); // /servlet/MyServlet + String pathInfo = req.getPathInfo(); // /a/b;c=123 + String queryString = req.getQueryString(); // d=789 + + // Reconstruct original requesting URL + StringBuffer url = new StringBuffer(); + url.append(scheme).append("://").append(serverName); + + if ((serverPort != 80) && (serverPort != 443)) { + url.append(":").append(serverPort); + } + + url.append(contextPath).append(servletPath); + + if (pathInfo != null) { + url.append(pathInfo); + } + if (queryString != null) { + url.append("?").append(queryString); + } + return url.toString(); + } + @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { StringBuffer jabawspath = req.getRequestURL(); jabawspath = jabawspath.delete(jabawspath.lastIndexOf("/"), jabawspath.length()); String serverPath = jabawspath.toString(); - System.out.println("Testing services at " + serverPath); +/** + String host = java.net.InetAddress.getLocalHost().getCanonicalHostName(); + System.out.println("Testing services at " + req.getRequestURL()); + System.out.println("Really: Testing services at " + serverPath); + System.out.println(" serverPath2 is " + getURL(req)); System.out.println(" Context Path is " + req.getContextPath()); + System.out.println(" Host is " + host); System.out.println(" Request URI is " + req.getRequestURI()); System.out.println(" Servlet Path is " + req.getServletPath()); System.out.println(" Path Info is " + req.getPathInfo()); - + System.out.println(" Local Port is " + req.getLocalPort()); + System.out.println(" Remote Port is " + req.getRemotePort()); + System.out.println(" Local address is " + req.getLocalAddr()); + System.out.println(" Remote address is " + req.getRemoteAddr()); + @SuppressWarnings("unchecked") + List list = Collections.list(req.getHeaderNames()); + System.out.println(" HTTP header names are " + list.toString()); + for (String hdr : list) { + System.out.println(" " + hdr + " header is " + req.getHeader(hdr)); + } +*/ List testResults = new ArrayList(); - + long startTime = System.nanoTime(); for (Services service : Services.values()) { StringWriter testres = new StringWriter(); PrintWriter writer = new PrintWriter(testres, true); @@ -63,6 +110,8 @@ public class ServiceStatus extends HttpServlet { testResults.add(result); } req.setAttribute("results", testResults); + long endTime = System.nanoTime(); + req.setAttribute("timeexec", (endTime - startTime) / 1000000); RequestDispatcher rd = req.getRequestDispatcher("statpages/ServicesStatus.jsp"); rd.forward(req, resp); }