当前位置: 首页>>代码示例>>Python>>正文


Python util.numCores函数代码示例

本文整理汇总了Python中mininet.util.numCores函数的典型用法代码示例。如果您正苦于以下问题:Python numCores函数的具体用法?Python numCores怎么用?Python numCores使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了numCores函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: cfsInfo

 def cfsInfo( self, f):
     "Internal method: return parameters for CFS bandwidth"
     pstr, qstr = 'cfs_period_us', 'cfs_quota_us'
     # CFS uses wall clock time for period and CPU time for quota.
     quota = int( self.period_us * f * numCores() )
     period = self.period_us
     if f > 0 and quota < 1000:
         debug( '(cfsInfo: increasing default period) ' )
         quota = 1000
         period = int( quota / f / numCores() )
     return pstr, qstr, period, quota
开发者ID:RimHaw,项目名称:mn-ccnx,代码行数:11,代码来源:node.py

示例2: __init__

    def __init__( self, topo=None, switch=OVSKernelSwitch, host=Host,
                  controller=DefaultController, link=Link, intf=Intf,
                  build=True, xterms=False, cleanup=False, ipBase='10.0.0.0/8',
                  inNamespace=False,
                  autoSetMacs=False, autoStaticArp=False, autoPinCpus=False,
                  listenPort=None, waitConnected=False ):
        """Create Mininet object.
           topo: Topo (topology) object or None
           switch: default Switch class
           host: default Host class/constructor
           controller: default Controller class/constructor
           link: default Link class/constructor
           intf: default Intf class/constructor
           ipBase: base IP address for hosts,
           build: build now from topo?
           xterms: if build now, spawn xterms?
           cleanup: if build now, cleanup before creating?
           inNamespace: spawn switches and controller in net namespaces?
           autoSetMacs: set MAC addrs automatically like IP addresses?
           autoStaticArp: set all-pairs static MAC addrs?
           autoPinCpus: pin hosts to (real) cores (requires CPULimitedHost)?
           listenPort: base listening port to open; will be incremented for
               each additional switch in the net if inNamespace=False"""
        self.topo = topo
        self.switch = switch
        self.host = host
        self.controller = controller
        self.link = link
        self.intf = intf
        self.ipBase = ipBase
        self.ipBaseNum, self.prefixLen = netParse( self.ipBase )
        hostIP = ( 0xffffffff >> self.prefixLen ) & self.ipBaseNum
        # Start for address allocation
        self.nextIP = hostIP if hostIP > 0 else 1
        self.inNamespace = inNamespace
        self.xterms = xterms
        self.cleanup = cleanup
        self.autoSetMacs = autoSetMacs
        self.autoStaticArp = autoStaticArp
        self.autoPinCpus = autoPinCpus
        self.numCores = numCores()
        self.nextCore = 0  # next core for pinning hosts to CPUs
        self.listenPort = listenPort
        self.waitConn = waitConnected

        self.hosts = []
        self.switches = []
        self.controllers = []
        self.links = []

        self.nameToNode = {}  # name to Node (Host/Switch) objects

        self.terms = []  # list of spawned xterm processes

        Mininet.init()  # Initialize Mininet if necessary

        self.built = False
        if topo and build:
            self.build()
开发者ID:cihatcetinkaya,项目名称:mininet,代码行数:59,代码来源:net.py

示例3: parseOptions

def parseOptions():
    "Parse command line options"
    parser = OptionParser()
    parser.add_option( '-o', '--output',
        default=True,
        action='store_true',
        help='write output to file?' )
    parser.add_option( '-t', '--time',
        type='int',
        default=10,
        help='cpu-stress time interval' )
    parser.add_option( '-r', '--runs',
        type='int',
        default=1,
        help='Runs for each topo' )
    parser.add_option( '-c', '--counts',
        action='callback',
        callback=intListCallback,
        default=[ 2, 4 ],
        type='string',
        help='nodes in the network, e.g. 2,4' )
    parser.add_option( '-u', '--utils',
        action='callback',
        callback=floatListCallback,
        default=[ 0.5, 0.7, .9 ],
        type='string',
        help='target machine utilizations, e.g. .5,.7,.9' )
    parser.add_option( '-m', '--machine',
        default='local',
        type='string',
        help='name of machine' )
    parser.add_option( '-e', '--experiment',
        default='',
        type='string',
        help='name of experiment' )   
    parser.add_option( '-s', '--static',
        default=False,
        action='store_true',
        help='statically allocate CPU to each host' )
    parser.add_option( '-b', '--bwsched', dest='sched',
                       default='cfs',
                       help='bandwidth scheduler: cfs (default) | rt | none' )
    options, args = parser.parse_args()
    if options.sched not in [ 'cfs', 'rt', 'none' ]:
        print "CPU bandwidth scheduler should be either 'cfs' or 'rt' or 'none'."
        parser.print_help()
        exit( 1 )
    options.host = quietRun( 'hostname' ).strip()
    options.cores = numCores()
    return options, args
开发者ID:EliseuTorres,项目名称:mininet-tests,代码行数:50,代码来源:CPUIsolationSweep.py

示例4: startRamcloud

 def startRamcloud( self, cpu=.6 ):
     """Start Ramcloud
        cpu: CPU usage limit (in seconds/s)"""
     # Create a cgroup so Ramcloud doesn't eat all of our CPU
     ramcloud = CPULimitedHost( 'ramcloud', inNamespace=False, period_us=5000 )
     ramcloud.setCPUFrac( cpu / numCores() )
     info( '\n' )
     ramcloud.cmd( 'export PATH=%s:$PATH' % self.onosDir )
     ramcloud.cmd( 'export ONOS_LOGDIR=%s' % self.logDir )
     for daemon in 'coord', 'server':
         ramcloud.cmd( 'onos.sh rc-%s start' % daemon )
         pid = self.waitStart( 'Ramcloud %s' % daemon, 'obj.master/' + daemon )
         self.waitNetstat( pid )
         status = self.cmd( 'onos.sh rc-%s.sh status' % daemon )
         if 'running' not in status:
             raise Exception( 'Ramcloud %s startup failed: ' % daemon + status )
     self.ramcloud = ramcloud
开发者ID:opennetworkinglab,项目名称:spring-open,代码行数:17,代码来源:onos.py

示例5: appendResults

def appendResults(net, outfile, n, cpu):
    result = [''] * n
    cmd = [None] * n  # Command objects for CPU stressers
    monitor = [None]*n
    monitor_outfile = [None]*n  # Filenames
    cpu_log = [None]*n

    info ("Starting CPU stressors\n")
    # Start cpu-stressers
    for i in xrange(0, n):
        server = net.hosts[i]
        # run for 120 secs extra; terminated below
        scmd = '%s %d %d' % (CPUSTRESS, opts.time+120, 0) 
        server.cmd(scmd + '&')
        monitor_outfile[i] = '/tmp/%s_cpu.out' % server.name
    sleep(1)

    info ("Starting CPU monitor\n")
    # Start cpu monitor
    startTime = int(time())
    cpumon_length = opts.time
    # Was always one second.
    # Now we will try the following: since cpuacct is adjusted every
    # 10 ms, we should try to make sure that each process makes some
    # progress each time interval.
    # for a minimum cpu time of 20 ms,
    # the interval should be 20 ms * n / (cpu% * numCores())
    cpumon_interval = 1.0
    cpumon_min = .020 / cpu / numCores()
    if cpumon_interval < cpumon_min:
        cpumon_interval = cpumon_min
        print "Adjusting cpumon_interval to %.2f seconds" % cpumon_interval
    hosts = ' '.join([h.name for h in net.hosts])
    stats = quietRun('%s %d %f %s' % (CPUMONITOR, cpumon_length, cpumon_interval, hosts))

    info ("Terminating processes\n")
    quietRun( 'pkill -9 -f ' + CPUSTRESS )

    # parse cpu monitor results
    info ("Parsing CPU monitor results\n")
    cpu_usage = parse_cpuacct(stats, cpulimit=cpu)

    appendOutput(outfile, cpu_usage)
