Skip to content

Conversation

dragomirp
Copy link
Contributor

@dragomirp dragomirp commented Jun 1, 2025

Async parallel requests for cluster status.

Checklist

  • I have added or updated any relevant documentation.
  • I have cleaned any remaining cloud resources from my accounts.

@dragomirp dragomirp force-pushed the parallel-patroni-calls-tlsv4 branch from 241814d to 74903f1 Compare June 13, 2025 14:25
@dragomirp dragomirp changed the title [MISC] Parallel patroni calls tlsv4 [MISC] Parallel patroni calls Jun 25, 2025
Comment on lines +326 to +329
if result := await task:
for task in tasks:
task.cancel()
await wait(tasks)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Get the first result, cancel the other requests.

)
return cluster_status.json()["members"]
return response["members"]
raise RetryError(last_attempt=Exception("Unable to reach any units"))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Most existing code should handle RetryErrors instead of empty lists.

Copy link
Member

Choose a reason for hiding this comment

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

Great move!

Comment on lines -182 to -191
main()
assert _urlopen.call_args_list == [
# Iteration 1. server2 is not called
call("http://server1:8008/cluster", timeout=5, context=sentinel.sslcontext),
# Iteration 2 local unit server1 is called first
call("http://server1:8008/cluster", timeout=5, context=sentinel.sslcontext),
call("http://server3:8008/cluster", timeout=5, context=sentinel.sslcontext),
# Iteration 3 Last known member is server3
call("https://server3:8008/cluster", timeout=5, context=sentinel.sslcontext),
]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Order is no longer deterministic.

)
cluster_status = json.loads(resp.read())
loop = get_running_loop()
tasks = [loop.run_in_executor(None, call_url, url, context) for url in urls]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

No deps when executing the script, so running urllib requests in an executor.

@dragomirp dragomirp marked this pull request as ready for review June 26, 2025 00:27
@dragomirp dragomirp requested review from a team, taurus-forever and marceloneppel and removed request for a team June 26, 2025 00:27
@dragomirp dragomirp mentioned this pull request Jun 26, 2025
2 tasks
Copy link
Contributor

@taurus-forever taurus-forever left a comment

Choose a reason for hiding this comment

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

I have run tests, the deployment of 3 units cluster is about 5-10% faster (5 minutes instead of 5-6). The defers count is also slightly better (110 VS 127 for 3 units deployment).

Also topology observer behaves properly on Primary loose (without leader re-elected).

LGTM. Good work and the step into the proper direction for sure!

Copy link
Member

@marceloneppel marceloneppel left a comment

Choose a reason for hiding this comment

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

Great work on introducing async in the proper way to improve the performance of those calls, Dragomir!

LGTM!

)
return cluster_status.json()["members"]
return response["members"]
raise RetryError(last_attempt=Exception("Unable to reach any units"))
Copy link
Member

Choose a reason for hiding this comment

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

Great move!

@dragomirp dragomirp merged commit 59b58e9 into 16/edge Jul 1, 2025
145 of 155 checks passed
@dragomirp dragomirp deleted the parallel-patroni-calls-tlsv4 branch July 1, 2025 14:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature, UI change, or workload upgrade Libraries: Out of sync
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants