• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

response time

 
manu chaox
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'd like to create a function, which will return the time(ms) corresponding response time of a web server.
I'd like to send request GET(http) on the server and than count response time(end_time - start_time).

something like:
int getResponseTime(String url,String get)
url ... page where GET is sending GET
get ... GET method of http

Could you help me please
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look into the URL and HttpURLConnection classes. If they don't makes sense on their own, see the Sun Networking Tutorial. The 2nd lesson covers this: Your Java programs can use URLs to connect to and retrieve information over a network which sounds just about right.

Let us know if you get stuck, or what you make if you don't!
 
manu chaox
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could it be in this way?




I would like to find out response time at higher number of requests.
I would like to solve this by more threads.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
At a quick read, that looks like a good start. Do you want to actually read the results back? That would make your time include the full data transmission. And you may have to beef it up over time as you find problem sites.

You could encapsulate this in a little class and run several of them with a thread pool. At some number of threads your network connection or your program will become the bottleneck just because you're doing too much. If you ran a thousand at once they might all appear to have 60 second response time. I have a downloader that seems to run best at three or four threads, but I haven't really measured it and your mileage may vary.

Are you comfortable with the Executor in Java5 and later? You can use a fixed size pool to control the number of threads, put all your sites in queue and wait for them to finish. Join us in the Threads forum if you have any trouble.
[ June 22, 2007: Message edited by: Stan James ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic