Skip to content

Commit f7d3c7d

Browse files
author
Zhe Zhang
authored
Merge pull request #8 from ray-project/state-observability-apis
State Observability API REP
2 parents 08c922d + dff4c77 commit f7d3c7d

File tree

1 file changed

+182
-0
lines changed

1 file changed

+182
-0
lines changed
Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
2+
## Summary
3+
### General Motivation
4+
5+
Ray does not currently expose public APIs for understanding the state of the system (what is running, resource consumption, errors, etc.). This is a frequent pain point for end-users and developers. This REP proposes to introduce structured APIs as part of the Ray 2.0 API for key states: actors, tasks, scheduling info, objects, resources, logs, etc.
6+
7+
#### Key requirements:
8+
- Need to expose all necessary Ray states for basic observability.
9+
- State APIs should be consistent / stable / well-documented. E.g., APIs names must be consistent with the concepts
10+
- APIs should be available to all clients, such as Dashboard, CLI, and Python APIs with the same implementation.
11+
- Shouldn’t introduce high overhead to the normal workloads.
12+
- Under no circumstances should it be possible to crash a cluster (say, up to our scalability envelope) using the observability APIs.
13+
14+
15+
### Should this change be within `ray` or outside?
16+
17+
Yes, the states we want to observe belong to Ray's internal components.
18+
19+
## Stewardship
20+
### Required Reviewers
21+
22+
@scv119, @edoakes, @ericl
23+
24+
### Shepherd of the Proposal (should be a senior committer)
25+
26+
@edoakes
27+
28+
## Design and Architecture
29+
30+
### States
31+
“States” must be closely related and consistent with “concepts / APIs” users learn. For example, if we expose tasks as core Ray concepts, users would like to see the state of tasks. Ideally, the name of the APIs should be consistent with the concepts too.
32+
33+
State APIs can be categorized into 3 types.
34+
35+
**Logical states**
36+
- Aligned with logical concepts in which users need to learn to use Ray.
37+
It- Useful for beginners to advanced users.
38+
- E.g., actors, tasks, objects, resources, placement groups, runtime environments
39+
40+
41+
**Physical states**
42+
- States from physical components.
43+
- When users scale up, it will become important to observe physical states.
44+
- E.g., logs, cluster health, worker processes, nodes
45+
46+
**Internal states**
47+
- Internal information about Ray.
48+
- They are mostly useful for maintainers to debug bugs, but users can also be benefited.
49+
- E.g., scheduling states, events, internal states of Ray components
50+
51+
52+
### Status quo
53+
The below table shows if the existing APIs support the states above. Each column explains if the API is available for each client (Python API, CLI, REST API). Each row indicates available states in Ray.
54+
55+
<img width="826" alt="Screen Shot 2022-04-26 at 11 14 28 AM" src="https://user-images.githubusercontent.com/18510752/165365387-32a11ea4-bd0b-4df5-aeaa-f74e89a5332d.png">
56+
<img width="854" alt="Screen Shot 2022-04-26 at 11 14 13 AM" src="https://user-images.githubusercontent.com/18510752/165365343-0f912117-feda-4050-838d-59bb30c0dd03.png">
57+
58+
59+
### Proposed APIs
60+
All states should be visible to the users through properly documented / stable / consistently named APIs. This section proposes the state APIs to observe the following resources.
61+
62+
- Green: Already available. Might need to make APIs public/stable.
63+
- Red, P0: States that cannot be accessed / hard to access now
64+
- Yellow, P0: API exists, but we need refinement or renaming.
65+
- Blue, P1: Less critical states. Could be missing or not refined.
66+
67+
<img width="806" alt="Screen Shot 2022-04-26 at 11 15 05 AM" src="https://user-images.githubusercontent.com/18510752/165365485-25727a08-2a08-4691-a554-fbe5b7544cde.png">
68+
<img width="807" alt="Screen Shot 2022-04-26 at 11 15 17 AM" src="https://user-images.githubusercontent.com/18510752/165365506-1e2c6bc7-c365-4405-a4ca-2c7257051d69.png">
69+
70+
### Terminologies
71+
- Consumer: Consumers of state APIs. In Ray, (e.g., dashboard, CLI, and Python APIs).
72+
- API server: Currently a Ray dashboard. Centralized server to aggregate and provide state information of the cluster.
73+
- Ray agent: Currently a dashboard agent. A Python process running per node.
74+
- Resources: Objects created by Ray. E.g., tasks, actors, placement groups, namespace.
75+
76+
### Observability API architecture
77+
Currently, there are two big architectural problems.
78+
1. Each consumer has its implementation for each API. E.g., ray.state.actors() and the API /logical/actors have their own implementation. each consumer in Ray uses different components/code to implement each layer, which in turn leads to having duplicated code and non-unified abstraction, which causes the unmaintainability of state APIs.
79+
2. No architectural pattern to guarantee stability. E.g., ray memory will just crash if the output is big.
80+
81+
We propose to use the Ray API server (which is known as the dashboard server) as a stateless, read-only, centralized component to provide state information across Ray. An API server will be responsible for providing an interface (either gRPC or REST, depending on what API server is standardized), caching, and querying data from sources (raylet, GCS, agent, workers), and post-processing the aggregated state information. Having a centralized component with a standardized interface will bring several benefits such as (1) all consumers can avoid having diverged implementation, (2) APIs will become language agonistic, (3) and good maintainability and low complexity with the expenses of performance. Since state APIs don't have strict performance requirements, the tradeoff wouldn't be a big problem.
82+
83+
<img width="359" alt="Screen Shot 2022-04-26 at 11 15 44 AM" src="https://user-images.githubusercontent.com/18510752/165365580-f953181a-67b8-4797-883d-d9b726d2780e.png">
84+
85+
Alternatively, we can allow consumers to directly query the states from each component (which resembles how the private GCS-based state APIs work). Although it is a viable option and could be slightly more scalable (because there's no centralized component), it has several drawbacks. (1) some logic is hard to generalize (e.g., service discovery) from all consumers. (2) APIs will be difficult to be used by some consumers (e.g., dashboard) (3) we will need to develop APIs for each language.
86+
87+
### Stability and Scalability
88+
Aggregation of large data to a centralized component with reasonable SLA is a hard problem to solve, especially for systems like Ray that have decentralized data sources (tasks, objects). Building systems that can scale well in such a scenario would be difficult and might require us to build/introduce new systems. For simplicity, we propose to **degrade the performance gracefully** when there is significantly high volume of data (e.g., shuffling millions of objects, and users want to access the list of all objects).
89+
90+
To support stability in the large-scale cluster, we will ensure to bound the output size of API. More concretely, there will be 4 rules.
91+
- O(1) overhead per node per call (e.g., lim 1000 records)
92+
- O(n) overhead on API server per call (n: number of nodes).
93+
- O(1) final result size (e.g., lim 10000 records)
94+
- The API server limits the number of concurrent requests.
95+
96+
Note that it means users can lose information when there is a high volume of data. However, debugging issues with the extremely high volume of data will hinder user experience or sometimes not even possible. It means we should optimize for **reducing the output size** rather than supporting users to access all high volumes of data.
97+
98+
### APIs
99+
Accessing states could be categorized by 2 types of APIs.
100+
- Unique-id-based APIs. For example, actors, tasks, placement groups, nodes, etc. All states could be accessed by similar APIs.
101+
- Other types of APIs that don't have unique ids. For example, logs, resources, or health-checking. These states need to be exposed in their unique way.
102+
103+
Note that the API example below is not finalized, and detailed API specifications will go through the Ray API review.
104+
105+
#### Unique-id based APIs
106+
We propose to introduce 3 different types of APIs.
107+
- Summary API, which will provide a comprehensive view of states. For example, tasks can be grouped by a task name, and the API can provide the number of running or pending tasks. Summary API will help users quickly figure out anomalies and narrow down the root causes of various issues.
108+
- List API, which will list all existing states of resources in the cluster. A summary API is not always sufficient, and users should be able to access more fine-grained information. For example, users would like to access the "state of every single actor" to exactly figure out problematic actors in the cluster.
109+
- Get API, which will return a detailed view of a single resource state. Get API could return more information than list APIs.
110+
111+
All the APIs will be available through CLI, Python API, and REST endpoints.
112+
113+
```
114+
# CLI
115+
ray summary actors # Returns the summary information.
116+
ray list actors --state=CREATED # Returns all entries of actors.
117+
ray get actor [id] # Return the detailed information of a single actor.
118+
119+
# Python
120+
ray.summary_actors()
121+
ray.list_actors(state="CREATED")
122+
ray.get_actor(id)
123+
124+
# REST
125+
/api/v1/actors/summary
126+
/api/v1/actors?state="CREATED"
127+
/api/v1/actors/{id}
128+
```
129+
130+
#### Non unique-id based APIs
131+
We'd like to propose 3 additional APIs that cannot be categorized as unique-based APIs.
132+
- `ray logs`. This API will allow users to access and tail any log files in the cluster through handy CLI commands.
133+
- `ray resources`. This API will allow users to access resource usage of the cluster as well as tasks/actors that occupy those resources.
134+
- `ray health-check. This API will help users to know the health of the cluster. This API already exists as a private API, and we'd like to propose it to be a public API.
135+
136+
The example API and output will look like this. Details will be confirmed as a follow-up.
137+
138+
```
139+
# ray logs
140+
ray logs actor [actor_id] # Print actor logs of the corresponding id.
141+
ray logs raylet [node_id] # Print the raylet logs of the corresponding id.
142+
ray logs raw [filename] # Print the file.
143+
ray logs GCS --follow # Tail the GCS log.
144+
145+
# ray resources
146+
ray resources # Returns the resource usage [used]/[total]. Will look like `ray status`.
147+
ray resources --per-node # Returns the resource usage per node.
148+
ray resources --detail # Returns the list of tasks/actors that use resources
149+
> CPU 4/16, GPU 1/4
150+
> f, {CPU: 1} * 3
151+
> Actor, {CPU: 1, GPU:1} * 1
152+
153+
# ray cluster-health # Returns exit code 0 if the cluster is alive.
154+
```
155+
156+
### Error handling
157+
All consumers should have the default timeout. It is the same for all internal aggregation RPCs.
158+
159+
- If the API server is down (or overloaded).
160+
- The request will simply timeout and users will be notified.
161+
- The availability of the API server is not in the scope of this REP.
162+
163+
- If the source is down (or overloaded)
164+
- Return the RPC with data loss and notify users about it.
165+
- The stability of data sources is not within the scope of this REP.
166+
167+
- The returned payload is too big
168+
- We will bound the output size of all internal RPCs to make sure this is not happening in the first iteration. In the future, we can solve it by chunking the result or using streaming.
169+
170+
## Compatibility, Deprecation, and Migration Plan
171+
### Dashboard
172+
In the medium term, we'd like to make the existing dashboard use state APIs. The dashboard server has had various stability issues due to its implementation (e.g., never GC some expensive information, or querying data from the cluster inefficiently every 1 second). It also has several permanent states in memory (e.g., a list of actor task specs) which makes it difficult to be fault-tolerant. Once all APIs are implemented, we'd like to propose making the dashboard "use state APIs" on-demand with pagination, so that it will become stateless and efficient.
173+
174+
### API server
175+
We'd like to rename the dashboard server as an API server. It will involve changing various file names and documentation changes. This has been the change that the community has been pushing for, and indeed we've added various dashboard-unrelated features to this component (e.g., job submission or usage states collection).
176+
177+
## Test Plan and Acceptance Criteria
178+
All APIs will be fully unit tested. All specifications in this documentation will be thoroughly tested at the unit-test level. The end-to-end flow will be tested within CI tests. Before the beta release, we will add large-scale testing to precisely understand scalability limitations and performance degradation in large clusters.
179+
180+
## (Optional) Follow-on Work
181+
- Pagination when accessing states.
182+
- Dashboard migration.

0 commit comments

Comments
 (0)