Key concepts#
This page describes Ray’s key concepts. These primitives work together to support a broad range of distributed applications.
Tasks#
Ray runs arbitrary functions asynchronously on separate worker processes. These asynchronous Ray functions are tasks. You can specify a task’s resource requirements in terms of CPUs, GPUs, and custom resources. The cluster scheduler uses these resource requests to distribute tasks across the cluster for parallel execution.
See the user guide for tasks.
Actors#
Actors extend the Ray API from functions, which are tasks, to classes. An actor is a stateful worker, which you can also think of as a service. When you instantiate an actor, Ray creates a worker for it and schedules the actor’s methods on that specific worker. The methods can access and mutate the state of that worker. Like tasks, actors support CPU, GPU, and custom resource requirements.
See the user guide for actors.
Objects#
Tasks and actors create objects and compute on them. These objects are remote objects because Ray can store them anywhere in a Ray cluster. You use object refs to refer to them. Ray caches remote objects in its distributed shared-memory object store, with one object store per node in the cluster. A remote object can live on one or more nodes, independent of who holds the object ref.
See the user guide for objects.
Placement groups#
Use placement groups to atomically reserve groups of resources across multiple nodes. With a placement group, you can schedule tasks and actors packed as close as possible for locality with the PACK strategy, or spread them apart with the SPREAD strategy. A common use case is gang-scheduling actors or tasks.
See the user guide for placement groups.
Environment dependencies#
When Ray executes tasks and actors on remote machines, their environment dependencies, such as Python packages, local files, and environment variables, must be available on those machines. To make them available, do one of the following:
Prepare your dependencies on the cluster in advance with the Ray cluster launcher.
Use Ray’s runtime environments to install them on the fly.