开发者ID:EliseuTorres,项目名称:mininet-tests,代码行数:43,代码来源:CPUIsolationSweep.py

示例6: rtInfo

 def rtInfo( self, f ):
     "Internal method: return parameters for RT bandwidth"
     pstr, qstr = 'rt_period_us', 'rt_runtime_us'
     # RT uses wall clock time for period and quota
     quota = int( self.period_us * f * numCores() )
     return pstr, qstr, self.period_us, quota
开发者ID:RimHaw,项目名称:mn-ccnx,代码行数:6,代码来源:node.py

示例7: __init__

    def __init__( self, topo=None, switch=OVSKernelSwitch,
                  legacySwitch=LegacySwitch, hostInterface=HostInterface,
                  legacyRouter=QuaggaRouter,
                  transitPortalRouter=TransitPortalRouter,
                  host=Host, controller=Controller, link=Link, intf=Intf,
                  build=True, xterms=False, cleanup=False, ipBase='10.0.0.0/8',
                  inNamespace=False,
                  autoSetMacs=False, autoStaticArp=False, autoPinCpus=False,
                  listenPort=None, bridgeNum=0, defaultHostInterfaceBind='eth0'):
        """Create Mininet object.
           topo: Topo (topology) object or None
           switch: default Switch class
           host: default Host class/constructor
           controller: default Controller class/constructor
           link: default Link class/constructor
           intf: default Intf class/constructor
           ipBase: base IP address for hosts,
           build: build now from topo?
           xterms: if build now, spawn xterms?
           cleanup: if build now, cleanup before creating?
           inNamespace: spawn switches and controller in net namespaces?
           autoSetMacs: set MAC addrs automatically like IP addresses?
           autoStaticArp: set all-pairs static MAC addrs?
           autoPinCpus: pin hosts to (real) cores (requires CPULimitedHost)?
           listenPort: base listening port to open; will be incremented for
               each additional switch in the net if inNamespace=False"""
        self.topo = topo
        self.switch = switch
        self.legacySwitch = legacySwitch
        self.hostInterface = hostInterface
        self.legacyRouter = legacyRouter
        self.transitPortalRouter = transitPortalRouter
        self.host = host
        self.controller = controller
        self.link = link
        self.intf = intf
        self.ipBase = ipBase
        self.ipBaseNum, self.prefixLen = netParse( self.ipBase )
        self.nextIP = 1  # start for address allocation
        self.inNamespace = inNamespace
        self.xterms = xterms
        self.cleanup = cleanup
        self.autoSetMacs = autoSetMacs
        self.autoStaticArp = autoStaticArp
        self.autoPinCpus = autoPinCpus
        self.numCores = numCores()
        self.nextCore = 0  # next core for pinning hosts to CPUs
        self.listenPort = listenPort
        self.bridgeNum = bridgeNum
        self.defaultHostInterfaceBind = defaultHostInterfaceBind

        self.hosts = []
        self.switches = []
        self.legacySwitches = []
        self.hostInterfaces = []
        self.legacyRouters = []
        self.transitPortalRouters = []
        self.controllers = []

        self.nameToNode = {}  # name to Node (Host/Switch/hostInterface/legacy(Router,Switch)) objects
        self.physicalAdaptersBridged = [] # physical adapters connected to a (any) bridge
        self.bridgeInterfaces = [] # instantiated bridges

        self.terms = []  # list of spawned xterm processes

        Mininet.init()  # Initialize Mininet if necessary

        self.built = False
        if topo and build:
            self.build()
开发者ID:aimonb,项目名称:miniNeXT,代码行数:70,代码来源:net.py

示例8: parse_cpuacct

