GetResponse delay

J

JezB

I do some peeking at files on the web in my program with code such as:

WebRequest wr = WebRequest.Create(url);
WebResponse r = wr.GetResponse();

I've noticed that the first time GetResponse is executed, it takes some 3 to
4 seconds. Repeating the same code in the same run is almost immediate. So
why the delay the first time this is executed on each run? And can I do
anything about it?
 
M

Michael C

JezB said:
I do some peeking at files on the web in my program with code such as:

WebRequest wr = WebRequest.Create(url);
WebResponse r = wr.GetResponse();

I've noticed that the first time GetResponse is executed, it takes some 3
to 4 seconds. Repeating the same code in the same run is almost immediate.
So why the delay the first time this is executed on each run? And can I do
anything about it?

This is a very normal thing for PCs. Haven't you ever used a PC before and
noticed that doing practically *anything* takes longer the first time?

Michael
 
J

JezB

I've been using PCs for 20 years pal. Doesn't explain why the same url in a
web browser appears instantly (it's only a small text file) yet GetResponse
takes 4 seconds - there must be a reason for it, and I assume you don't know
it.
 
S

SurfNet

JezB said:
I've been using PCs for 20 years pal. Doesn't explain why the same url in a
web browser appears instantly (it's only a small text file) yet GetResponse
takes 4 seconds - there must be a reason for it, and I assume you don't know
it.

I see to possibilities.

1) There is a high overhead setting up the HTTP connection and the second
time its reused...
2) The immediate code is compiled the first time and the second time its
already present. That might be a side-effect of dotNET.
3) A round-trip to the server is expensive and the second time the cache is
used (not too likely that this is the case).

Of course combinations are possible too...

- Joris
 
M

Michael C

JezB said:
I've been using PCs for 20 years pal. Doesn't explain why the same url in
a web browser appears instantly (it's only a small text file) yet
GetResponse takes 4 seconds - there must be a reason for it, and I assume
you don't know it.

It's called cache my friend.

Michael
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top