Commit 0f5e5fa
authored
Adding retries for DBFS API on Error Code 429 (#319)
This PR attempts to use the well received [tenacity library ](https://github.com/jd/tenacity) to add retries for the DBFS cli commands. This is needed since we are imposing request limiting for these APIs.
The retries are done with an exponential backoff only for error code 429. The exponential multiplier is 1 sec and the max wait is 30 seconds. We will randomly wait up to 2^x * 1 seconds between each retry until the range reaches 60 seconds, then randomly up to 60 seconds afterwards where x is the number of retry. We will try a maximum for 7 times.
Manually testing by using the following script produced this error.
```
Rate limit exceeded. Retrying with exponential backoff.
WARNING:databricks_cli.dbfs.api: Received 429 REQUEST_LIMIT_EXCEEDED for attempt 1. Retrying in 0.2678150505033847 seconds.
Rate limit exceeded. Retrying with exponential backoff.
WARNING:databricks_cli.dbfs.api: Received 429 REQUEST_LIMIT_EXCEEDED for attempt 2. Retrying in 1.4529390049015964 seconds.
Rate limit exceeded. Retrying with exponential backoff.
WARNING:databricks_cli.dbfs.api: Received 429 REQUEST_LIMIT_EXCEEDED for attempt 3. Retrying in 1.4825864280042993 seconds.
Rate limit exceeded. Retrying with exponential backoff.
WARNING:databricks_cli.dbfs.api: Received 429 REQUEST_LIMIT_EXCEEDED for attempt 4. Retrying in 3.79336630796632 seconds.
Rate limit exceeded. Retrying with exponential backoff.
WARNING:databricks_cli.dbfs.api: Received 429 REQUEST_LIMIT_EXCEEDED for attempt 5. Retrying in 19.54595718573239 seconds.
Rate limit exceeded. Retrying with exponential backoff.
WARNING:databricks_cli.dbfs.api: Received 429 REQUEST_LIMIT_EXCEEDED for attempt 6. Retrying in 32.52860286202574 seconds.
DbfsTestingRateLimitSuite-c5458501-c08b-4add-b782-d3198fee31a2
bogdan-ghita
databricks-results
test-dir-1
tmp
DbfsTestingRateLimitSuite-c5458501-c08b-4add-b782-d3198fee31a2
bogdan-ghita
databricks-results
test-dir-1
tmp
DbfsTestingRateLimitSuite-c5458501-c08b-4add-b782-d3198fee31a2
bogdan-ghita
databricks-results
test-dir-1
tmp
```
In case of an error, we see the following output.
```
Rate limit exceeded. Retrying with exponential backoff.
WARNING:databricks_cli.dbfs.api: Received 429 REQUEST_LIMIT_EXCEEDED for attempt 1. Retrying in 0.25618165976582064 seconds.
Rate limit exceeded. Retrying with exponential backoff.
WARNING:databricks_cli.dbfs.api: Received 429 REQUEST_LIMIT_EXCEEDED for attempt 2. Retrying in 1.3924883604006733 seconds.
Rate limit exceeded. Retrying with exponential backoff.
Error: RateLimitException: 429 Too Many Requests
```
Script:
```
#!/bin/bash
CONCURRENT_REQ_LIMIT=30
NUM_REQUESTS_TO_EXCEED=1
NUM_REQUESTS=$((CONCURRENT_REQ_LIMIT + NUM_REQUESTS_TO_EXCEED))
for (( i=1; i<=$NUM_REQUESTS; i++ )); do
echo "$(date) Sending request $i"
dbfs ls dbfs:/ &
done
wait
```
Unit tests were added to test the changes.1 parent bf2951f commit 0f5e5fa
4 files changed
Lines changed: 205 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| 31 | + | |
| 32 | + | |
31 | 33 | | |
32 | 34 | | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
33 | 38 | | |
34 | 39 | | |
35 | 40 | | |
36 | 41 | | |
37 | 42 | | |
38 | | - | |
| 43 | + | |
39 | 44 | | |
40 | 45 | | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
41 | 54 | | |
42 | 55 | | |
43 | 56 | | |
| |||
75 | 88 | | |
76 | 89 | | |
77 | 90 | | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
78 | 120 | | |
79 | 121 | | |
80 | 122 | | |
81 | 123 | | |
82 | 124 | | |
83 | 125 | | |
| 126 | + | |
84 | 127 | | |
85 | 128 | | |
86 | 129 | | |
| |||
101 | 144 | | |
102 | 145 | | |
103 | 146 | | |
| 147 | + | |
104 | 148 | | |
105 | 149 | | |
106 | 150 | | |
107 | 151 | | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
108 | 164 | | |
109 | | - | |
| 165 | + | |
110 | 166 | | |
111 | 167 | | |
112 | 168 | | |
113 | 169 | | |
114 | 170 | | |
115 | 171 | | |
116 | | - | |
117 | | - | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
118 | 178 | | |
119 | 179 | | |
120 | 180 | | |
| |||
126 | 186 | | |
127 | 187 | | |
128 | 188 | | |
129 | | - | |
130 | | - | |
| 189 | + | |
131 | 190 | | |
132 | 191 | | |
133 | 192 | | |
| |||
146 | 205 | | |
147 | 206 | | |
148 | 207 | | |
| 208 | + | |
149 | 209 | | |
150 | 210 | | |
151 | 211 | | |
152 | 212 | | |
153 | | - | |
| 213 | + | |
| 214 | + | |
154 | 215 | | |
155 | 216 | | |
156 | 217 | | |
| |||
172 | 233 | | |
173 | 234 | | |
174 | 235 | | |
| 236 | + | |
175 | 237 | | |
176 | 238 | | |
177 | 239 | | |
| 240 | + | |
178 | 241 | | |
179 | 242 | | |
180 | 243 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
| 42 | + | |
42 | 43 | | |
43 | 44 | | |
44 | 45 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
34 | | - | |
| 34 | + | |
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| |||
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
58 | 65 | | |
59 | 66 | | |
60 | 67 | | |
| |||
103 | 110 | | |
104 | 111 | | |
105 | 112 | | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
106 | 145 | | |
107 | 146 | | |
108 | 147 | | |
| |||
122 | 161 | | |
123 | 162 | | |
124 | 163 | | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
125 | 174 | | |
126 | 175 | | |
127 | 176 | | |
| |||
138 | 187 | | |
139 | 188 | | |
140 | 189 | | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
141 | 210 | | |
142 | 211 | | |
143 | 212 | | |
| |||
159 | 228 | | |
160 | 229 | | |
161 | 230 | | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
162 | 247 | | |
163 | 248 | | |
164 | 249 | | |
| |||
173 | 258 | | |
174 | 259 | | |
175 | 260 | | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
176 | 281 | | |
177 | 282 | | |
178 | | - | |
| 283 | + | |
179 | 284 | | |
180 | 285 | | |
181 | 286 | | |
182 | 287 | | |
183 | 288 | | |
184 | 289 | | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
185 | 313 | | |
186 | 314 | | |
187 | 315 | | |
| |||
0 commit comments