Skip to content
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

SQS: avoid excessive GetQueueURL calls by using cached queue url #1621

Merged
merged 3 commits into from
Apr 19, 2023

Conversation

sparrowt
Copy link
Contributor

The first commit fixes #1618.

The second clarifies some comments & variable names which I found confusing while trying to figure out what was going on.

Copy link
Member

@auvipy auvipy left a comment

Choose a reason for hiding this comment

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

this will also need proper test coverage

@sparrowt
Copy link
Contributor Author

sparrowt commented Dec 2, 2022

Hi @auvipy, thanks for looking at my PR - aside from coverage are you happy with the caching change in principle?

I haven't added any new methods or logical code paths, only made a small modification to one existing path - are these core methods not already covered? Is there a way for me to access the coverage results which https://github.com/celery/kombu/actions/runs/3533431074/jobs/6067061888 seems to be recording? Thanks in advance.

P.S. I noticed 3 of the CI runs failed, but none looked to be related to this code change, are they expected?

@auvipy
Copy link
Member

auvipy commented Dec 4, 2022

to be honest, the actual change is hard to review, due to lots of renaming. can you please add tests? I am in favour of caching if it doesn't break anything, rather improve excessive calls to GetQURL

@thedrow
Copy link
Member

thedrow commented Dec 26, 2022

This would be easier to review if it included just the changes required to avoid excessive GetQueueURL calls.
The rest of the changes are valuable but make the change harder to review.

@sparrowt Any chance you'll refactor this PR and break it down into several PRs?

@auvipy
Copy link
Member

auvipy commented Mar 2, 2023

@sparrowt it would be great if you can revisit this

@sparrowt
Copy link
Contributor Author

sparrowt commented Apr 3, 2023

Hi folks, sorry for the delayed response - I deliberately made this PR with 2 separate commits, the first of which is a minimal fix for the problem, then the second which renames things which appeared to be confusingly named (whilst I was trying to figure out how everything worked).

Would you still prefer the 2nd commit to be removed to a separate PR potentially, or are you happy to review it commit by commit?

Regarding testing, I assume _get_async as a crucial code path is already covered by tests, so hopefully the continued passing of these tests should be sufficient? From the point of view of celery/kombu there shouldn't be any externally observable change in behaviour so I can't think of a logically new test which should be added. As mentioned above I don't have access to the coverage details which the CI seemed to be producing.

Copy link
Member

@auvipy auvipy left a comment

Choose a reason for hiding this comment

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

beside appropriate regression tests, please re-base as well

kombu/transport/SQS.py Show resolved Hide resolved
kombu/transport/SQS.py Show resolved Hide resolved
`_get_from_sqs` was unnecessarily calling `get_queue_url` every
time even though the only place which calls `_get_from_sqs`
(that is `_get_async`) actually already knows the queue URL.

This change avoids hundreds of `GetQueueUrl` AWS API calls per hour
when using this SQS backend with celery.

Also `connection` is set by the one-and-only caller (and `queue` is
actually the queue name string now anyway so couldn't ever have
`.connection`) so remove the None default and unused fallback code.
It seems that prior to 129a9e4 it returned a queue
object but this is no longer the case so update comments
variable names accordingly to make it clearer.

Also remove the incorrect fallback which cannot
be correct any more given the return value has to
be the queue URL which must be a string.
@sparrowt sparrowt force-pushed the cache-queue-url-issue-1618 branch 2 times, most recently from 70035a7 to 75b7ea3 Compare April 18, 2023 11:41
This key code path (which as far as I can see is
the main route when using celery with SQS) was
missing test coverage.

This test adds coverage for:
`_get_bulk_async` -> `_get_async` -> `_get_from_sqs`
@sparrowt sparrowt requested a review from auvipy April 18, 2023 12:39
@sparrowt
Copy link
Contributor Author

I've added coverage for the existing core code path which was missing it (and also rebased my PR), how's that? :)

@auvipy
Copy link
Member

auvipy commented Apr 18, 2023

I've restarted the CI

@auvipy auvipy merged commit 5062d53 into celery:main Apr 19, 2023
@auvipy
Copy link
Member

auvipy commented Apr 19, 2023

thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SQS transport calls get_queue_url *every* time before receive_message - should cache?
3 participants