Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 208
  • Last Modified:

http client/stress tool

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
pronane
Asked:
pronane
  • 5
  • 4
  • 3
  • +1
1 Solution
 
CEHJCommented:
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
 
pronaneAuthor Commented:
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
 
TimYatesCommented:
Or, use JMeter, Apache's extendable Website/code stress tester...

http://jakarta.apache.org/jmeter/
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
TimYatesCommented:
it basically does what you want to do...
0
 
pronaneAuthor Commented:
ya i know that ive tested it and used it.  its the basis of what i want to do.  
0
 
pronaneAuthor Commented:
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
 
TimYatesCommented:
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
 
Computer101Commented:
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
 
CEHJCommented:
Personally i think the advice that's been given has been neither useless nor effortless.
0
 
TimYatesCommented:
Neither do I :-(

He even said "thanks for that link, didnt know that before" to CEHJ's comment...
0
 
Computer101Commented:
Got it, recommendations for closure?

Computer101
E-E Admin
0
 
CEHJCommented:
Points split between me and Tim please
0
 
pronaneAuthor Commented:
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
 
pronaneAuthor Commented:
the recommendations is I didnt get a sufficient answer or an answer that helped me with what I am trying to do.
0
 
Computer101Commented:
Question placed in PAQ

Computer101
E-E Admin
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 5
  • 4
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now