mstover1 2002/08/27 08:03:37
Modified: src/core/org/apache/jmeter/engine StandardJMeterEngine.java
src/core/org/apache/jmeter/threads JMeterThread.java
ListenerNotifier.java
src/core/org/apache/jmeter/util JMeterUtils.java
src/protocol/http/org/apache/jmeter/protocol/http/sampler
HTTPSampler.java HTTPSamplerFull.java
PostWriter.java
Log:
turning off keep-alive dynamically when run out of connections
Revision Changes Path
1.9 +12 -3
jakarta-jmeter/src/core/org/apache/jmeter/engine/StandardJMeterEngine.java
Index: StandardJMeterEngine.java
===================================================================
RCS file:
/home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/engine/StandardJMeterEngine.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- StandardJMeterEngine.java 25 Aug 2002 20:10:04 -0000 1.8
+++ StandardJMeterEngine.java 27 Aug 2002 15:03:36 -0000 1.9
@@ -297,7 +297,16 @@
{
JMeterThread item = (JMeterThread)iter.next();
item.stop();
- ((Thread)allThreads.get(item)).interrupt();
+ Thread t = (Thread)allThreads.get(item);
+ if(t != null)
+ {
+ t.interrupt();
+ }
+ else
+ {
+ log.warn("Lost thread: "+item.getThreadName());
+ allThreads.remove(item);
+ }
}
}
1.7 +9 -2
jakarta-jmeter/src/core/org/apache/jmeter/threads/JMeterThread.java
Index: JMeterThread.java
===================================================================
RCS file:
/home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/threads/JMeterThread.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- JMeterThread.java 26 Aug 2002 15:49:37 -0000 1.6
+++ JMeterThread.java 27 Aug 2002 15:03:36 -0000 1.7
@@ -154,9 +154,16 @@
}
finally
{
+ log.info("Thread "+threadName+" is done");
monitor.threadFinished(this);
}
}
+
+ public String getThreadName()
+ {
+ return threadName;
+ }
+
/****************************************
* !ToDo (Method description)
***************************************/
1.4 +14 -3
jakarta-jmeter/src/core/org/apache/jmeter/threads/ListenerNotifier.java
Index: ListenerNotifier.java
===================================================================
RCS file:
/home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/threads/ListenerNotifier.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ListenerNotifier.java 25 Aug 2002 19:42:21 -0000 1.3
+++ ListenerNotifier.java 27 Aug 2002 15:03:36 -0000 1.4
@@ -44,12 +44,22 @@
((SampleListener)
iter.next()).sampleOccurred(res);
}
}
- try
+ if(sleepTime > 0)
{
- Thread.sleep(sleepTime);
+ try
+ {
+ Thread.sleep(sleepTime);
+ }
+ catch (InterruptedException e)
+ {
+ }
}
- catch (InterruptedException e)
+ else
{
+ if(size() > 200)
+ {
+
Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
+ }
}
}
log.debug("Listener Notifier stopped");
@@ -74,6 +84,7 @@
catch (RuntimeException e)
{
sleepTime = 2000;
+ Thread.currentThread().setPriority(Thread.NORM_PRIORITY);
return null;
}
}
1.6 +2 -2 jakarta-jmeter/src/core/org/apache/jmeter/util/JMeterUtils.java
Index: JMeterUtils.java
===================================================================
RCS file: /home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/util/JMeterUtils.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- JMeterUtils.java 25 Aug 2002 19:42:21 -0000 1.5
+++ JMeterUtils.java 27 Aug 2002 15:03:36 -0000 1.6
@@ -1036,6 +1036,6 @@
*/
public static String getJMeterVersion()
{
- return "@VERSION@";
+ return "1.7.3";
}
}
1.9 +51 -22
jakarta-jmeter/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampler.java
Index: HTTPSampler.java
===================================================================
RCS file:
/home/cvs/jakarta-jmeter/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampler.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- HTTPSampler.java 25 Aug 2002 19:42:21 -0000 1.8
+++ HTTPSampler.java 27 Aug 2002 15:03:36 -0000 1.9
@@ -115,6 +115,8 @@
public final static String MULTIPART_FORM = "multipart_form";
protected static String encoding = "iso-8859-1";
private static final PostWriter postWriter = new PostWriter();
+ protected HttpURLConnection conn;
+ private int connectionTries = 0;
public void setFileField(String value)
{
setProperty(FILE_FIELD, value);
@@ -618,7 +620,7 @@
{
w.write(buffer, 0, x);
}
- in.close();
+ //in.close();
w.flush();
w.close();
return w.toByteArray();
@@ -634,8 +636,6 @@
throws IOException
{
StringBuffer headerBuf = new StringBuffer();
- //PrintWriter headerBytes = new PrintWriter(output);
- // either 'HTTP/1.0' or 'HTTP/1.1'
headerBuf.append(conn.getHeaderField(0).substring(0, 8));
headerBuf.append(" ");
headerBuf.append(conn.getResponseCode());
@@ -655,14 +655,6 @@
headerBuf.append("\n");
return headerBuf.toString().getBytes("8859_1");
}
- /*
- * Uploading a file - put in separate sampler
- * else if (contentType.equals(MULTIPART_FORM))
- * {
- *
- * }
- * }
- */
/****************************************
* Extracts all the required cookies for that particular URL request and set
* them in the <code>HttpURLConnection</code> passed in
@@ -810,6 +802,37 @@
removeArguments();
parseArguments(newUrl.getQuery());
}
+
+ protected long connect() throws IOException
+ {
+ long time = System.currentTimeMillis();
+ try
+ {
+ conn.connect();
+ }
+ catch(IOException e)
+ {
+ log.debug("Connection failed, turning off keep-alive and
trying again");
+ if(connectionTries++ == 10)
+ {
+ log.error("Can't connect",e);
+ throw e;
+ }
+ conn.disconnect();
+ conn = null;
+ System.gc();
+ Runtime.getRuntime().runFinalization();
+ this.setUseKeepAlive(false);
+ conn = setupConnection(getUrl(),getMethod());
+ if(getMethod().equals(HTTPSampler.POST))
+ {
+ postWriter.setHeaders(conn,this);
+ }
+ time = connect();
+ }
+ return time;
+ }
+
/****************************************
* Samples <code>Entry</code> passed in and stores the result in
<code>SampleResult</code>
*
@@ -820,7 +843,7 @@
private SampleResult sample(boolean redirected)
{
log.debug("Start : sample2");
- long time = 0L;
+ long time = System.currentTimeMillis();
SampleResult res = new SampleResult();
if (redirected)
{
@@ -833,7 +856,6 @@
// behaves. That's not to say it's perfect as is...
}
URL u = null;
- HttpURLConnection conn = null;
try
{
u = getUrl();
@@ -854,13 +876,17 @@
// data in the count... should we? - mike: good point, I
changed it
// TO-DO: Is there something I'm missing here?
// [/Jordi]
- time = System.currentTimeMillis();
+ if (!redirected
+ &&
getProperty(HTTPSampler.METHOD).equals(HTTPSampler.POST))
+ {
+ postWriter.setHeaders(conn,this);
+ }
+ time = connect();
if (!redirected
&&
getProperty(HTTPSampler.METHOD).equals(HTTPSampler.POST))
{
sendPostData(conn);
}
- conn.connect();
saveConnectionCookies(conn, u, getCookieManager());
int errorLevel = 0;
try
@@ -869,8 +895,9 @@
}
catch (IOException e)
{
- res.setSuccessful(false);
time = bundleResponseInResult(time, res, conn);
+ res.setSuccessful(false);
+ res.setTime(time);
return res;
}
if (errorLevel / 100 == 2 || errorLevel == 304)
@@ -925,12 +952,14 @@
// calling disconnect doesn't close the connection
immediately, but
// indicates we're through with it. The JVM should
close it when
// necessary.
- if (conn != null)
+ String connection = conn.getHeaderField("Connection");
+ if (connection == null ||
connection.equalsIgnoreCase("close"))
conn.disconnect();
}
catch (Exception e)
{
}
+
}
log.debug("End : sample2");
return res;
@@ -941,15 +970,15 @@
HttpURLConnection conn)
throws IOException, FileNotFoundException
{
+ res.setDataType(res.TEXT);
byte[] ret = readResponse(conn);
byte[] head = getResponseHeaders(conn, res);
time = System.currentTimeMillis() - time;
byte[] complete = new byte[ret.length + head.length];
System.arraycopy(head, 0, complete, 0, head.length);
System.arraycopy(ret, 0, complete, head.length, ret.length);
- res.setResponseData(complete);
- res.setSuccessful(true);
- res.setDataType(res.TEXT);
+ res.setResponseData(complete);
+ res.setSuccessful(true);
return time;
}
/****************************************
1.5 +2 -3
jakarta-jmeter/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSamplerFull.java
Index: HTTPSamplerFull.java
===================================================================
RCS file:
/home/cvs/jakarta-jmeter/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSamplerFull.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- HTTPSamplerFull.java 23 Aug 2002 22:51:47 -0000 1.4
+++ HTTPSamplerFull.java 27 Aug 2002 15:03:36 -0000 1.5
@@ -372,11 +372,10 @@
log.debug("Start : loadBinary");
byte[] ret = new byte[0];
res.setSamplerData(new HTTPSampler(url));
- HttpURLConnection conn = null;
try
{
conn = setupConnection(url, GET);
- conn.connect();
+ connect();
}
catch(IOException ioe)
{
1.3 +24 -10
jakarta-jmeter/src/protocol/http/org/apache/jmeter/protocol/http/sampler/PostWriter.java
Index: PostWriter.java
===================================================================
RCS file:
/home/cvs/jakarta-jmeter/src/protocol/http/org/apache/jmeter/protocol/http/sampler/PostWriter.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- PostWriter.java 24 Aug 2002 00:45:25 -0000 1.2
+++ PostWriter.java 27 Aug 2002 15:03:36 -0000 1.3
@@ -91,15 +91,10 @@
public void sendPostData(URLConnection connection, HTTPSampler sampler)
throws IOException
{
- ((HttpURLConnection)connection).setRequestMethod("POST");
-
// If filename was specified then send the post using multipart syntax
String filename = sampler.getFileField();
if ((filename != null) && (filename.trim().length() > 0))
{
- connection.setRequestProperty("Content-type",
"multipart/form-data; boundary=" + BOUNDARY);
- connection.setDoOutput(true);
- connection.setDoInput(true);
OutputStream out = connection.getOutputStream();//new
FileOutputStream("c:\\data\\experiment.txt");//new ByteArrayOutputStream();//
writeln(out,"--"+BOUNDARY);
Iterator args = sampler.getArguments().iterator();
@@ -114,7 +109,30 @@
writeln(out,"--" + BOUNDARY+"--");
out.flush();
- out.close();
+ //out.close();
+ }
+
+ // No filename specified, so send the post using normal syntax
+ else
+ {
+ String postData = sampler.getQueryString();
+ PrintWriter out = new
PrintWriter(connection.getOutputStream());
+ out.print(postData);
+ out.flush();
+ }
+ }
+
+ public void setHeaders(URLConnection connection,HTTPSampler sampler) throws
IOException
+ {
+ ((HttpURLConnection)connection).setRequestMethod("POST");
+
+ // If filename was specified then send the post using multipart syntax
+ String filename = sampler.getFileField();
+ if ((filename != null) && (filename.trim().length() > 0))
+ {
+ connection.setRequestProperty("Content-type",
"multipart/form-data; boundary=" + BOUNDARY);
+ connection.setDoOutput(true);
+ connection.setDoInput(true);
}
// No filename specified, so send the post using normal syntax
@@ -124,10 +142,6 @@
connection.setRequestProperty("Content-length", "" +
postData.length());
connection.setRequestProperty("Content-type",
"application/x-www-form-urlencoded");
connection.setDoOutput(true);
-
- PrintWriter out = new
PrintWriter(connection.getOutputStream());
- out.print(postData);
- out.close();
}
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>