[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: download problem



Matt Domsch wrote:
On Thu, May 15, 2008 at 10:04:51PM +1200, Nigel Jones wrote:
subhodip biswas wrote:
hi !
while trying to download F9 what I face is quite frustrating ..in fact
this can be faced by a lot of user in India .
while  wbut mirror is down (temporarily ) and other cannot handle all
the load and bit torrent is quite slow .
clicking on i386 direct download always gives error 412 : too many
connected users .
any way of avoiding this .. I am currently downloading from a mirror
in USA and its quite slow.

Hi,

Going from what I know (someone might want to update me here):
We currently only have 3 mirrors in India (http://mirrors.fedoraproject.org/), one is on a 45mbps link, while the other two are on 5mbps and 2mbps links.

One thing MM would benefit from would be a weighted sampler.

Right now, it collects various lists of Hosts to return (same
netblock, same country, same continent, global). It shuffles (python random.shufle()) each of
the lists, then concatenates them, and sends that result to the end
user.  However, this does not take into account that one mirror has a
45Mbps link, and another a 2Mbps; they would each get chosen
"randomly".

What I need is a replacement for random.shuffle() that takes a list of
tuples: (something, weight).  And returns a list of somethings that
was generated with a statistical sampling based on weight.

Now, this is _probably_ a simple thing to do; my college number theory
professor would mock me for having not "just done it" myself, but hey
- I took that class _twice_ before passing it - I don't trust my
skills in this area to get it right.

Volunteers?



Perhaps something like the attached test program. I am new to python so be gentle.

--
	kr
#!/usr/bin/python

# comparison function for use by list.sort to sort elements based on the second
# element of the tuples
# first and second should be two element tuples with an integer weight being 
# the second element of each
def rev_weighted_tuple_cmp(first, second):

   # if first tuple is greater than the second	
   if first[1] > second[1]:
      return -1

   # if the tuples are equal	
   elif first[1] == second[1]:
      return 0

   # if the first tuple is less than the second
   else:
      return 1

# function to return a list from a list of weighted tuples 
# list_of_tuples should be a list of two element tuples of which the second 
# element is an integer weight
# returns a list of elements which are the first elements of each tuple. the
# list is sorted in descending order based on the weighting
def weighted_list(list_of_tuples):

   # sort the list of tuples based on the weight
   list_of_tuples.sort(rev_weighted_tuple_cmp)

   # build the return list of just the first elements
   # initialize the list with first element
   ret_list = [list_of_tuples[0][0]]
  
   # start the index at one since we already added the first element
   index = 1

   # add the remaining elements
   while index < len(list_of_tuples):
      ret_list.append(list_of_tuples[index][0])
      index = index+1

   # return the list
   return ret_list


# test tuples
a = ('test1.fedoraproject.org',30)
b = ('test2.fedoraproject.org',5)
c = ('test3.fedoraproject.org',45)
d = ('test4.fedoraproject.org',10)

# test list of tuples
l = [a,b,c,d,a,b,c,d]
print l

# create new list
new_list = weighted_list(l)
print new_list

   

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]