Exemple #1
0
    signal.signal(signal.SIGINT,  _termination_handler)
    signal.signal(signal.SIGTERM, _termination_handler)

    pid = -1
    def in_my_cgroup():
        """
          Function to add new process into the cgroup
        """
        pid = os.getpid()
        cg = Cgroup('level_400')
        cg.add_task(pid)

    # Create a cgroup called "level_400", set the CPU limit to 50%, which is one core
    cg = Cgroup('level_400')
    cg.set_shares(2)
    cg.set_cores(2)

    # Set the max PID's to 10
    cg.set_max_pids(10)

    # Create a process and add it to the cgroup
    p1 = subprocess.Popen(["/bin/sysbench",
                           "--test=cpu",
                           "--cpu-max-prime=1000000000",
                           "--num-threads=1",
                           "--max-time=20",
                           "--forced-shutdown=0",
                           "run"],
                           stderr=DEVNULL,
                           stdout=DEVNULL,
                           preexec_fn=in_my_cgroup)
Exemple #2
0
    signal.signal(signal.SIGTERM, _termination_handler)

    pid = -1

    def in_my_cgroup():
        """
          Function to add new process into the cgroup
        """
        pid = os.getpid()
        cg = Cgroup('level_102')
        cg.add_task(pid)

    # Create a cgroup called "level_102", set the CPU limit to 50%, which is one core
    cg = Cgroup('level_102')
    cg.set_shares(1)
    cg.set_cores(1)

    # Create a process and add it to the cgroup
    p1 = subprocess.Popen([
        helpers.sysbench(), "--test=cpu", "--cpu-max-prime=1000000000",
        "--num-threads=2", "--max-time=300", "--forced-shutdown=0", "run"
    ],
                          stderr=DEVNULL,
                          stdout=DEVNULL,
                          preexec_fn=in_my_cgroup)

    # Run the monitoring loop, report every 60 seconds
    while True:
        print collect_cpu("level_102")
        time.sleep(10)