예제 #1
0
    def test_defaults_to_max_workers_and_argv_zero(self):
        worker_count = random.randint(1, 8)
        set_max_workers_count(worker_count)
        service = WorkersService(reactor)

        from maasserver.workers import MAX_WORKERS_COUNT
        self.assertEquals(MAX_WORKERS_COUNT, service.worker_count)
        self.assertEquals(sys.argv[0], service.worker_cmd)
예제 #2
0
파일: server.py 프로젝트: th3architect/maas
def run():
    """Run the maas-regiond master service.

    Spawns children workers up to the number of CPU's minimum is 4 workers.
    """
    args = parse()

    # Remove all the command line arguments, so they don't interfere with
    # the twistd argument parser.
    sys.argv = sys.argv[:1]

    # Workers are spawned with environment so it knows that it would only
    # be a worker.
    if os.environ.get("MAAS_REGIOND_PROCESS_MODE") == "worker":
        # Ignore interrupt on the workers. The master will kill them directly.
        signal.signal(signal.SIGINT, signal.SIG_IGN)
        runWorkerServices()
        return

    # Circular imports.
    from maasserver.workers import set_max_workers_count

    # Debug mode, run the all-in-one mode.
    if args.debug:
        set_max_workers_count(1)
        runAllInOneServices()
        return

    # Calculate the number of workers.
    worker_count = args.workers
    if not worker_count:
        from maasserver.config import RegionConfiguration

        try:
            with RegionConfiguration.open() as config:
                worker_count = config.num_workers
        except Exception:
            worker_count = 4
    if worker_count <= 0:
        raise ValueError("Number of workers must be greater than zero.")

    # Set the maximum number of workers.
    set_max_workers_count(worker_count)

    # Start the master services, which will spawn the required workers.
    runMasterServices()
예제 #3
0
def run():
    """Run the maas-regiond master service.

    Spawns children workers up to the number of CPU's minimum is 4 workers.
    """
    args = parse()

    # Remove all the command line arguments, so they don't interfere with
    # the twistd argument parser.
    sys.argv = sys.argv[:1]

    # Workers are spawned with environment so it knows that it would only
    # be a worker.
    if os.environ.get('MAAS_REGIOND_PROCESS_MODE') == 'worker':
        # Ignore interrupt on the workers. The master will kill them directly.
        signal.signal(signal.SIGINT, signal.SIG_IGN)
        runWorkerServices()
        return

    # Debug mode, run the all-in-one mode.
    if args.debug:
        runAllInOneServices()
        return

    # Calculate the number of workers.
    worker_count = args.workers
    if not worker_count:
        worker_count = os.cpu_count() or 4
        if worker_count < 4:
            worker_count = 4
        # At the moment is is capped at 4 to keep it the same as 2.3. Once
        # the work is done to move the postgres listener and the RPC this
        # should be bumped to 8 workers.
        if worker_count > 4:
            worker_count = 4
    if worker_count <= 0:
        raise ValueError('Number of workers must be greater than zero.')

    # Set the maximum number of workers.
    from maasserver.workers import set_max_workers_count
    set_max_workers_count(worker_count)

    # Start the master services, which will spawn the required workers.
    runMasterServices()
예제 #4
0
    def test_set_max_workers_count(self):
        worker_count = random.randint(1, 8)
        set_max_workers_count(worker_count)
        from maasserver.workers import MAX_WORKERS_COUNT

        self.assertEqual(worker_count, MAX_WORKERS_COUNT)