Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Can perl be used to test ISP upload speed?

0 views
Skip to first unread message

Guy

unread,
Dec 2, 2003, 10:53:19 PM12/2/03
to
I suspect that this may not be in the proper newsgroup, and if so, please
ignore this posting.

I have perl 5.008 on a web server. I can create a perl script that can
manipulate data that is sent to it from an HTML form.

But I can't think of a way that perl could be used to test upload speed.

A good way to test upload speed would be to upload a file and calculate the
time it took to get there. But again I can't see how perl could be used to
test upload speed, and I'm wondering if it is possible.

I'm actually thinking that current online broadband speed tests use
something other that a server side script. I think they actually download a
small client side program?

Guy Doucet


Gunnar Hjalmarsson

unread,
Dec 2, 2003, 11:01:33 PM12/2/03
to
Guy wrote:
> But I can't think of a way that perl could be used to test upload
> speed.

Then you don't know much about Perl, do you?

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

Guy

unread,
Dec 3, 2003, 7:51:43 PM12/3/03
to
I thought my previous postings already showed that :-)

Actually, the only thing I -have- done with Perl, are CGI scripts running on
web servers, that manipulate data sent to it from forms inside HTML pages.
So I've really only seen where a few variables at a time are sent to a Perl
script and for that matter, the Perl script just updates text files and then
spits out HTML pages in return back to the browser.

The only thought that comes to mind for measuring upload speed is that I'd
have to keep track of time. Then making a few repeated calls to the Perl
script sending a little bit of data at a time. But making repeated calls
wouldn't be a good way either because each time a new channel has to be
created and this takes time not really related to upload speed. I also
don't know the inside of HTTP either. There must be a limit to the amount of
data an HTML document can send back to the web server - but that's another
issue.

Guy


"Gunnar Hjalmarsson" <nor...@gunnar.cc> wrote in message
news:bqjn76$23379n$1...@ID-184292.news.uni-berlin.de...

Gunnar Hjalmarsson

unread,
Dec 3, 2003, 11:56:29 PM12/3/03
to
[ Please do not top post! ]

Guy wrote:


> Gunnar Hjalmarsson wrote:
>> Guy wrote:
>>> But I can't think of a way that perl could be used to test
>>> upload speed.
>>
>> Then you don't know much about Perl, do you?
>

> I thought my previous postings already showed that :-)

Well, sorry for my sulky reply. I just thought that your original post
was unnecessarily wordy. If I understand you right, you want to know:

"How can I have Perl measure the time it takes to run a certain
operation?"

Basically it can be done like this (assuming the operation takes a few
seconds):

my $starttime = time;
# code for accomplishing something
print 'Done. It took ', time - $starttime, " seconds.\n";

Ben Morrow

unread,
Dec 4, 2003, 1:39:43 PM12/4/03
to

Gunnar Hjalmarsson <nor...@gunnar.cc> wrote:
> [ Please do not top post! ]
>
> Guy wrote:
> > Gunnar Hjalmarsson wrote:
> >> Guy wrote:
> >>> But I can't think of a way that perl could be used to test
> >>> upload speed.
> >>
> >> Then you don't know much about Perl, do you?
> >
> > I thought my previous postings already showed that :-)
>
> Well, sorry for my sulky reply. I just thought that your original post
> was unnecessarily wordy. If I understand you right, you want to know:
>
> "How can I have Perl measure the time it takes to run a certain
> operation?"

I would have said the OP would be better interpreted as "How can I
write a CGI that will time a file upload submitted to it?"; which I
don't *think* can be done...

Ben

--
perl -e'print map {/.(.)/s} sort unpack "a2"x26, pack "N"x13,
qw/1632265075 1651865445 1685354798 1696626283 1752131169 1769237618
1801808488 1830841936 1886550130 1914728293 1936225377 1969451372
2047502190/' # b...@morrow.me.uk

Gunnar Hjalmarsson

unread,
Dec 5, 2003, 6:30:42 AM12/5/03
to
Ben Morrow wrote:

> Gunnar Hjalmarsson wrote:
>> If I understand you right, you want to know:
>>
>> "How can I have Perl measure the time it takes to run a certain
>> operation?"
>
> I would have said the OP would be better interpreted as "How can I
> write a CGI that will time a file upload submitted to it?"; which I
> don't *think* can be done...

I can't see how a file upload would differ from other things in this
respect. This script appears to work fine for me:

#!/usr/bin/perl
use strict;
use warnings;
use CGI;

my $dir = '/path/to/incoming/directory';

my $starttime = time;

my $q = new CGI;
my $fh = $q->upload('myfile');
$q->uploadInfo($fh)->{'Content-Disposition'} =~
/filename="([\w\-\. ]+)"/;
my $name = ($1 or $starttime);
open FILE, "> $dir/$name" or die $!;
binmode FILE;
print FILE $_ while <$fh>;
close FILE;

print "Content-type: text/html\n\n";
print "$name was uploaded.<br>";
print "It took ", time - $starttime, " seconds.\n";

What am I missing?

Ben Morrow

unread,
Dec 5, 2003, 7:10:00 AM12/5/03
to

Gunnar Hjalmarsson <nor...@gunnar.cc> wrote:
> Ben Morrow wrote:
> > Gunnar Hjalmarsson wrote:
> >> If I understand you right, you want to know:
> >>
> >> "How can I have Perl measure the time it takes to run a certain
> >> operation?"
> >
> > I would have said the OP would be better interpreted as "How can I
> > write a CGI that will time a file upload submitted to it?"; which I
> > don't *think* can be done...
>
> I can't see how a file upload would differ from other things in this
> respect. This script appears to work fine for me:
>
<snip>
>
> What am I missing?

*thinks*

Nothing. I was (not) thinking that the actual upload would be
completed before the CGI was invoked.

You may still end up with a smaller value for the time than you
should, if httpd starts buffering the upload before the perl script
starts.

Ben

--
"The Earth is degenerating these days. Bribery and corruption abound.
Children no longer mind their parents, every man wants to write a book,
and it is evident that the end of the world is fast approaching."
-Assyrian stone tablet, c.2800 BC b...@morrow.me.uk

0 new messages