Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Any way to assess client connection speed? 2

Status
Not open for further replies.

may1hem

Programmer
Jul 28, 2002
262
GB
I know this is a tricky one, but is there any clever way to assess a visitor's connection speed?

I'm sure it must be possible using Flash or Java by testing time between the server & client, but I don't want to soil my ASP/DHTML site with any plug-ins so the simpler the method, the better.

Thanks for any ideas,

May
 
I've seen this done, nothing that's all that wonderful... but it seems the person sets a time variable at the start of loading up an image of a set size. Then once the image is loaded, they have that trigger the setting of another variable... subtract the two, divide size/time and you have an estimation.

-Rob
 
Thanks Rob,

Do you think this method is reasonably reliable? Is it possible to check, using JavaScript, whether an image has been fully downloaded?

It sounds good and i'm thinking of using it but just wondering if there are any glaring holes that i've overlooked.

Of course, the speed of the Web varies depending on time and day, but that's irrelevant for me. I just want to work out if the visitor's connection is currently fast enought to send heavy media.

Thanks for your ideas,

May
 
I believe the big hole is people who turn off images, but I'm fairly certain you can detect that.

I guess you're going to have to do something to make sure they're not loading the image from cache as well.

I'm not sure of anything else, I've never implemented such a scheme, just heard of it... it sounds to me like a scheme which should work, but is probably easily fooled. Assuming reasonable users I'd imagine you'll be fine... if you have to worry about someone being malicious... that's another story.

Good luck, I'll spend some time over the next day or so and see if I can't find a snippet of code that implements this.

-Rob
 
Thanks Rob, I think you're right about the caching, and script blocking should be considered as well.

Thanks for your input Gary. I'm using ASP. Do you know of a way to test connection speed from the server-side? I guess this would amount to pretty much the same results?

May
 
I reckon it's almost impossible to get any sort of reliable result. If it could be done, it would probably need a combination of client / server code, as the server would have to specify when the page was sent out, and the client would have to indicate when it was received. This causes other problems, as the client result would have to be sent back to the server (ie. another page hit). On a slow connection, the test alone would slow things down even more. Also, aside from false readings with caching, etc, what if the server and client are in different time zones? You have to be careful you're comparing similar time readings.

My own view is that, if most big sites ask you explicitly what connection speed you have, there's probably a good reason for it.
 
No, I don't agree blueark and xutopia...

to get any reasonable estimation it all needs to be done on the client side... trying to time it on the server side just doesn't make any sense.

The client needs to set a time before and after the start of a transfer... trying to match clocks between a server and client just doesn't work, forget about different time zones, being off by seconds in much more tragic to this sort of test... having the server measure what it sends out doesn't either.

now, making the client do it is a trick I agree, but it's the only way to produce any sort of reasonable estimation that I can imagine.

-Rob
 
Actually, I've had a think about it, and I think you're right about client side. Firstly, use inline javascript to get the time into a variable. Then, use a function in the <body OnLoad()..> to get a new time and find the difference. This will only fire when the document, including images, has loaded, so it should give you a reasonably accurate result. Finally, redirect to an appropriate page depending on the result. I'm sure some of you JavaScript wizards could come up with the actual code!
 
well I still stand behind what I stated. I don't think there are any reliable means to figure out speed on the client side only.

Speed is determined by two factors. Connection time (ping time) and throughput (transfer rate). There are many ways you can try to figure out a speed (download a page and see how much time it takes to load, download a set of images and time it). I am not sure the numbers you get are anywhere close to what the connection really is like between that client and other servers around the world (the server you would be using for the test could be under a lot of load and not provide as much throughput as the client could use).

Whatever happens keep us posted. I'd be interested in seeing how your tests come out! :) Gary Haran
 
Hmmm...

Working out the speed client-side sounds like a solution. I'm not keen on using the Body OnLoad event as that requires a page change and that could cause a few problems. I think I remember reading that pages that automatically changed location cause accessibility-related problems. Perhaps that only refers to content vanishing whilst a reader is reading the page aloud? I digress... Where were we?

What would be ideal is to send an image to the client initially and time that. This way we're no looking at connection time but throughput and this should be a good measure of bandwidth (or connection speed on the Net at that time on that day). I'm not sure how long a connection takes but either we can measure 1 and count that as a constant or take it to be negligible in relation to the image transfer time.

Isn't it possible to send a portion of a page in ASP using a Flush method, or similar? Can the script be halted until a response is received back from the client, stating the initial image download time?

Then, if the time is less than a specified number of seconds then we could send the heavy media. If the time is large then send the light static images.

Hmm.. Need some ASP help here. Any ideas?

Thanks,

May
 
Well, I'm with Gary on this one.

I just ran 3 tests directly after each other on the link provided above. The following are the results.

662.25 kbits/sec
820.7 kbits/sec
599.27 kbits/sec

The above figures may show my connection speed, but that is only at the exact time that I run the test, not the whole time I am visiting that site.

I might get the script running at a time when I have a great connection and then when the actual content of the site shows, my connection could be either a lot slower or a lot faster.

If you wanted to take a reliable account of connection speed, you need to run multiple tests, not just one or two.

Hope this helps Wullie


The pessimist complains about the wind. The optimist expects it to change.
The leader adjusts the sails. - John Maxwell
 

Read the question Why are my results different every time I run the test?[/].

Wullie pointed out something I did. This is not reliable because no matter what you do the connection speed can increase or decrease because of your network activity or the activity of a node higher up in your network.

Like wullie I'll say that you will need to run the test quite a few times to see if it is consistent. Gary Haran
 
Yes, but I think we've moved on from accuracy to getting some idea of whether or not the client can handle heavy media. On a slow dial-up, the values vary too, but at least it's clear that it's under a certain threshold (eg. 41, 35, 43 when I tested it). Surely this is of some use when determining what media to send.

The only problem I have is that the test itself is something many people won't have the patience to wait for, which is probably why it's better to let the user decide what content they want. Also, even those with fast connections mightn't want to download huge files, just like many people with flash plug-ins prefer the html version of a page...
 
Thanks for that, Rob! *STAR* for you.

One drawback there is that the test image is 200Kb. Blueark's right that users won't have the patience to wait, though this could be used to test some of the initial images on the page.

Possibly even send down static images, test their speed and dynamically replace them with heavier animated images or Flash if the user has a good connection. I mean bandwidth, of course, not connection time.

Is there a way, using JavaScript, to check if an image has been fully downloaded? It would have to be a reliable check as we don't want to be confused by image blockers.

Thanks,

May
 
Well, here's my two cents on the accuracy discussion.

My impression of such a test has always been and still is, it's only useful to differentiate dialups from faster connections. Namely, above or below a certain threshold as stated above.

You're not going to use it to determine exact download speed or any such issue.

Given that, the larger the file the more accurate your results. 200k apparently is pretty reliable... given that you're exactly determining the users ability to accept heavy media, I would toy with the lower threshold of image size for a reasonable reading. I would bet at 50k you would not be able to get any idea how fast someone's connection actually is, but you'd still be able to differentiate between a dialup and a DSL connection.

-Rob
 
skiflyer

Even using 50k to test the connection, that is a further 50k added to the download time for a dial-up user.

I don't see the point in adding download time just to see if you can speed up the download for the user.

Hops this helps Wullie


The pessimist complains about the wind. The optimist expects it to change.
The leader adjusts the sails. - John Maxwell
 
I don't agree or disagree with that notion... in part it depends just how small you can make that file and get a reasonable response... and it doesn't necessarily need to be an additional 50k as mayhem pointed out, it could be the initial image on your splash page if you like.

But granted, I do see it's usefuleness as limited.

-Rob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top