Home arrow static arrow Java Programming [Archive] - hi all
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - hi all
10 Duke Stars available
This topic has 7 replies on 1 page.

Posts:3
Registered: 8/2/04
hi all  
Aug 2, 2004 7:29 AM



 
I am developing one HTTP client software and saving response times.
I use the following algorithm to get a specific file from HTTP server.

(socket connection and URL stuff...)
time1
BufferedInputStream bis = new BufferedInputStream(url.openStream());
time2
while (( bis.read(buff,0,BUFFER)) != -1)
{
here i write it to local file!!!
bos.write(buff,0,rec);
bos.flush();
}
time3

Now! would the response time of the service be
responsetime = time2 - time1
or
responsetime = time3 - time1
or
responsetime = time3 - time2
?

if any has an idea , id appriciate it!!
Thanks in advance!
 

Posts:14,142
Registered: 99-04-02
Re: hi all  
Aug 2, 2004 7:56 AM (reply 1 of 7)



 
depends.... do you want response time to mean time for the server to accept your request? If so, it's time2 - time1. If you want to include complete file download, it's time3 - time1. OF course, that could vary more based on file size.
 

Posts:6,487
Registered: 5/5/04
Re: hi all  
Aug 2, 2004 7:59 AM (reply 2 of 7)



 
If you use time3 then you are also measuring the time taken to write the result to disk.
Instead you should read the result into memory (or dump it) to get a more accurate time.
 

Posts:3
Registered: 8/2/04
Re: hi all  
Aug 2, 2004 8:14 AM (reply 3 of 7)



 
well, i am not interested in writing the file to the disk. What i cant be sure of is that:
does the communication flow like below?

time1: client opens the stream BufferedInputStream bis = new BufferedInputStream(url.openStream()); and server accepts the request and send all the ip packets for the file!
time2:server finished sending packets and client starts to read from stream

or

time1: client opens the stream BufferedInputStream bis = new BufferedInputStream(url.openStream()); and server accepts the request and starts to send the packets for the file.
time2:while server continues to send packets and client starts to read the packets that arrived simultaneously.

Thanks
 

Posts:14,142
Registered: 99-04-02
Re: hi all  
Aug 2, 2004 8:42 AM (reply 4 of 7)



 
Well, it's a little confusing... what is "(socket connection and URL stuff...)"?

You call url.openStream(), so that implies you are using the URLConnection class. So in this case, nothing actually happens til you call openStream(). This call will make the underlying socket connection to the server and push the request thru, and receive the response and return an input stream that you can start reading the body content of the response.

If you are really interested in detailed measurement of different parts of the process, you should use regular Sockets and generate the headers and handle the responses yourself. The best you can get from URLConnection is to count the time between openStream() and reading the first bytes from the input stream, which tells you how long the server response takes to start. Then the time after the last read to tell you total file transfer time.
 

Posts:47
Registered: 4/1/03
Re: hi all  
Aug 2, 2004 9:07 AM (reply 5 of 7)



 

the point is esponsetime means for what ?
 

Posts:3
Registered: 8/2/04
Re: hi all  
Aug 2, 2004 9:34 AM (reply 6 of 7)



 
ok you say,
- openstream will connect and push the request, and receive the RESPONSE. where is the file i requested now? is the file already within this response or is it still on the DISK of SERVER so the method bis.read(buff,0,BUFFER)) , downloads it from the DISK of SERVER.
Thanks a alot
 

Posts:14,142
Registered: 99-04-02
Re: hi all  
Aug 2, 2004 10:10 AM (reply 7 of 7)



 
once you call openStream(), the file will start being pushed by the server, but depending on the file size and the connection speed between client and server, any or all of the file could be anwhere between the server's network buffer and the client's network buffer. You don't get it into your app til you start reading from the input stream.

Like I said, if you want to know the time from request start to response header finish (not including response content transfer) you'd have to use regular Sockets and talk to the server directly without using URLConnection.
 
This topic has 7 replies on 1 page.