Skip to content

Commit

Permalink
[dvs] Add options to limit CPU usage (sonic-net#1394)
Browse files Browse the repository at this point in the history
Signed-off-by: Danny Allen <daall@microsoft.com>
  • Loading branch information
daall authored Aug 12, 2020
1 parent 36fe710 commit b9146b9
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 7 deletions.
12 changes: 12 additions & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,18 @@ For those developing new features for SWSS or the DVS framework, you might find
```

## Other useful test parameters
- You can specify a maximum amount of cores for the DVS to use (we recommend 2):
```
sudo pytest --max_cpu 2
```

For a persistent DVS:
```
docker run --privileged -v /var/run/redis-vs/sw:/var/run/redis --network container:sw -d --name vs --cpus 2 docker-sonic-vs
```

For specific details about the performance impact of this, see [the Docker docs.](https://docs.docker.com/config/containers/resource_constraints/#configure-the-default-cfs-scheduler)

- You can see the output of all test cases that have been run by adding the verbose flag:

```
Expand Down
30 changes: 23 additions & 7 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ def pytest_addoption(parser):
help="keep testbed after test")
parser.addoption("--imgname", action="store", default="docker-sonic-vs",
help="image name")
parser.addoption("--max_cpu",
action="store",
default=2,
type=int,
help="Max number of CPU cores to use, if available. (default = 2)")


class AsicDbValidator(DVSDatabase):
Expand Down Expand Up @@ -158,7 +163,15 @@ class DockerVirtualSwitch(object):
FLEX_COUNTER_DB_ID = 5
STATE_DB_ID = 6

def __init__(self, name=None, imgname=None, keeptb=False, fakeplatform=None, log_path=None):
def __init__(
self,
name=None,
imgname=None,
keeptb=False,
fakeplatform=None,
log_path=None,
max_cpu=2
):
self.basicd = ['redis-server',
'rsyslogd']
self.swssd = ['orchagent',
Expand Down Expand Up @@ -243,10 +256,13 @@ def __init__(self, name=None, imgname=None, keeptb=False, fakeplatform=None, log
self.environment = ["fake_platform={}".format(fakeplatform)] if fakeplatform else []

# create virtual switch container
self.ctn = self.client.containers.run(imgname, privileged=True, detach=True,
environment=self.environment,
network_mode="container:%s" % self.ctn_sw.name,
volumes={ self.mount: { 'bind': '/var/run/redis', 'mode': 'rw' } })
self.ctn = self.client.containers.run(imgname,
privileged=True,
detach=True,
environment=self.environment,
network_mode=f"container:{self.ctn_sw.name}",
volumes={self.mount: {"bind": "/var/run/redis", "mode": "rw"}},
cpu_count=max_cpu)

self.redis_sock = self.mount + '/' + "redis.sock"

Expand Down Expand Up @@ -973,11 +989,11 @@ def dvs(request) -> DockerVirtualSwitch:
name = request.config.getoption("--dvsname")
keeptb = request.config.getoption("--keeptb")
imgname = request.config.getoption("--imgname")
max_cpu = request.config.getoption("--max_cpu")
fakeplatform = getattr(request.module, "DVS_FAKE_PLATFORM", None)

log_path = name if name else request.module.__name__

dvs = DockerVirtualSwitch(name, imgname, keeptb, fakeplatform, log_path)
dvs = DockerVirtualSwitch(name, imgname, keeptb, fakeplatform, log_path, max_cpu)

yield dvs

Expand Down

0 comments on commit b9146b9

Please sign in to comment.