Skip to content

[Core]The first PR for running worker in container - #15976

Closed
chenk008 wants to merge 21 commits into
ray-project:masterfrom
antgroup:worker_in_container
Closed

chenk008 wants to merge 21 commits into
ray-project:masterfrom
antgroup:worker_in_container

Conversation

@chenk008

@chenk008 chenk008 commented May 21, 2021 •

Copy link
Copy Markdown
Contributor

Why are these changes needed?

We want to use container to resource limit, and use container image to support different dependencies.
This is the first PR to implements that feature. By using Podman, Worker process will started in container.

Now runtime_env is serialized in cpp code, we can't reuse runtime_env to specify the contain image.We add container image option fields into job_config, and supports to specify the contain image.

We add worker_resource into WorkerCacheKey, because worker_resource is one of worker’ characteristic, different actors have different worker_resource should not reuse worker process especially in container mode.

Start worker in container:

  1. start ray with config
ray start --head --port=6379 --system-config='{"worker_process_in_container_enabled":true}'

2 start job with container image

job_config = ray.job_config.JobConfig(worker_container_image="ray:latest")

ray.init(address="auto",job_config=job_config)

There are some features in next PR:

  1. Dashboard_agent need to prepare image in every node, otherwise Raylet main thread will block on pulling container image.
  2. Need to do validate that the worker image has a correct version

Related issue number

#14077

Checks

@chenk008
chenk008 force-pushed the worker_in_container branch 2 times, most recently from 62a9cea to 8c2e097 Compare May 25, 2021 11:44
@chenk008 chenk008 changed the title [WIP][Core]The first PR for running worker in container [Core]The first PR for running worker in container May 26, 2021
@bklaubos

Copy link
Copy Markdown

@chenk008
`start ray with config

  1. ray start --head --port=6379 --system-config='{"worker_process_in_container_enabled":true}'
    2 start job with container image

job_config = ray.job_config.JobConfig(worker_container_image="ray:latest")
ray.init(address="auto",job_config=job_config)`

Q: If ray start --head --port=6379 --system-config='{"worker_process_in_container_enabled":false}', do we still need to set
job_config = ray.job_config.JobConfig(worker_container_image="ray:latest")??

@chenk008

Copy link
Copy Markdown
Contributor Author

Q: If ray start --head --port=6379 --system-config='{"worker_process_in_container_enabled":false}', do we still need to set
job_config = ray.job_config.JobConfig(worker_container_image="ray:latest")??

@bklaubos No, we don't need to set worker_container_image when disable worker_process_in_container

Comment thread src/ray/util/filesystem.cc Resolved
Comment thread python/ray/job_config.py Resolved
Comment thread python/ray/node.py Resolved
Comment thread src/ray/raylet/worker_pool.cc Resolved
Comment thread src/ray/raylet/worker_pool.h Resolved
Comment thread src/ray/raylet/worker_pool.h Resolved
Comment thread src/ray/raylet/worker_pool.cc Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if it works when we enable multiple workers in one process.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to not enable setting cpus and memories in this PR.

@jovany-wang

Copy link
Copy Markdown
Contributor

Also, can you add some tests?

@chenk008

chenk008 commented Jun 1, 2021

Copy link
Copy Markdown
Contributor Author

Also, can you add some tests?

I have tried to start privileged container in BuildKite, but it failed. I am still working on it.

@chenk008
chenk008 marked this pull request as draft June 2, 2021 13:00
Comment thread src/ray/common/ray_config_def.h Resolved
Comment thread src/ray/core_worker/core_worker.cc Resolved
Comment thread docker/ray-nest-container/Dockerfile Resolved
Comment thread .buildkite/pipeline.yml Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@simon-mo Can you take a look at the CI workflow?

@chenk008
chenk008 force-pushed the worker_in_container branch from 21b5641 to 51a99ea Compare June 4, 2021 16:07
@chenk008
chenk008 marked this pull request as ready for review June 4, 2021 16:10
@chenk008
chenk008 requested a review from simon-mo June 5, 2021 07:50
@chenk008

chenk008 commented Jun 8, 2021

Copy link
Copy Markdown
Contributor Author

@ericl @simon-mo Please take a look at this change.

Comment thread .buildkite/pipeline.yml
- pip install docker
- python ./ci/travis/build-docker-images.py --py-versions PY36 --build-type BUILDKITE --only-build-nest-container
- mkdir /ray-mount/containers
- docker save -o /ray-mount/containers/images.tar rayproject/ray-nest-container:nightly-py36-cpu

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add some comments why are we doing this. i.e. what does each container do, why do we run the test in the container (i assume it needs access to podman?)

Comment thread ci/travis/test-worker-in-container.sh Outdated

export RAY_BACKEND_LOG_LEVEL=debug
"$HOME/anaconda3/bin/pip" install --no-cache-dir pytest
pytest /ray/python/ray/tests/test_actor_in_container.py -s

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use bazel to launch test instead of pytest directly

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will enable better reporting. please also add - cleanup() { if [ "${BUILDKITE_PULL_REQUEST}" = "false" ]; then ./ci/travis/upload_build_info.sh; fi }; trap cleanup EXIT to the steps so we are uploading correct logs.

@jovany-wang jovany-wang left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

C++ part looks good to me, and let's wait for @simon-mo to approve other parts.

Comment thread src/ray/util/filesystem.h
/// \return The non-volatile temporary directory for the current user (often /tmp).
std::string GetUserTempDir();