def parse_cpuacct(stats, cpulimit=None):
    '''Return the following:
        cpu_usage[n], with each element a dict{'xvals':[], 'cpuvals':[]}
        cpu_stat[n] with each element a dict{'xvals':[], 'uservals': [], 'systemvals': []}
        '''
    cpu_usage = {}

    rec_re = re.compile(r'cgroup (\S+),time (\d+.\d+)')
    spaces = re.compile('\s+')

    host = None
    time = None

    # Report CPU limit in CPU seconds rather than as a fraction (!)
    cores = numCores()
    cpulimit *= cores

    for line in stats.split('\n'):
        m = rec_re.match(line)
        if m:
            host = m.group(1)
            time = float(m.group(2))
        else:
            line = spaces.sub( ' ', line ).split()
            if 'usage' in line:
                cpuval = float(line[1])
                if host is None or time is None:
                    continue
                if host not in cpu_usage:
                    cpu_usage[host] = {'xvals':[], 'cpuvals':[], 'uservals':[],
                     'systemvals':[], 'percpuvals':[], 'cpulimit': cpulimit }
                cpu_usage[host]['xvals'].append(time)
                cpu_usage[host]['cpuvals'].append(cpuval)

            elif 'user' in line:
                userval = float(line[1])
                if host is None or time is None:
                    continue
                cpu_usage[host]['uservals'].append(userval)

            elif 'system' in line:
                systemval = float(line[1])
                if host is None or time is None:
                    continue
                cpu_usage[host]['systemvals'].append(systemval)
            elif 'percpu' in line:
                percpuval = map(float, line[1:])
                if host is None or time is None:
                    continue
                cpu_usage[host]['percpuvals'].append(percpuval)

    # Round results to reported (though not necessarily actual) accuracy (ns, HZ)
    def r9(x):
        return round(x,9)
    def r2(x):
        return round(x,2)

    for k,v in cpu_usage.iteritems():
        intervals = diff_list(v['xvals'])
        v['xvals'] = [r9(x - v['xvals'][0]) for x in v['xvals']]
        v['xvals'].pop(0)
        v['cpuvals'] = [r9(1e-9*x/y) for x, y in zip(diff_list(v['cpuvals']), intervals)]
        v['uservals'] = [r2(1e-2*x/y) for x, y in zip(diff_list(v['uservals']), intervals)]
        v['systemvals'] = [r2(1e-2*x/y) for x, y in zip(diff_list(v['systemvals']), intervals)]
        v['percpuvals'] = [[r9(1e-9*x/y) for x in l] 
                           for l, y in zip(double_diff_list(v['percpuvals']), intervals)]
        v['cpucount'] = cores

    return [cpu_usage[k] for k in sorted(cpu_usage.keys(), key=natural)]
开发者ID:EliseuTorres,项目名称:mininet-tests,代码行数:69,代码来源:CPUIsolationLib.py

示例9: quietRun

    nodea.cmdPrint('route -n')
    nodeb.cmdPrint('route -n')
    print "*** starting sshd servers"
    for host in net.hosts:
        host.name, host.IP()
        host.cmdPrint('/usr/sbin/sshd')
    print "*** checking ping and ssh connectivity"
    net.pingAll()
    print "*** fixing local route on nodea"
    nodea.cmdPrint("ifconfig lo up")
    nodea.cmdPrint("ping -c1 " + nodea.IP() )
    for suffix in 'ABCDEFGHIJ':
        nodea.cmdPrint( 'ssh node-' + suffix + ' hostname')
    print "*** running test"
    host = quietRun('hostname').strip()
    cores = numCores()
    outfile = "emulab-%s-%sp-%s-%s-%s.out" % ( host, cores, sched, cpu, fastbw)
    nodea.cmdPrint("./emulab-test.sh  2>&1 | tee %s; echo done" % outfile)
    print "stopping sshd servers"
    for host in net.hosts:
        host.cmdPrint('pkill -9 -f /usr/sbin/sshd')
    net.stop()

if __name__ == '__main__':
    setLogLevel( 'info' )
    targetbw=200
    targetcpu=.09
    run( sched='cfs', cpu=targetcpu, fastbw=targetbw )
    run( sched='cfs', cpu=targetcpu, fastbw=None )
    run( sched='none', cpu=None, fastbw=targetbw )
    run( sched='none', cpu=None, fastbw=None, lanbw=None )
开发者ID:EliseuTorres,项目名称:mininet-tests,代码行数:31,代码来源:emulab-test.py


注:本文中的mininet.util.numCores函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。