mirror of
https://github.com/docker/compose.git
synced 2025-07-26 07:04:32 +02:00
Merge pull request #5751 from mnottale/cpu_period
Add support for 'cpu_period' for compose v2.1-v2.3.
This commit is contained in:
commit
85670e208b
@ -67,6 +67,7 @@ DOCKER_CONFIG_KEYS = [
|
|||||||
'command',
|
'command',
|
||||||
'cpu_count',
|
'cpu_count',
|
||||||
'cpu_percent',
|
'cpu_percent',
|
||||||
|
'cpu_period',
|
||||||
'cpu_quota',
|
'cpu_quota',
|
||||||
'cpu_shares',
|
'cpu_shares',
|
||||||
'cpus',
|
'cpus',
|
||||||
|
@ -106,6 +106,7 @@
|
|||||||
"container_name": {"type": "string"},
|
"container_name": {"type": "string"},
|
||||||
"cpu_shares": {"type": ["number", "string"]},
|
"cpu_shares": {"type": ["number", "string"]},
|
||||||
"cpu_quota": {"type": ["number", "string"]},
|
"cpu_quota": {"type": ["number", "string"]},
|
||||||
|
"cpu_period": {"type": ["number", "string"]},
|
||||||
"cpuset": {"type": "string"},
|
"cpuset": {"type": "string"},
|
||||||
"depends_on": {
|
"depends_on": {
|
||||||
"oneOf": [
|
"oneOf": [
|
||||||
|
@ -110,6 +110,7 @@
|
|||||||
"cpu_percent": {"type": "integer", "minimum": 0, "maximum": 100},
|
"cpu_percent": {"type": "integer", "minimum": 0, "maximum": 100},
|
||||||
"cpu_shares": {"type": ["number", "string"]},
|
"cpu_shares": {"type": ["number", "string"]},
|
||||||
"cpu_quota": {"type": ["number", "string"]},
|
"cpu_quota": {"type": ["number", "string"]},
|
||||||
|
"cpu_period": {"type": ["number", "string"]},
|
||||||
"cpus": {"type": "number", "minimum": 0},
|
"cpus": {"type": "number", "minimum": 0},
|
||||||
"cpuset": {"type": "string"},
|
"cpuset": {"type": "string"},
|
||||||
"depends_on": {
|
"depends_on": {
|
||||||
|
@ -113,6 +113,7 @@
|
|||||||
"cpu_percent": {"type": "integer", "minimum": 0, "maximum": 100},
|
"cpu_percent": {"type": "integer", "minimum": 0, "maximum": 100},
|
||||||
"cpu_shares": {"type": ["number", "string"]},
|
"cpu_shares": {"type": ["number", "string"]},
|
||||||
"cpu_quota": {"type": ["number", "string"]},
|
"cpu_quota": {"type": ["number", "string"]},
|
||||||
|
"cpu_period": {"type": ["number", "string"]},
|
||||||
"cpus": {"type": "number", "minimum": 0},
|
"cpus": {"type": "number", "minimum": 0},
|
||||||
"cpuset": {"type": "string"},
|
"cpuset": {"type": "string"},
|
||||||
"depends_on": {
|
"depends_on": {
|
||||||
|
@ -10,6 +10,7 @@ import six
|
|||||||
from .errors import ConfigurationError
|
from .errors import ConfigurationError
|
||||||
from compose.const import COMPOSEFILE_V2_0 as V2_0
|
from compose.const import COMPOSEFILE_V2_0 as V2_0
|
||||||
from compose.utils import parse_bytes
|
from compose.utils import parse_bytes
|
||||||
|
from compose.utils import parse_nanoseconds_int
|
||||||
|
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
@ -223,6 +224,12 @@ def bytes_to_int(s):
|
|||||||
return v
|
return v
|
||||||
|
|
||||||
|
|
||||||
|
def to_microseconds(v):
|
||||||
|
if not isinstance(v, six.string_types):
|
||||||
|
return v
|
||||||
|
return int(parse_nanoseconds_int(v) / 1000)
|
||||||
|
|
||||||
|
|
||||||
class ConversionMap(object):
|
class ConversionMap(object):
|
||||||
map = {
|
map = {
|
||||||
service_path('blkio_config', 'weight'): to_int,
|
service_path('blkio_config', 'weight'): to_int,
|
||||||
@ -230,6 +237,8 @@ class ConversionMap(object):
|
|||||||
service_path('build', 'labels', FULL_JOKER): to_str,
|
service_path('build', 'labels', FULL_JOKER): to_str,
|
||||||
service_path('cpus'): to_float,
|
service_path('cpus'): to_float,
|
||||||
service_path('cpu_count'): to_int,
|
service_path('cpu_count'): to_int,
|
||||||
|
service_path('cpu_quota'): to_microseconds,
|
||||||
|
service_path('cpu_period'): to_microseconds,
|
||||||
service_path('configs', 'mode'): to_int,
|
service_path('configs', 'mode'): to_int,
|
||||||
service_path('secrets', 'mode'): to_int,
|
service_path('secrets', 'mode'): to_int,
|
||||||
service_path('healthcheck', 'retries'): to_int,
|
service_path('healthcheck', 'retries'): to_int,
|
||||||
|
@ -62,6 +62,7 @@ HOST_CONFIG_KEYS = [
|
|||||||
'cgroup_parent',
|
'cgroup_parent',
|
||||||
'cpu_count',
|
'cpu_count',
|
||||||
'cpu_percent',
|
'cpu_percent',
|
||||||
|
'cpu_period',
|
||||||
'cpu_quota',
|
'cpu_quota',
|
||||||
'cpu_shares',
|
'cpu_shares',
|
||||||
'cpus',
|
'cpus',
|
||||||
@ -947,6 +948,7 @@ class Service(object):
|
|||||||
device_write_iops=blkio_config.get('device_write_iops'),
|
device_write_iops=blkio_config.get('device_write_iops'),
|
||||||
mounts=options.get('mounts'),
|
mounts=options.get('mounts'),
|
||||||
device_cgroup_rules=options.get('device_cgroup_rules'),
|
device_cgroup_rules=options.get('device_cgroup_rules'),
|
||||||
|
cpu_period=options.get('cpu_period'),
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_secret_volumes(self):
|
def get_secret_volumes(self):
|
||||||
|
@ -122,10 +122,11 @@ class ServiceTest(DockerClientTestCase):
|
|||||||
assert container.get('HostConfig.CpuShares') == 73
|
assert container.get('HostConfig.CpuShares') == 73
|
||||||
|
|
||||||
def test_create_container_with_cpu_quota(self):
|
def test_create_container_with_cpu_quota(self):
|
||||||
service = self.create_service('db', cpu_quota=40000)
|
service = self.create_service('db', cpu_quota=40000, cpu_period=150000)
|
||||||
container = service.create_container()
|
container = service.create_container()
|
||||||
container.start()
|
container.start()
|
||||||
assert container.get('HostConfig.CpuQuota') == 40000
|
assert container.get('HostConfig.CpuQuota') == 40000
|
||||||
|
assert container.get('HostConfig.CpuPeriod') == 150000
|
||||||
|
|
||||||
@v2_2_only()
|
@v2_2_only()
|
||||||
def test_create_container_with_cpu_count(self):
|
def test_create_container_with_cpu_count(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user