| View previous topic :: View next topic |
| Author |
Message |
Hippo Contributor


Joined: 08 Feb 2005 Posts: 53
|
Posted: Wed Feb 09, 2005 11:14 am Post subject: Help with Download Speed code using dreadnet.dll |
|
|
I am using dreadnet.dll to create and bandwidth monitor. The code I have written seems to work ok, but it seems to over estimate the download speed by about 10k/s. If someone could test this on there system to prove the point I would be grateful.
| Code: | external dreadnet.dll
#define function,dnet
option decimalsep,.
Title Bandwidth Monitor
DIALOG CREATE,New Dialog,-1,0,266,87
DIALOG ADD,TEXT,TEXT1,12,12,,,TEXT1
DIALOG ADD,TEXT,TEXT2,36,12,,,TEXT2
DIALOG ADD,TEXT,TEXT3,60,12,,,TEXT3
DIALOG SHOW
goto timer
:Evloop
wait event,1
goto @event()
:TIMER
%%bytesin = @Dnet(Genstats,Infmat)
%%bytesout = @Dnet(Genstats,outfmat)
dialog set,text1,Total Bytes Downloaded %%bytesin
dialog set,text2,Total Bytes Uploaded %%bytesout
%%TransferredBytes_1 = @Dnet(Genstats,Inbytes)
wait 1
%%TransferredBytes_2 = @Dnet(Genstats,Inbytes)
%%TransferredBytes = @diff(%%TransferredBytes_2, %%TransferredBytes_1)
#--- %%TransferredBytes now holds the number of bytes tranferred in one second
%%Speed = @fdiv(%%TransferredBytes, 1024)
dialog set,text3,Download Speed: @format(%%speed,3.2) kb/s
goto evloop
:Close
exit |
|
|
| Back to top |
|
 |
Hooligan VDS Developer


Joined: 28 Oct 2003 Posts: 480 Location: California
|
Posted: Wed Feb 09, 2005 4:01 pm Post subject: |
|
|
I suspect that there is some overhead involved that your calculation does not account for. (Packet headers, etc.)
Hooligan _________________ Hooligan
Why be normal? |
|
| Back to top |
|
 |
Dr. Dread Professional Member


Joined: 03 Aug 2001 Posts: 1065 Location: Copenhagen, Denmark
|
|
| Back to top |
|
 |
Dr. Dread Professional Member


Joined: 03 Aug 2001 Posts: 1065 Location: Copenhagen, Denmark
|
Posted: Wed Feb 09, 2005 6:25 pm Post subject: |
|
|
Come to think of it, the VDS Wait command is usually not very precise for this type of timing. If the
actual wait time is say 1.04 secs you will get false results from your maths.
I will try a bit of testing.
Greetz
Dr. Dread _________________ ~~ Alcohol and calculus don't mix... Don't drink and derive! ~~
String.DLL * advanced string processing |
|
| Back to top |
|
 |
Hippo Contributor


Joined: 08 Feb 2005 Posts: 53
|
Posted: Wed Feb 09, 2005 6:35 pm Post subject: |
|
|
Thanks for testing it out
If the VDS command WAIT is a bit slack, then as you say i'll get errors  |
|
| Back to top |
|
 |
jules Professional Member


Joined: 14 Sep 2001 Posts: 1043 Location: Cumbria, UK
|
Posted: Wed Feb 09, 2005 6:55 pm Post subject: |
|
|
The WAIT command cannot be relied upon to be accurate because Windows is a multi-tasking OS and your program may not get control of the CPU at the appointed time. Also, VDS checks the message queue after the execution of every line to allow pending messages to be processed, so the delays can be quite significant if the system is busy.
A more accurate method would probably be to use the GetTickCount API to find out how many hardware timer ticks have elapsed since the last time you got the information. _________________ The Tech Pro
www.tech-pro.net |
|
| Back to top |
|
 |
Dr. Dread Professional Member


Joined: 03 Aug 2001 Posts: 1065 Location: Copenhagen, Denmark
|
Posted: Wed Feb 09, 2005 8:12 pm Post subject: |
|
|
Arrived at the same conclusion
Little tester:
| Code: | external dreadnet.dll
#define function,dnet
option decimalsep,.
LOADLIB kernel32.dll
Title Bandwidth Monitor
DIALOG CREATE,Bandwidth Monitor,-1,0,266,167,ONTOP
DIALOG ADD,STYLE,STYLE1,,,,GREEN,FFFF9B
DIALOG ADD,TEXT,TEXT1,12,12,,,
DIALOG ADD,TEXT,TEXT2,36,12,,,
DIALOG ADD,TEXT,TEXT3,60,12,,,
DIALOG ADD,SCOPE,SCOPE1,80,12,240,80,,,MEDIUM
DIALOG SHOW
goto timer
:Evloop
wait event,0
goto @event()
:TIMER
%%bytesin = @Dnet(Genstats,Infmat)
%%bytesout = @Dnet(Genstats,outfmat)
dialog set,text1,Total Bytes Downloaded %%bytesin
dialog set,text2,Total Bytes Uploaded %%bytesout
%%time_1 = @lib(kernel32,GetTickCount,INT:)
%%TransferredBytes_1 = @Dnet(Genstats,Inbytes)
wait .5
%%time_2 = @lib(kernel32,GetTickCount,INT:)
%%TransferredBytes_2 = @Dnet(Genstats,Inbytes)
%%TransferredBytes = @diff(%%TransferredBytes_2, %%TransferredBytes_1)
%%msecs = @diff(%%time_2,%%time_1)
%%Speed = @fdiv(%%TransferredBytes, @fmul(%%msecs,1.024))
dialog set,text3,Download Speed: @format(%%speed,3.2) kB/s
DIALOG SET,SCOPE1,@format(%%speed,3.0)
goto evloop
:Close
FREELIB kernel32.dll
exit
|
Greetz
Dr. Dread _________________ ~~ Alcohol and calculus don't mix... Don't drink and derive! ~~
String.DLL * advanced string processing |
|
| Back to top |
|
 |
Eddyy Newbie
Joined: 16 Dec 2004 Posts: 9 Location: Puerto Rico, USA
|
Posted: Wed Feb 09, 2005 11:43 pm Post subject: |
|
|
| I'm working on a similar code and I was having the same problem with accuracy using the wait command. I resolved the problem using the @datetime function to get the difference between two times. That way, "5 seconds is always 5 seconds". I also use 5 seconds intervals between reads for extra accuracy. When I compare my final reading with other download monitors they are very close. |
|
| Back to top |
|
 |
Hippo Contributor


Joined: 08 Feb 2005 Posts: 53
|
Posted: Thu Feb 10, 2005 9:18 am Post subject: |
|
|
Thanks for the help guys, I think I've got it licked now  |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You can attach files in this forum You can download files in this forum
|
|