-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Run Repo Requests in Parallel on ProjectDetail Pages #1562
Conversation
dc2543c
to
5897d25
Compare
@bloodearnest – is this good to go now? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 with a suggestion
jobserver/views/projects.py
Outdated
"name": f.path.segments[1], | ||
"url": url, | ||
"is_private": is_private, | ||
} | ||
|
||
futures = [repo_thread_pool.submit(get_repo, url=url) for url in repo_urls] | ||
for future in concurrent.futures.as_completed(futures): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, I think we can slightly simplify this using Executor.map(). We can also set an explicit timeout for all requests too, which is usually a good idea when doing concurrency.
So, maybe replace the last 3 lines with:
# use the threadpool to parallelise the repo requests
yield from repo_thread_pool.map(get_repo, repo_urls, timeout=30)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
map basically does what you did, but handles cancellation and timeouts: https://github.com/python/cpython/blob/main/Lib/concurrent/futures/_base.py#L571
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Much nicer, and TIL!
On ProjectDetail pages with several repos the lookup for private/public status was noticably slowing the page down. This switches to ThreadPoolExecutor to run through them in parallel (mostly).
5897d25
to
f481e66
Compare
On ProjectDetail pages with several repos the lookup for private/public
status was noticably slowing the page down. This switches to
ThreadPoolExecutor to run through them in parallel (mostly).