/simulator/plot_topo.py

https://bitbucket.org/hilfialkaff/tomography
Python | 62 lines | 48 code | 11 blank | 3 comment | 5 complexity | 05118f7f66f4f2b8c6454bfe6ed3804f MD5 | raw file
  1. from manager import Manager
  2. from topology import JellyfishTopology, Jellyfish2Topology, FatTreeTopology
  3. from algorithm import * # pyflakes_bypass
  4. CONFIG_NAME = 'config'
  5. BANDWIDTH = 100000 # 100 MBps link
  6. num_jobs = [] # Number of jobs to run in the cluster from the traces
  7. num_ports = [] # Number of ports in the topology
  8. num_hosts = [] # Number of host nodes in the topology
  9. ft_num_hosts = [] # Number of host nodes in fat-tree topology
  10. num_switches = [] # Number of switches in the topology
  11. num_mr = [] # Number of maps/reducers
  12. cpu = [] # Number of CPU cores/machine
  13. mem = [] # GB of RAM/machine
  14. def read_config():
  15. global num_jobs, num_ports, num_hosts, ft_num_hosts, num_switches, \
  16. num_mr, cpu, mem
  17. def _read_config():
  18. line = f.readline()
  19. return [int(_) for _ in line.split(' ')[1:]]
  20. f = open(CONFIG_NAME)
  21. num_jobs = _read_config()
  22. num_ports = _read_config()
  23. num_hosts = _read_config()
  24. ft_num_hosts = _read_config()
  25. num_switches = _read_config()
  26. num_mr = _read_config()
  27. cpu = _read_config()
  28. mem = _read_config()
  29. f.close()
  30. def plot_topo():
  31. # Jellyfish
  32. for num_port, num_host, num_switch in zip(num_ports, num_hosts, num_switches):
  33. topo = JellyfishTopology(BANDWIDTH, num_host, num_switch, num_port)
  34. mgr = Manager(topo, algorithm, Algorithm.K_PATH, deepcopy(jobs), 1, 1)
  35. mgr.graph.plot("jf_" + str(num_port))
  36. mgr.clean_up()
  37. # Modified jellyfish
  38. for num_port, num_host, num_switch in zip(num_ports, num_hosts, num_switches):
  39. topo = Jellyfish2Topology(BANDWIDTH, num_host, num_switch, num_port)
  40. mgr = Manager(topo, algorithm, Algorithm.K_PATH, deepcopy(jobs), 1, 1)
  41. mgr.graph.plot("jf2_" + str(num_port))
  42. mgr.clean_up()
  43. # Fat-Tree
  44. for i, num_host in zip(num_ports, ft_num_hosts):
  45. topo = FatTreeTopology(BANDWIDTH, i)
  46. mgr = Manager(topo, algorithm, Algorithm.FLOYD_WARSHALL, deepcopy(jobs), 1, 1)
  47. mgr.graph.plot("ft_" + str(i))
  48. mgr.clean_up()
  49. if __name__ == '__main__':
  50. read_config()
  51. plot_topo()