/// \return The stderr reference file. return empty if stderr not redirect to file.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// \return The stderr reference file. return empty if stderr not redirect to file.
/// \return The stderr reference file. Return empty if stderr is not redirected to file.

};

TEST_F(ContainerWorkerPoolTest, RegisterDriver) {
// ContainerWorkerPoolTest constructor will invoke PYTHON RegisterDriver.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// ContainerWorkerPoolTest constructor will invoke PYTHON RegisterDriver.
// ContainerWorkerPoolTest constructor will invokes PYTHON RegisterDriver.

WorkerCacheKey env = {override_environment_variables, serialized_runtime_env};
ResourceSet workerCacheKeyResource = worker_resource;
if (!worker_process_in_container_enabled_) {
workerCacheKeyResource = {};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These lines could be simplified to:

ResourceSet workerCacheKeyResource = worker_process_in_container_enabled_ ? worker_resource : {};

// logger, and the worker process' stdout/stderr has been redirected to raylet.err by
// default.
std::string stderr_file = ray::GetStderrFile();
if (!stderr_file.empty()) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if stderr_file string is empty?

if (RAY_LOG_ENABLED(DEBUG)) {
argv.emplace_back("--log-level=debug");
} else {
argv.emplace_back("--rm");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does --rm do? Could you add comments for it?

}
// TODO set uid for container, for example: -u admin
argv.emplace_back("-d");
argv.emplace_back("-v");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add more comments for these command line options? (eg, -d -v)

Comment thread python/ray/tests/BUILD
tags = ["exclusive", "worker-nest-container"],
# Now we run this test in a container which has installed ray
deps = [],
) No newline at end of file

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A new line.

@jovany-wang

Copy link
Copy Markdown
Contributor

And also wait for @ericl or @pcmoritz to approve this feature flag.

@ericl
In this PR, we add a new flag worker_process_in_container_enabled to enable starting container workers. In technical, it will not break anything because this works in bypass. That means if we don't enable this flag, everything should be same as before.

@ericl

ericl commented Jun 9, 2021

Copy link
Copy Markdown
Contributor

Now runtime_env is serialized in cpp code, we can't reuse runtime_env to specify the contain image.We add container image option fields into job_config, and supports to specify the contain image.

Hmm this is very unfortunate, we intended runtime env to be used for specifying docker image in a unified way. What if we made it a protobuf? Then, we also don't need the system flag since we can enable docker only if it's found in the runtime env proto.

Cc @iycheng

@ericl

ericl commented Jun 9, 2021

Copy link
Copy Markdown
Contributor

Dashboard_agent need to prepare image in every node, otherwise Raylet main thread will block on pulling container image.

Similarly, this should just be preparing runtime envs, which could automatically include the docker image.

@ericl ericl left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

API: change worker_container_image: X to runtime_env: docker: X

@chenk008

chenk008 commented Jun 9, 2021 •

Copy link
Copy Markdown
Contributor Author

Now runtime_env is serialized in cpp code, we can't reuse runtime_env to specify the contain image.We add container image option fields into job_config, and supports to specify the contain image.

Hmm this is very unfortunate, we intended runtime env to be used for specifying docker image in a unified way. What if we made it a protobuf? Then, we also don't need the system flag since we can enable docker only if it's found in the runtime env proto.

Cc @iycheng

I have open a issue : #16333. We can discuss in this issue.

@chenk008

chenk008 commented Jun 9, 2021

Copy link
Copy Markdown
Contributor Author

Dashboard_agent need to prepare image in every node, otherwise Raylet main thread will block on pulling container image.

Similarly, this should just be preparing runtime envs, which could automatically include the docker image.

It makes sense. I this this PR #15904 can help to pull container image.

@@ -0,0 +1,92 @@
ARG BASE_IMAGE="ubuntu:groovy"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this only for testing?

Comment thread python/ray/node.py
Comment on lines +303 to +304
try_to_create_directory(
os.path.join(self._session_dir, "worker_container"))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you mind putting them into runtime_resources? This is the place where all runtime env related things being put.

Comment on lines +917 to +923
if (const char *env_pid = std::getenv("RAYLET_PID")) {
pid_t pid = static_cast<pid_t>(std::atoi(env_pid));
if (!IsProcessAlive(pid)) {
RAY_LOG(ERROR) << "Raylet failed. Shutting down. Pid: " << pid;
Shutdown();
}
} else if (!IsParentProcessAlive()) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confused here about why we need it. Do you mind giving some comments about this?

return child;
}

Process WorkerPool::StartContainerProcess(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't need this function to be put in CPP layer. Shim process should be good enough.

Check it here https://github.com/ray-project/ray/blob/master/python/ray/workers/setup_runtime_env.py

Right now it only take care of conda env, like install conda and activate and start default worker.

I think you can process it there in the same way, but make sure run it before the conda env get processed.

@architkulkarni could you help double-check it's working with shim process?

@fishbone

Copy link
Copy Markdown
Contributor

Right now, conda is installed in shim process and it's designed to be extended easily. We probably don't want another code path to take care of env installation. Could you try to put the logic into shim process? I have the feeling that the code will become clearer and easier to maintain. @architkulkarni could you also help check it can be done in shim process?

@ericl ericl added this to the Containerized Workers milestone Jun 23, 2021
@chenk008 chenk008 mentioned this pull request Jun 25, 2021
2 of 6 tasks
@ericl ericl closed this Jun 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants