?
Solved

http client/stress tool

Posted on 2003-04-01
15
Medium Priority
?
207 Views
Last Modified: 2011-09-20
I am trying to create a basic test tool, that hopefully will develop into a bigger project, basically I want to create a simple threaded httpclient that will send multiple requests to a server, record the avg response time, response time etc.  I want to know what would be the best way to modify this using threads and is their anything I have to look out for.  How can I record the response times etc, as I want to create a graph from the results??  Has anyone tried this before?  ANy good links etc?? I have read a lot, I know im capable of doing it, I just want to be put on the right track.

 Some sample code would be great.

import java.net.*;
import java.io.*;
import java.util.*;

public class WebTest
{
    public static void main (String[] args)
    {
        // initialize random seed
        Random randomGen = new Random(new Date().getTime());
        while(true)
        {
            try
           {
               // sleep for a random interval
               Thread.currentThread().sleep(randomGen.nextInt(args.length>1?(new Integer(args[1]).intValue()):10000));
                if(args.length>0)
               {
                   // print the user supplied URL to the console window
                   System.out.println(args[0]);
                   // open URL connection
                   URLConnection urlConn = new URL(args[0]).openConnection();
                   urlConn.setUseCaches(false);
                   // read and print the content to the console window
                   InputStream in = urlConn.getInputStream();
                    byte buf[] = new byte[4096];
                    int nSize = in.read(buf);
                    while(nSize>=0)
                   {
                       System.out.print(new String(buf,0,nSize));
                       nSize = in.read(buf);
                   }
                   System.out.print("\r\n");
               }
                else return;
           }
            catch(Exception e)
           {
               // print error message
               System.out.println("Exception: "+e.getMessage());
           }
        }
    }
}

Thanks,

Paul
0
Comment
Question by:pronane
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 3
  • +1
15 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 8246008
You should really use thread pooling, or you'll end up stressing the client as well ;-)

See http://archive.devx.com/upload/free/features/javapro/2000/10oct00/tm0010/tm0010.asp

for instance
0
 
LVL 1

Author Comment

by:pronane
ID: 8246482
Any ideas on any of the other parts of the question, thanks for that link, didnt know that before ;)  The one thing I want to do correctly is receving stats and graphing them, Im not really sure how to go about that at all.
0
 
LVL 35

Expert Comment

by:TimYates
ID: 8246564
Or, use JMeter, Apache's extendable Website/code stress tester...

http://jakarta.apache.org/jmeter/
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 35

Expert Comment

by:TimYates
ID: 8246571
it basically does what you want to do...
0
 
LVL 1

Author Comment

by:pronane
ID: 8246582
ya i know that ive tested it and used it.  its the basis of what i want to do.  
0
 
LVL 1

Author Comment

by:pronane
ID: 8248242
No one got any other ideas?  Thanks for the above responses but this is stuff I knew already, can I claim my point back?  Sorry its just I hoped to get a better response. Thanks again.
0
 
LVL 35

Expert Comment

by:TimYates
ID: 8248324
Jmeter is open source...  if you're gonna copy it, you might as well do it from the source ;-)

To get this question deleted or moved to PAQ for free (which is better, as people can see the responses), post a message here:

http://www.experts-exchange.com/Community_Support/CleanUp/

Explaining the url for this question, what you want doing, and why...
0
 
LVL 1

Expert Comment

by:Computer101
ID: 8287547
A request for deletion has been made.  If no response or you feel this is in error, comment.  If no objection, I will delete in three days.

Computer101
E-E Admin
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 8287841
Personally i think the advice that's been given has been neither useless nor effortless.
0
 
LVL 35

Expert Comment

by:TimYates
ID: 8294912
Neither do I :-(

He even said "thanks for that link, didnt know that before" to CEHJ's comment...
0
 
LVL 1

Expert Comment

by:Computer101
ID: 8296064
Got it, recommendations for closure?

Computer101
E-E Admin
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 8298429
Points split between me and Tim please
0
 
LVL 1

Author Comment

by:pronane
ID: 8299612
I knew this already, thats why, however if one/both of you answer me this question then I will give the points.  Is that fair enough ??? ;)

0
 
LVL 1

Author Comment

by:pronane
ID: 8308379
the recommendations is I didnt get a sufficient answer or an answer that helped me with what I am trying to do.
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 8345383
Question placed in PAQ

Computer101
E-E Admin
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses
Course of the Month9 days, 1 hour left to enroll

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question