forum.vdsworld.com Forum Index forum.vdsworld.com
Visit VDSWORLD.com
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Help with Download Speed code using dreadnet.dll

 
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> General Help
View previous topic :: View next topic  
Author Message
Hippo
Contributor
Contributor


Joined: 08 Feb 2005
Posts: 53

PostPosted: Wed Feb 09, 2005 11:14 am    Post subject: Help with Download Speed code using dreadnet.dll Reply with quote

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
View user's profile Send private message
Hooligan
VDS Developer
VDS Developer


Joined: 28 Oct 2003
Posts: 480
Location: California

PostPosted: Wed Feb 09, 2005 4:01 pm    Post subject: Reply with quote

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
View user's profile Send private message
Dr. Dread
Professional Member
Professional Member


Joined: 03 Aug 2001
Posts: 1065
Location: Copenhagen, Denmark

PostPosted: Wed Feb 09, 2005 5:54 pm    Post subject: Reply with quote

Hi!

At first glance I cannot see why it should fail. I use Windows' Management Information Base API to
plug into Win network stats.

You can read more here, if you're interested:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/mib/mib/mib_structures.asp

The numbers you get are retrieved from there.

Greetz
Dr. Dread

_________________
~~ Alcohol and calculus don't mix... Don't drink and derive! ~~

String.DLL * advanced string processing
Back to top
View user's profile Send private message
Dr. Dread
Professional Member
Professional Member


Joined: 03 Aug 2001
Posts: 1065
Location: Copenhagen, Denmark

PostPosted: Wed Feb 09, 2005 6:25 pm    Post subject: Reply with quote

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
View user's profile Send private message
Hippo
Contributor
Contributor


Joined: 08 Feb 2005
Posts: 53

PostPosted: Wed Feb 09, 2005 6:35 pm    Post subject: Reply with quote

Thanks for testing it out Smile

If the VDS command WAIT is a bit slack, then as you say i'll get errors Sad
Back to top
View user's profile Send private message
jules
Professional Member
Professional Member


Joined: 14 Sep 2001
Posts: 1043
Location: Cumbria, UK

PostPosted: Wed Feb 09, 2005 6:55 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
Dr. Dread
Professional Member
Professional Member


Joined: 03 Aug 2001
Posts: 1065
Location: Copenhagen, Denmark

PostPosted: Wed Feb 09, 2005 8:12 pm    Post subject: Reply with quote

Arrived at the same conclusion Wink

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
View user's profile Send private message
Eddyy
Newbie


Joined: 16 Dec 2004
Posts: 9
Location: Puerto Rico, USA

PostPosted: Wed Feb 09, 2005 11:43 pm    Post subject: Reply with quote

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
View user's profile Send private message
Hippo
Contributor
Contributor


Joined: 08 Feb 2005
Posts: 53

PostPosted: Thu Feb 10, 2005 9:18 am    Post subject: Reply with quote

Thanks for the help guys, I think I've got it licked now Smile
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> General Help All times are GMT
Page 1 of 1

 
Jump to:  
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

Twitter@vdsworld       RSS

Powered by phpBB © 2001, 2005 phpBB Group