Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Tue 02 Sep 2014, 05:35
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
Need to auto. find the fastest server.
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [7 Posts]  
Author Message
sunburnt


Joined: 08 Jun 2005
Posts: 5016
Location: Arizona, U.S.A.

PostPosted: Sun 24 Feb 2013, 20:26    Post subject:  Need to auto. find the fastest server.  

I`m making a download GUI.
It needs to find the fastest server from a list for the region the PC is in.
This saves the user from having to pick from a long list of servers.

It would be nice to auto. find the region, but it looks difficult to do.
So the user would probably select the region to speed the search.
N. America, S. America, Australia ( Pacific ), Asia, Europe, Africa.

Testing within countries will not find the fastest server in that region.
And the region list is much shorter to pick from than a country list.


# Also... I`m using ping to test speed, but is there a better way to do it?
.
Back to top
View user's profile Send private message 
Karl Godt


Joined: 20 Jun 2010
Posts: 3964
Location: Kiel,Germany

PostPosted: Tue 26 Feb 2013, 08:37    Post subject:  

The country list can be obtained like
Code:
COUNTRIES=`ls -1 /usr/share/locale`
as it does the Puppy code in the setup scripts quicksetup andor rc.country . A reagion list would need a manually brewed and typed database file .
Back to top
View user's profile Send private message Visit poster's website 
L18L

Joined: 19 Jun 2010
Posts: 2505
Location: Burghaslach, Germany somewhere also known as "Hosla"

PostPosted: Tue 26 Feb 2013, 13:56    Post subject: Re: Need to auto. find the fastest server.  

sunburnt wrote:
# Also... I`m using ping to test speed, but is there a better way to do it?.


example:

time wget http://www.taek1do.de
real 0m0.576s
user 0m0.007s
sys 0m0.090s

time ping www.taek1do.de
real 0m2.890s
user 0m0.003s
sys 0m0.007s

wget is more relevant I think.
Back to top
View user's profile Send private message 
vovchik


Joined: 23 Oct 2006
Posts: 1285
Location: Ukraine

PostPosted: Tue 26 Feb 2013, 15:16    Post subject:  

Dear Terry,

Because ping is usually slow, I would try using my bing prog with L18L's timing method:

Code:

' ***********************************************************
' PROGRAM:   bing.bac
' PURPOSE:   to check whether a network connection is alive
' AUTHOR:      Peter van Eerten (network.bac)
' MODDED:    vovchik (Puppy Linux forum)
'          command line argument feature added
' COMMENTS:   http://www.basic-converter.org/network.bac.html         
' DEPENDS:   bash, bacon
' PLATFORM:   Puppy Linux (actually, any *nix)
' DATE:      30-05-2010
' VERSION:   0.1a
' ***********************************************************


' *****************
' DECLARATIONS
' *****************

OPTION SOCKET 1
GLOBAL site$, port$ TYPE STRING
CONST version$ = "0.1a"

' *****************
' END DECLARATIONS
' *****************


' *****************
' SUBROUTINES
' *****************

' ------------
SUB USAGE()
' ------------
   PRINT NL$,"bing - BaCon network check - ", version$,NL$
   PRINT "Usage: bing IP port", NL$
   PRINT "Where:", NL$
   PRINT "  IP   = a site such as 'www.google.com' or"
   PRINT "         an IP address such as '192.168.0.1'"
   PRINT "  port = a TCP/IP port number, such as '80' for http",NL$
   PRINT "Example: bing www.google.com 80", NL$
   END
END SUB

' ------------
SUB GET_ARGS()
' ------------
   SPLIT ARGUMENT$ BY " " TO array$ SIZE argcnt
   IF argcnt < 3 THEN
      USAGE
   ELSE
      IF VAL(array$[2]) > 0 THEN
         site$ = array$[1]
         port$ = array$[2]
      ELSE
         PRINT NL$, "Input arguments contain bad values."
         USAGE
      END IF
   END IF
END SUB

' ------------
SUB SHOW_RESULTS(NUMBER OK)
' ------------
   IF OK THEN
      PRINT NL$, "All OK. Site '", site$, "' is reachable.", NL$
   ELSE
      PRINT NL$, "Site '", site$, "' not reachable! ", ERR$(ERROR), NL$
      END
   END IF
END SUB

' ------------
SUB DNS_INTERRUPT()
' ------------
   PRINT NL$, "That DNS lookup took too long! Exiting...", NL$
   END
END SUB

' *****************
' END SUBROUTINES
' *****************


' *****************
' MAIN
' *****************

GET_ARGS
TRAP LOCAL
CATCH GOTO NETWORK_ERROR
ALARM DNS_INTERRUPT, 2
OPEN CONCAT$(site$, ":", port$) FOR NETWORK AS mynet
CLOSE NETWORK mynet
ALARM DNS_INTERRUPT, 0
SHOW_RESULTS(TRUE)
END

' ------------
LABEL NETWORK_ERROR
' ------------
   SHOW_RESULTS(FALSE)

' *****************
' END MAIN
' *****************


and run bing like this:


Code:

time bing www.google.com 80


perhaps suppressing the bing output.

With kind regards,
vovchik
Back to top
View user's profile Send private message 
sunburnt


Joined: 08 Jun 2005
Posts: 5016
Location: Arizona, U.S.A.

PostPosted: Tue 26 Feb 2013, 21:05    Post subject:  

Thanks guys, a tough subject I`ve found.

Hey Karl Godt; It`s been awhile...
/usr/share/locale has: /en, /en_US, /fi, and: locale.alias => /etc/locale.alias
Dosn`t "fi" = Finland?
I`m not sure of a method to parse the country from this.

L18L; That`s probably much better than using ping. Good idea!

Vovchik; How have you been? This too looks more useful than ping.
I`ll compile it and see how it works, should be like using wget.


I scraped the Ubuntu country mirrors web page and got a text list.
I`ll make a regions list from it, but auto. detecting the country is good.

Still, doing it by regions would better assure getting a good mirror.
Luxembourg, Serbia, Kuwait, and others have only one slow mirror.
.
Back to top
View user's profile Send private message 
vovchik


Joined: 23 Oct 2006
Posts: 1285
Location: Ukraine

PostPosted: Wed 27 Feb 2013, 04:46    Post subject:  

Dear Terry,

This is a little mod for the SHOW_RESULTS sub. It obviates the need to call the external "time" routine:

Code:
' ------------
SUB SHOW_RESULTS(NUMBER OK)
' ------------
   IF OK THEN
      PRINT NL$, "All OK. Site '", site$, "' is reachable."
      PRINT "Elapsed time: ";
      PRINT (float)TIMER/1000 FORMAT "%.3g"
      PRINT " seconds"
   ELSE
      PRINT NL$, "Site '", site$, "' not reachable! ", ERR$(ERROR), NL$
      END
   END IF
END SUB


With kind regards,
vovchik

PS. If some slow-to-respond sites are generating a "non-reachable" error, you could change the timeout setting in the "main" part of the prog as follows:

Code:
ALARM DNS_INTERRUPT, 5


That would give up to 5 seconds for a response from a slow server.
Back to top
View user's profile Send private message 
sunburnt


Joined: 08 Jun 2005
Posts: 5016
Location: Arizona, U.S.A.

PostPosted: Wed 27 Feb 2013, 15:56    Post subject:  

Thanks vovchik, I`ll add the code to bing.

If a web site`s slow responding I think it`s already failed.

And parsing mirrors should be quick or it cuts into download time.
That reason and easy selection for the user is why I like regions.
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 1 [7 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
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 cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0657s ][ Queries: 11 (0.0044s) ][ GZIP on ]