Author: pferraro
Date: 2008-09-23 00:44:46 -0400 (Tue, 23 Sep 2008)
New Revision: 1883
Modified:
trunk/mod_cluster/src/demo/java/org/jboss/modcluster/demo/servlet/ActiveSessionsLoadServlet.java
trunk/mod_cluster/src/demo/java/org/jboss/modcluster/demo/servlet/BusyConnectorsLoadServlet.java
trunk/mod_cluster/src/demo/java/org/jboss/modcluster/demo/servlet/LoadServlet.java
trunk/mod_cluster/src/demo/java/org/jboss/modcluster/demo/servlet/ReceiveTrafficLoadServlet.java
trunk/mod_cluster/src/demo/java/org/jboss/modcluster/demo/servlet/RecordServlet.java
trunk/mod_cluster/src/demo/java/org/jboss/modcluster/demo/servlet/SendTrafficLoadServlet.java
trunk/mod_cluster/src/demo/java/org/jboss/modcluster/demo/servlet/SystemLoadServlet.java
Log:
improve load reliability
Modified:
trunk/mod_cluster/src/demo/java/org/jboss/modcluster/demo/servlet/ActiveSessionsLoadServlet.java
===================================================================
---
trunk/mod_cluster/src/demo/java/org/jboss/modcluster/demo/servlet/ActiveSessionsLoadServlet.java 2008-09-23
03:56:50 UTC (rev 1882)
+++
trunk/mod_cluster/src/demo/java/org/jboss/modcluster/demo/servlet/ActiveSessionsLoadServlet.java 2008-09-23
04:44:46 UTC (rev 1883)
@@ -58,11 +58,10 @@
{
int count = Integer.parseInt(this.getParameter(request, COUNT, "20"));
- HttpClient client = new HttpClient();
- HttpMethod method = new HeadMethod(this.createLocalURL(request, null));
-
for (int i = 0; i < count; ++i)
{
+ HttpClient client = new HttpClient();
+ HttpMethod method = new HeadMethod(this.createLocalURL(request, null));
client.executeMethod(method);
}
}
Modified:
trunk/mod_cluster/src/demo/java/org/jboss/modcluster/demo/servlet/BusyConnectorsLoadServlet.java
===================================================================
---
trunk/mod_cluster/src/demo/java/org/jboss/modcluster/demo/servlet/BusyConnectorsLoadServlet.java 2008-09-23
03:56:50 UTC (rev 1882)
+++
trunk/mod_cluster/src/demo/java/org/jboss/modcluster/demo/servlet/BusyConnectorsLoadServlet.java 2008-09-23
04:44:46 UTC (rev 1883)
@@ -30,7 +30,6 @@
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.HttpMethod;
-import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
import org.apache.commons.httpclient.methods.HeadMethod;
/**
@@ -59,9 +58,8 @@
long end = System.currentTimeMillis() + duration;
- HttpClient client = new HttpClient(new MultiThreadedHttpConnectionManager());
- HttpMethod method = new HeadMethod(this.createLocalURL(request,
Collections.singletonMap(END, String.valueOf(end))));
- Runnable task = new ExecuteMethodTask(client, method);
+ String url = this.createLocalURL(request, Collections.singletonMap(END,
String.valueOf(end)));
+ Runnable task = new ExecuteMethodTask(url);
int count = Integer.parseInt(this.getParameter(request, COUNT,
"50"));
@@ -83,20 +81,21 @@
private class ExecuteMethodTask implements Runnable
{
- private final HttpClient client;
- private final HttpMethod method;
+ private final String url;
- ExecuteMethodTask(HttpClient client, HttpMethod method)
+ ExecuteMethodTask(String url)
{
- this.client = client;
- this.method = method;
+ this.url = url;
}
public void run()
{
+ HttpClient client = new HttpClient();
+ HttpMethod method = new HeadMethod(this.url);
+
try
{
- this.client.executeMethod(this.method);
+ client.executeMethod(method);
}
catch (HttpException e)
{
Modified:
trunk/mod_cluster/src/demo/java/org/jboss/modcluster/demo/servlet/LoadServlet.java
===================================================================
---
trunk/mod_cluster/src/demo/java/org/jboss/modcluster/demo/servlet/LoadServlet.java 2008-09-23
03:56:50 UTC (rev 1882)
+++
trunk/mod_cluster/src/demo/java/org/jboss/modcluster/demo/servlet/LoadServlet.java 2008-09-23
04:44:46 UTC (rev 1883)
@@ -24,9 +24,14 @@
import java.util.Iterator;
import java.util.Map;
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
+import org.apache.catalina.ServerFactory;
+import org.apache.catalina.connector.Connector;
+
/**
* @author Paul Ferraro
*
@@ -40,6 +45,26 @@
protected static final String DEFAULT_DURATION = "15";
protected static final String COUNT = "count";
+ private static final String PORT = "port";
+
+ /**
+ * @{inheritDoc}
+ * @see javax.servlet.GenericServlet#init(javax.servlet.ServletConfig)
+ */
+ @Override
+ public void init(ServletConfig config) throws ServletException
+ {
+ super.init(config);
+
+ for (Connector connector:
ServerFactory.getServer().findServices()[0].findConnectors())
+ {
+ if (connector.getProtocol().startsWith("HTTP"))
+ {
+ config.getServletContext().setAttribute(PORT,
Integer.valueOf(connector.getPort()));
+ }
+ }
+ }
+
protected String createServerURL(HttpServletRequest request, Map<String, String>
parameterMap)
{
return this.createURL(request, request.getServerName(), request.getServerPort(),
parameterMap);
@@ -47,7 +72,8 @@
protected String createLocalURL(HttpServletRequest request, Map<String, String>
parameterMap)
{
- return this.createURL(request, request.getLocalName(), request.getLocalPort(),
parameterMap);
+ Integer port = (Integer) this.getServletContext().getAttribute(PORT);
+ return this.createURL(request, request.getLocalName(), (port != null) ?
port.intValue() : request.getLocalPort(), parameterMap);
}
private String createURL(HttpServletRequest request, String host, int port,
Map<String, String> parameterMap)
Modified:
trunk/mod_cluster/src/demo/java/org/jboss/modcluster/demo/servlet/ReceiveTrafficLoadServlet.java
===================================================================
---
trunk/mod_cluster/src/demo/java/org/jboss/modcluster/demo/servlet/ReceiveTrafficLoadServlet.java 2008-09-23
03:56:50 UTC (rev 1882)
+++
trunk/mod_cluster/src/demo/java/org/jboss/modcluster/demo/servlet/ReceiveTrafficLoadServlet.java 2008-09-23
04:44:46 UTC (rev 1883)
@@ -53,24 +53,29 @@
int size = Integer.parseInt(this.getParameter(request, SIZE, "100")) *
1000;
HttpClient client = new HttpClient();
- PutMethod method = new PutMethod(this.createLocalURL(request, null));
RequestEntity entity = new ByteArrayRequestEntity(new byte[size]);
- method.setRequestEntity(entity);
for (int i = 0; i < duration; ++i)
{
long start = System.currentTimeMillis();
+ PutMethod method = new PutMethod(this.createLocalURL(request, null));
+ method.setRequestEntity(entity);
client.executeMethod(method);
- try
+ long ms = 1000 - (System.currentTimeMillis() - start);
+
+ if (ms > 0)
{
- Thread.sleep(1000 - System.currentTimeMillis() - start);
+ try
+ {
+ Thread.sleep(ms);
+ }
+ catch (InterruptedException e)
+ {
+ Thread.currentThread().interrupt();
+ }
}
- catch (InterruptedException e)
- {
- Thread.currentThread().interrupt();
- }
}
}
}
Modified:
trunk/mod_cluster/src/demo/java/org/jboss/modcluster/demo/servlet/RecordServlet.java
===================================================================
---
trunk/mod_cluster/src/demo/java/org/jboss/modcluster/demo/servlet/RecordServlet.java 2008-09-23
03:56:50 UTC (rev 1882)
+++
trunk/mod_cluster/src/demo/java/org/jboss/modcluster/demo/servlet/RecordServlet.java 2008-09-23
04:44:46 UTC (rev 1883)
@@ -21,12 +21,16 @@
*/
package org.jboss.modcluster.demo.servlet;
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
-import org.jboss.modcluster.demo.client.RequestDriver;
+import org.apache.catalina.Engine;
+import org.apache.catalina.ServerFactory;
+import org.jboss.modcluster.demo.Constants;
/**
* @author Paul Ferraro
@@ -42,6 +46,19 @@
/**
* @{inheritDoc}
+ * @see javax.servlet.GenericServlet#init(javax.servlet.ServletConfig)
+ */
+ @Override
+ public void init(ServletConfig config) throws ServletException
+ {
+ super.init(config);
+
+ Engine engine = (Engine)
ServerFactory.getServer().findServices()[0].getContainer();
+ config.getServletContext().setAttribute("jvmRoute",
engine.getJvmRoute());
+ }
+
+ /**
+ * @{inheritDoc}
* @see javax.servlet.http.HttpServlet#service(javax.servlet.http.HttpServletRequest,
javax.servlet.http.HttpServletResponse)
*/
@Override
@@ -65,6 +82,6 @@
}
}
- response.setHeader(RequestDriver.NODE_HEADER, request.getLocalName());
+ response.setHeader(Constants.NODE_HEADER, (String)
this.getServletContext().getAttribute("jvmRoute"));
}
}
Modified:
trunk/mod_cluster/src/demo/java/org/jboss/modcluster/demo/servlet/SendTrafficLoadServlet.java
===================================================================
---
trunk/mod_cluster/src/demo/java/org/jboss/modcluster/demo/servlet/SendTrafficLoadServlet.java 2008-09-23
03:56:50 UTC (rev 1882)
+++
trunk/mod_cluster/src/demo/java/org/jboss/modcluster/demo/servlet/SendTrafficLoadServlet.java 2008-09-23
04:44:46 UTC (rev 1883)
@@ -52,6 +52,7 @@
int size = Integer.parseInt(request.getParameter(SIZE)) * 1000;
response.getOutputStream().write(new byte[size]);
+ response.flushBuffer();
}
/**
@@ -74,14 +75,19 @@
client.executeMethod(method);
- try
+ long ms = 1000 - (System.currentTimeMillis() - start);
+
+ if (ms > 0)
{
- Thread.sleep(1000 - System.currentTimeMillis() - start);
+ try
+ {
+ Thread.sleep(ms);
+ }
+ catch (InterruptedException e)
+ {
+ Thread.currentThread().interrupt();
+ }
}
- catch (InterruptedException e)
- {
- Thread.currentThread().interrupt();
- }
}
}
}
Modified:
trunk/mod_cluster/src/demo/java/org/jboss/modcluster/demo/servlet/SystemLoadServlet.java
===================================================================
---
trunk/mod_cluster/src/demo/java/org/jboss/modcluster/demo/servlet/SystemLoadServlet.java 2008-09-23
03:56:50 UTC (rev 1882)
+++
trunk/mod_cluster/src/demo/java/org/jboss/modcluster/demo/servlet/SystemLoadServlet.java 2008-09-23
04:44:46 UTC (rev 1883)
@@ -47,14 +47,17 @@
// Naughty loop
while (System.currentTimeMillis() - start < duration)
{
- try
+ if ((System.currentTimeMillis() % 10) == 0)
{
- Thread.sleep(1);
+ try
+ {
+ Thread.sleep(1);
+ }
+ catch (InterruptedException e)
+ {
+ break;
+ }
}
- catch (InterruptedException e)
- {
- break;
- }
}
}
}
\ No newline at end of file