Author: pferraro
Date: 2008-09-22 00:06:24 -0400 (Mon, 22 Sep 2008)
New Revision: 1876
Added:
trunk/mod_cluster/src/demo/java/org/jboss/modcluster/demo/servlet/
trunk/mod_cluster/src/demo/java/org/jboss/modcluster/demo/servlet/ActiveSessionsLoadServlet.java
trunk/mod_cluster/src/demo/java/org/jboss/modcluster/demo/servlet/BusyConnectorsServlet.java
trunk/mod_cluster/src/demo/java/org/jboss/modcluster/demo/servlet/ConnectionPoolLoadServlet.java
trunk/mod_cluster/src/demo/java/org/jboss/modcluster/demo/servlet/HeapMemoryLoadServlet.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/RequestCountLoadServlet.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
trunk/mod_cluster/src/demo/java/org/jboss/modcluster/demo/servlet/ThreadCountLoadServlet.java
Log:
Servlets per load metric.
Added:
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
(rev 0)
+++
trunk/mod_cluster/src/demo/java/org/jboss/modcluster/demo/servlet/ActiveSessionsLoadServlet.java 2008-09-22
04:06:24 UTC (rev 1876)
@@ -0,0 +1,69 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.modcluster.demo.servlet;
+
+import java.io.IOException;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpMethod;
+import org.apache.commons.httpclient.methods.HeadMethod;
+
+/**
+ * @author Paul Ferraro
+ *
+ */
+public class ActiveSessionsLoadServlet extends LoadServlet
+{
+ /** The serialVersionUID */
+ private static final long serialVersionUID = -946741803216943778L;
+
+ /**
+ * @{inheritDoc}
+ * @see javax.servlet.http.HttpServlet#doHead(javax.servlet.http.HttpServletRequest,
javax.servlet.http.HttpServletResponse)
+ */
+ @Override
+ protected void doHead(HttpServletRequest request, HttpServletResponse response)
+ {
+ request.getSession(true);
+ }
+
+ /**
+ * @{inheritDoc}
+ * @see javax.servlet.http.HttpServlet#service(javax.servlet.http.HttpServletRequest,
javax.servlet.http.HttpServletResponse)
+ */
+ @Override
+ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws
IOException
+ {
+ 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)
+ {
+ client.executeMethod(method);
+ }
+ }
+}
Added:
trunk/mod_cluster/src/demo/java/org/jboss/modcluster/demo/servlet/BusyConnectorsServlet.java
===================================================================
---
trunk/mod_cluster/src/demo/java/org/jboss/modcluster/demo/servlet/BusyConnectorsServlet.java
(rev 0)
+++
trunk/mod_cluster/src/demo/java/org/jboss/modcluster/demo/servlet/BusyConnectorsServlet.java 2008-09-22
04:06:24 UTC (rev 1876)
@@ -0,0 +1,111 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.modcluster.demo.servlet;
+
+import java.io.IOException;
+import java.util.Collections;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+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;
+
+/**
+ * @author Paul Ferraro
+ *
+ */
+public class BusyConnectorsServlet extends LoadServlet
+{
+ /** The serialVersionUID */
+ private static final long serialVersionUID = -946741803216943778L;
+
+ private static final String END = "end";
+
+ /**
+ * @{inheritDoc}
+ * @see javax.servlet.http.HttpServlet#service(javax.servlet.http.HttpServletRequest,
javax.servlet.http.HttpServletResponse)
+ */
+ @Override
+ protected void service(HttpServletRequest request, HttpServletResponse response)
throws IOException
+ {
+ String parameter = request.getParameter(END);
+
+ if (parameter == null)
+ {
+ int duration = Integer.parseInt(this.getParameter(request, DURATION,
"15")) * 1000;
+
+ 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);
+
+ int count = Integer.parseInt(this.getParameter(request, COUNT,
"50"));
+
+ for (int i = 0; i < count; ++i)
+ {
+ new Thread(task).start();
+ }
+ }
+ else
+ {
+ long end = Long.parseLong(parameter);
+
+ if (end < System.currentTimeMillis())
+ {
+ response.sendRedirect(response.encodeRedirectURL(this.createLocalURL(request,
Collections.singletonMap(END, String.valueOf(end)))));
+ }
+ }
+ }
+
+ private class ExecuteMethodTask implements Runnable
+ {
+ private final HttpClient client;
+ private final HttpMethod method;
+
+ ExecuteMethodTask(HttpClient client, HttpMethod method)
+ {
+ this.client = client;
+ this.method = method;
+ }
+
+ public void run()
+ {
+ try
+ {
+ this.client.executeMethod(this.method);
+ }
+ catch (HttpException e)
+ {
+ BusyConnectorsServlet.this.log(e.getMessage(), e);
+ }
+ catch (IOException e)
+ {
+ BusyConnectorsServlet.this.log(e.getMessage(), e);
+ }
+ }
+ }
+}
Added:
trunk/mod_cluster/src/demo/java/org/jboss/modcluster/demo/servlet/ConnectionPoolLoadServlet.java
===================================================================
---
trunk/mod_cluster/src/demo/java/org/jboss/modcluster/demo/servlet/ConnectionPoolLoadServlet.java
(rev 0)
+++
trunk/mod_cluster/src/demo/java/org/jboss/modcluster/demo/servlet/ConnectionPoolLoadServlet.java 2008-09-22
04:06:24 UTC (rev 1876)
@@ -0,0 +1,105 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.modcluster.demo.servlet;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.sql.DataSource;
+
+/**
+ * @author Paul Ferraro
+ *
+ */
+public class ConnectionPoolLoadServlet extends LoadServlet
+{
+ /** The serialVersionUID */
+ private static final long serialVersionUID = -7183638924988586271L;
+ private static final String DATASOURCE = "datasource";
+ private static final String USER = "user";
+ private static final String PASSWORD = "password";
+
+ /**
+ * @{inheritDoc}
+ * @see javax.servlet.http.HttpServlet#service(javax.servlet.http.HttpServletRequest,
javax.servlet.http.HttpServletResponse)
+ */
+ @Override
+ protected void service(HttpServletRequest request, HttpServletResponse response)
+ {
+ String name = this.getParameter(request, DATASOURCE, "java:/DefaultDS");
+
+ int count = Integer.parseInt(this.getParameter(request, COUNT, "20"));
+ int duration = Integer.parseInt(this.getParameter(request, DURATION,
DEFAULT_DURATION)) * 1000;
+
+ try
+ {
+ DataSource dataSource = (DataSource) new InitialContext().lookup(name);
+
+ String user = this.getParameter(request, USER, null);
+ String password = this.getParameter(request, PASSWORD, null);
+
+ List<Connection> connections = new ArrayList<Connection>(count);
+
+ try
+ {
+ for (int i = 0; i < count; ++i)
+ {
+ connections.add((user != null) ? dataSource.getConnection(user, password)
: dataSource.getConnection());
+ }
+
+ Thread.sleep(duration);
+ }
+ catch (InterruptedException e)
+ {
+ Thread.currentThread().interrupt();
+ }
+ finally
+ {
+ for (Connection connection: connections)
+ {
+ try
+ {
+ connection.close();
+ }
+ catch (SQLException e)
+ {
+ this.log(e.getMessage(), e);
+ }
+ }
+ }
+ }
+ catch (NamingException e)
+ {
+ this.log(e.getMessage(), e);
+ }
+ catch (SQLException e)
+ {
+ this.log(e.getMessage(), e);
+ }
+ }
+}
Added:
trunk/mod_cluster/src/demo/java/org/jboss/modcluster/demo/servlet/HeapMemoryLoadServlet.java
===================================================================
---
trunk/mod_cluster/src/demo/java/org/jboss/modcluster/demo/servlet/HeapMemoryLoadServlet.java
(rev 0)
+++
trunk/mod_cluster/src/demo/java/org/jboss/modcluster/demo/servlet/HeapMemoryLoadServlet.java 2008-09-22
04:06:24 UTC (rev 1876)
@@ -0,0 +1,63 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.modcluster.demo.servlet;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * @author Paul Ferraro
+ *
+ */
+public class HeapMemoryLoadServlet extends LoadServlet
+{
+ /** The serialVersionUID */
+ private static final long serialVersionUID = -8183119455180366670L;
+
+ /**
+ * @{inheritDoc}
+ * @see javax.servlet.http.HttpServlet#service(javax.servlet.http.HttpServletRequest,
javax.servlet.http.HttpServletResponse)
+ */
+ @Override
+ protected void service(HttpServletRequest request, HttpServletResponse response)
+ {
+ int duration = Integer.parseInt(this.getParameter(request, DURATION,
DEFAULT_DURATION));
+
+ long free = Runtime.getRuntime().freeMemory();
+
+ @SuppressWarnings("unused")
+ Object array = (free > Integer.MAX_VALUE) ? new byte[Integer.MAX_VALUE][(int)
free / Integer.MAX_VALUE] : new byte[(int) free];
+
+ try
+ {
+ Thread.sleep(duration);
+ }
+ catch (InterruptedException e)
+ {
+ Thread.currentThread().interrupt();
+ }
+
+ array = null;
+
+ System.gc();
+ }
+}
Added: 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
(rev 0)
+++
trunk/mod_cluster/src/demo/java/org/jboss/modcluster/demo/servlet/LoadServlet.java 2008-09-22
04:06:24 UTC (rev 1876)
@@ -0,0 +1,99 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.modcluster.demo.servlet;
+
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+
+/**
+ * @author Paul Ferraro
+ *
+ */
+public class LoadServlet extends HttpServlet
+{
+ /** The serialVersionUID */
+ private static final long serialVersionUID = 5665079393261425098L;
+
+ protected static final String DURATION = "duration";
+ protected static final String DEFAULT_DURATION = "15";
+ protected static final String COUNT = "count";
+
+ protected String createServerURL(HttpServletRequest request, Map<String, String>
parameterMap)
+ {
+ return this.createURL(request, request.getServerName(), request.getServerPort(),
parameterMap);
+ }
+
+ protected String createLocalURL(HttpServletRequest request, Map<String, String>
parameterMap)
+ {
+ return this.createURL(request, request.getLocalName(), request.getLocalPort(),
parameterMap);
+ }
+
+ private String createURL(HttpServletRequest request, String host, int port,
Map<String, String> parameterMap)
+ {
+ StringBuilder builder = new StringBuilder();
+
+ builder.append(request.getScheme()).append("://");
+ builder.append(host).append(':').append(port);
+ builder.append(request.getContextPath()).append(request.getServletPath());
+
+ if ((parameterMap != null) && !parameterMap.isEmpty())
+ {
+ builder.append("?");
+
+ Iterator<Map.Entry<String, String>> entries =
parameterMap.entrySet().iterator();
+
+ while (entries.hasNext())
+ {
+ Map.Entry<String, String> entry = entries.next();
+
+ builder.append(entry.getKey()).append('=').append(entry.getValue());
+
+ if (entries.hasNext())
+ {
+ builder.append('&');
+ }
+ }
+ }
+
+ return builder.toString();
+ }
+
+ protected String getParameter(HttpServletRequest request, String name, String
defaultValue)
+ {
+ String value = request.getParameter(name);
+
+ if (value == null)
+ {
+ value = this.getInitParameter(name);
+ }
+
+ if (value == null)
+ {
+ value = this.getServletContext().getInitParameter(name);
+ }
+
+ return (value != null) ? value : defaultValue;
+ }
+}
Added:
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
(rev 0)
+++
trunk/mod_cluster/src/demo/java/org/jboss/modcluster/demo/servlet/ReceiveTrafficLoadServlet.java 2008-09-22
04:06:24 UTC (rev 1876)
@@ -0,0 +1,76 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.modcluster.demo.servlet;
+
+import java.io.IOException;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.methods.ByteArrayRequestEntity;
+import org.apache.commons.httpclient.methods.PutMethod;
+import org.apache.commons.httpclient.methods.RequestEntity;
+
+/**
+ * @author Paul Ferraro
+ *
+ */
+public class ReceiveTrafficLoadServlet extends LoadServlet
+{
+ /** The serialVersionUID */
+ private static final long serialVersionUID = 2344830128026153418L;
+ private static final String SIZE = "size";
+
+ /**
+ * @{inheritDoc}
+ * @see javax.servlet.http.HttpServlet#service(javax.servlet.http.HttpServletRequest,
javax.servlet.http.HttpServletResponse)
+ */
+ @Override
+ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws
IOException
+ {
+ int duration = Integer.parseInt(this.getParameter(request, DURATION,
DEFAULT_DURATION));
+
+ 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();
+
+ client.executeMethod(method);
+
+ try
+ {
+ Thread.sleep(1000 - System.currentTimeMillis() - start);
+ }
+ catch (InterruptedException e)
+ {
+ Thread.currentThread().interrupt();
+ }
+ }
+ }
+}
Added:
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
(rev 0)
+++
trunk/mod_cluster/src/demo/java/org/jboss/modcluster/demo/servlet/RecordServlet.java 2008-09-22
04:06:24 UTC (rev 1876)
@@ -0,0 +1,51 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.modcluster.demo.servlet;
+
+import java.io.IOException;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.jboss.modcluster.demo.client.RequestDriver;
+
+/**
+ * @author Paul Ferraro
+ *
+ */
+public class RecordServlet extends HttpServlet
+{
+ /** The serialVersionUID */
+ private static final long serialVersionUID = -4143320241936636855L;
+
+ /**
+ * @{inheritDoc}
+ * @see javax.servlet.http.HttpServlet#service(javax.servlet.http.HttpServletRequest,
javax.servlet.http.HttpServletResponse)
+ */
+ @Override
+ protected void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
+ {
+ response.setHeader(RequestDriver.NODE_HEADER, request.getLocalName());
+ }
+}
Added:
trunk/mod_cluster/src/demo/java/org/jboss/modcluster/demo/servlet/RequestCountLoadServlet.java
===================================================================
---
trunk/mod_cluster/src/demo/java/org/jboss/modcluster/demo/servlet/RequestCountLoadServlet.java
(rev 0)
+++
trunk/mod_cluster/src/demo/java/org/jboss/modcluster/demo/servlet/RequestCountLoadServlet.java 2008-09-22
04:06:24 UTC (rev 1876)
@@ -0,0 +1,53 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.modcluster.demo.servlet;
+
+import java.io.IOException;
+import java.util.Collections;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * @author Paul Ferraro
+ *
+ */
+public class RequestCountLoadServlet extends LoadServlet
+{
+ /** The serialVersionUID */
+ private static final long serialVersionUID = -5001091954463802789L;
+
+ /**
+ * @{inheritDoc}
+ * @see javax.servlet.http.HttpServlet#service(javax.servlet.http.HttpServletRequest,
javax.servlet.http.HttpServletResponse)
+ */
+ @Override
+ protected void service(HttpServletRequest request, HttpServletResponse response)
throws IOException
+ {
+ int count = Integer.parseInt(this.getParameter(request, COUNT, "50"));
+
+ if (count > 1)
+ {
+ response.sendRedirect(this.createLocalURL(request,
Collections.singletonMap(COUNT, String.valueOf(count - 1))));
+ }
+ }
+}
Added:
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
(rev 0)
+++
trunk/mod_cluster/src/demo/java/org/jboss/modcluster/demo/servlet/SendTrafficLoadServlet.java 2008-09-22
04:06:24 UTC (rev 1876)
@@ -0,0 +1,87 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.modcluster.demo.servlet;
+
+import java.io.IOException;
+import java.util.Collections;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpMethod;
+import org.apache.commons.httpclient.methods.PostMethod;
+
+/**
+ * @author Paul Ferraro
+ *
+ */
+public class SendTrafficLoadServlet extends LoadServlet
+{
+ /** The serialVersionUID */
+ private static final long serialVersionUID = -8586013739155819909L;
+ private static final String SIZE = "size";
+
+ /**
+ * @{inheritDoc}
+ * @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest,
javax.servlet.http.HttpServletResponse)
+ */
+ @Override
+ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException
+ {
+ int size = Integer.parseInt(request.getParameter(SIZE)) * 1000;
+
+ response.getOutputStream().write(new byte[size]);
+ }
+
+ /**
+ * @{inheritDoc}
+ * @see javax.servlet.http.HttpServlet#service(javax.servlet.http.HttpServletRequest,
javax.servlet.http.HttpServletResponse)
+ */
+ @Override
+ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws
IOException
+ {
+ int duration = Integer.parseInt(this.getParameter(request, DURATION,
DEFAULT_DURATION));
+
+ String size = this.getParameter(request, SIZE, "100");
+
+ HttpClient client = new HttpClient();
+ HttpMethod method = new PostMethod(this.createLocalURL(request,
Collections.singletonMap(SIZE, size)));
+
+ for (int i = 0; i < duration; ++i)
+ {
+ long start = System.currentTimeMillis();
+
+ client.executeMethod(method);
+
+ try
+ {
+ Thread.sleep(1000 - System.currentTimeMillis() - start);
+ }
+ catch (InterruptedException e)
+ {
+ Thread.currentThread().interrupt();
+ }
+ }
+ }
+}
Added:
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
(rev 0)
+++
trunk/mod_cluster/src/demo/java/org/jboss/modcluster/demo/servlet/SystemLoadServlet.java 2008-09-22
04:06:24 UTC (rev 1876)
@@ -0,0 +1,60 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.modcluster.demo.servlet;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * @author Paul Ferraro
+ *
+ */
+public class SystemLoadServlet extends LoadServlet
+{
+ /** The serialVersionUID */
+ private static final long serialVersionUID = 5665079393261425098L;
+
+ /**
+ * @{inheritDoc}
+ * @see javax.servlet.http.HttpServlet#service(javax.servlet.http.HttpServletRequest,
javax.servlet.http.HttpServletResponse)
+ */
+ @Override
+ protected void service(HttpServletRequest request, HttpServletResponse response)
+ {
+ long start = System.currentTimeMillis();
+
+ int duration = Integer.parseInt(this.getParameter(request, DURATION,
"15")) * 1000;
+
+ // Naughty loop
+ while (System.currentTimeMillis() - start < duration)
+ {
+ try
+ {
+ Thread.sleep(1);
+ }
+ catch (InterruptedException e)
+ {
+ break;
+ }
+ }
+ }
+}
\ No newline at end of file
Added:
trunk/mod_cluster/src/demo/java/org/jboss/modcluster/demo/servlet/ThreadCountLoadServlet.java
===================================================================
---
trunk/mod_cluster/src/demo/java/org/jboss/modcluster/demo/servlet/ThreadCountLoadServlet.java
(rev 0)
+++
trunk/mod_cluster/src/demo/java/org/jboss/modcluster/demo/servlet/ThreadCountLoadServlet.java 2008-09-22
04:06:24 UTC (rev 1876)
@@ -0,0 +1,68 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.modcluster.demo.servlet;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * @author Paul Ferraro
+ *
+ */
+public class ThreadCountLoadServlet extends LoadServlet
+{
+ /** The serialVersionUID */
+ private static final long serialVersionUID = 4975054340996769991L;
+
+ /**
+ * @{inheritDoc}
+ * @see javax.servlet.http.HttpServlet#service(javax.servlet.http.HttpServletRequest,
javax.servlet.http.HttpServletResponse)
+ */
+ @Override
+ protected void service(HttpServletRequest request, HttpServletResponse response)
+ {
+ final int duration = Integer.parseInt(this.getParameter(request, DURATION,
DEFAULT_DURATION)) * 1000;
+
+ int count = Integer.parseInt(this.getParameter(request, COUNT, "50"));
+
+ for (int i = 0; i < count; ++i)
+ {
+ Thread thread = new Thread()
+ {
+ @Override
+ public void run()
+ {
+ try
+ {
+ Thread.sleep(duration);
+ }
+ catch (InterruptedException e)
+ {
+ this.interrupt();
+ }
+ }
+ };
+
+ thread.start();
+ }
+ }
+}