예제 #1
0
def kill(worker,t):
  time.sleep(t)
  print "killing a worker ..."
  worker.stop_server()
예제 #2
0
    contribs = links.join(ranks, [], 'Z').flatMap(lambda LR: [(dest, LR[1] /
      len(LR[0])) for dest in LR[0]])
    ## RDD (url, updated_ranks)
    ranks = contribs.reduceByKey(lambda x, y: x + y, 0).mapValues(lambda s:
      (1 - a) * s).join(damped_ranks, 0, a / N).mapValues(lambda pair: pair[0] + pair[1])
    ranks.execute()
  return ranks

ranks = pagerank(links, seed_ranks, 22)._get_data()
print ranks
correct_ranks = {'A': 0.03278160674806574, 'C': 0.3458609076996311, 'B': 0.3814496256075537, 'E': 0.08088589507077021, 'D': 0.03908723728670415, 'G': 0.016169498060114126, 'F': 0.03908723728670415, 'I': 0.016169498060114126, 'H': 0.016169498060114126, 'K': 0.016169498060114126, 'J': 0.016169498060114126}
print correct_ranks
failed = False
try:
  assert ranks == correct_ranks
except:
  for k,v in correct_ranks.items():
    if ranks[k] - v > epsilon:
      failed = True
      print "value", ranks[k], "of key",k,"is not",v

if failed:
    print "FAIL"
else:
    print "PASS"

print sched.workers

for worker in workers:
  worker.stop_server()