Skip to content

k3cgrouparch

Action-CI Documentation Status Package

Set up cgroup directory tree according to configuration saved in zookeeper, and add pid to cgroup accordingly.

k3cgrouparch is a component of pykit3 project: a python3 toolkit set.

Installation

pip install k3cgrouparch

Quick Start

manager.run() reads the cgroup tree from the ZooKeeper node <zk_prefix>/arch_conf and builds it under cgroup_dir. Then it keeps adding the pids in each cgroup's pid files to that cgroup, and never returns.

from k3cgrouparch import manager


def get_cgroup_pid_file(cgroup_name):
    if cgroup_name == "test_cgroup_a":
        return ["/tmp/test.pid"]
    # ...


def get_zk_host():
    return "127.0.0.1:2181,1.2.3.4:2181"


argkv = {
    "cgroup_dir": "/sys/fs/cgroup",
    "get_cgroup_pid_file": get_cgroup_pid_file,
    "get_zk_host": get_zk_host,
    "zk_prefix": "/cluster_a/service_rank",
    "zk_auth_data": [("digest", "super:123456")],
    "communicate_ip": "127.0.0.1",
    "communicate_port": 3344,
    "redis_ip": "127.0.0.1",
    "redis_port": 6379,
}

manager.run(**argkv)

manager.get_cgexec_arg() builds the same tree and returns the cgexec arguments of each cgroup. This example reads the tree {"cpu": {"sub_cgroup": {"test_cgroup_a": {"conf": {"share": 1024}}}}}:

argkv = {
    "cgroup_dir": "/sys/fs/cgroup",
    "get_zk_host": get_zk_host,
    "zk_prefix": "/cluster_a/service_rank",
    "zk_auth_data": [("digest", "super:123456")],
}
cgexec_arg = manager.get_cgexec_arg(["test_cgroup_a"], **argkv)
# {"test_cgroup_a": " -g cpu:/test_cgroup_a"}

API Reference

k3cgrouparch

Name

cgrouparch

A python lib used to build cgroup directory tree, add set cgroup pid.

Status

This library is considered production ready.

It supports only cgroup v1. It manages the cpu and blkio subsystems in <cgroup_dir>/<subsystem>, such as /sys/fs/cgroup/cpu. It uses v1 files such as cpu.shares, blkio.weight and tasks. A host that mounts only the cgroup v2 unified hierarchy has none of these files.

Description

This lib is used to set up cgroup directory tree according to configuration saved in zookeeper, and add pid to cgroup accordingly.

License

The MIT License (MIT) - Copyright (c) 2015 Zhang Yanpo (张炎泼)