Martin T
11/04/2021, 1:27 PMhost_config
to our DockerRun
config:
flow.storage = Docker(
registry_url=...,
image_name=...,
files={...},
env_vars={...},
python_dependencies=[...]
)
client = docker.APIClient()
host_config = client.create_host_config(mem_limit=12345,
mem_reservation=1234
)
flow.run_config = DockerRun(host_config=host_config)
flow.executor = LocalDaskExecutor()
When registered to Cloud, this seems to be ok, since starting a Run shows the following default in Host Config:
{
"Memory": 12345,
"MemoryReservation": 1234
}
However, this seems to have no effect on the the newly created flow containers.
docker stats
show that MEM USAGE keeps growing and a LIMIT that equals the total server memory.
docker inspect <CONTAINER> | grep \"Memory[\"R]
gives
"Memory": 0,
"MemoryReservation": 0,
What are we missing here?Anna Geller
from prefect.run_configs import DockerRun
run_config = DockerRun(host_config=dict(mem_limit=12345))
more info:
• https://docs.prefect.io/api/latest/run_configs.html#dockerrun
• https://docker-py.readthedocs.io/en/stable/api.html#docker.api.container.ContainerApiMixin.create_host_configMartin T
11/04/2021, 1:34 PMMartin T
11/04/2021, 1:35 PMMartin T
11/04/2021, 1:35 PMAnna Geller
mem_limit
should be usedAnna Geller
Martin T
11/04/2021, 1:40 PMflow.executor = LocalDaskExecutor()
as listed aboveAnna Geller
run_config = DockerRun(host_config=dict(mem_limit=12345))
I was asking about executor, because you can limit the resources by specifying fewer workers e.g.
flow.executor = LocalDaskExecutor(scheduler="processes", num_workers=2)
Does it make sense to set limits on the executor rather than flow? Are you setting this because your flow is running out of memory?Martin T
11/04/2021, 1:51 PMrun_config
again, still no luck. I've also tried `LocalExecutor()`to ensure this is not a Dask issue.Martin T
11/04/2021, 1:55 PMmem_limit
and mem_reservation
is suited for our needs.
(num_workers
(for dask) and/or Cloud concurrency limits for Flows/Tasks won't help us because number of tasks is not proportional to the workloads of individual runs.)Anna Geller
mem_limit
as string e.g. host_config=dict(mem_limit="128m")
?Martin T
11/04/2021, 2:00 PMMartin T
11/04/2021, 2:02 PMAnna Geller
Martin T
11/04/2021, 2:04 PMKevin Kho
pip show docker
? I just noticed mem_reservation
was added in 4.3.1. mem_limit
should work though. But the version will help me be sure.Martin T
11/04/2021, 3:14 PMpip show docker
= 5.0.3
locally where i build deploy... (?)Kevin Kho
Kevin Kho
"Memory": 1073741824,
"MemoryReservation": 12345678,
Kevin Kho
Martin T
11/04/2021, 6:06 PMdocker stats
to find the new autogenerated container name (all other container have specific names). Then docker inspect <CONTAINER> | grep
gives:
"Memory": 0,
"MemoryReservation": 0,
Here is the server docker version you mentioned (if relevant):
[server]$ docker exec -it prefect-docker-agent-xyz /bin/bash
root@970eb27929c5:/# pip show docker
Name: docker
Version: 4.4.4
and the flow container:
[server]$ docker exec -it brave_bardeen /bin/bash
root@5f8a37ed4886:/# pip show docker
Name: docker
Version: 5.0.2
Kevin Kho
docker version
?Kevin Kho
Martin T
11/05/2021, 6:51 AM[server]$ cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)
[server]$ docker version
Client: Docker Engine - Community
Version: 20.10.7
API version: 1.41
Go version: go1.13.15
Git commit: f0df350
Built: Wed Jun 2 11:58:10 2021
OS/Arch: linux/amd64
Context: default
Experimental: true
Server: Docker Engine - Community
Engine:
Version: 20.10.7
API version: 1.41 (minimum version 1.12)
Go version: go1.13.15
Git commit: b0f5bc3
Built: Wed Jun 2 11:56:35 2021
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.4.6
GitCommit: d71fcd7d8303cbf684402823e425e9dd2e99285d
runc:
Version: 1.0.0-rc95
GitCommit: b9ee9c6314599f1b4a7f497e1f1f856fe433d3b7
docker-init:
Version: 0.19.0
GitCommit: de40ad0
$ docker inspect prefect-docker-agent-for-cloud_prefect-agent.xxx.yyy
...
"Args": [
"-g",
"--",
"entrypoint.sh",
"sh",
"-c",
"prefect agent docker start --no-docker-interface --log-level DEBUG --token xxx -n ${PREFECT_NAME} --network prefect-docker-agent-for-cloud-network --volume /var/run/docker.sock:/var/run/docker.sock:ro --volume /root/.docker/:/root/.docker/:ro"
],
...
Anna Geller
prefect agent docker start --label YOUR_LABEL --log-level DEBUG --key YOUR_API_KEY -n ${PREFECT_NAME} --network prefect-docker-agent-for-cloud-network --volume /var/run/docker.sock:/var/run/docker.sock:ro --volume /root/.docker/:/root/.docker/:ro
If you want more environment isolation for this process, you can run it within a virtual environment.
I also noticed that:
1. You use API token rather than API key - API tokens are deprecated, so API key would be preferable
2. The --no-docker-interface flag is also deprecated (I believe it’s likely because of exactly this problem that you’re facing with Docker-in-Docker)
3. You have no labels assigned to the agent. Usually, you add a label to the agent, and then add the same label to your flow so that you can match flow with the agent for deployment - I included the label in the above command that you can start in a local process.
The CLI docs provide more information on all of that: https://docs.prefect.io/api/latest/cli/agent.html#docker-startMartin T
11/05/2021, 10:33 AMMartin T
11/05/2021, 10:42 AMAnna Geller
Anna Geller