Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: add caching to GapicCallable#527

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
daniel-sanche merged 28 commits intomainfromoptimize_gapic_callable
May 3, 2024

Conversation

daniel-sanche
Copy link
Contributor

@daniel-sanchedaniel-sanche commentedSep 6, 2023
edited by parthea
Loading

_GapicCallable currently does a lot of work on eachcall, re-building each wrapped function, using a lot of calls to helper functions. This cost is added to every single rpc, so it can really add up

This PR does the following optimizations

  • removes the_apply_decorators and_is_not_none_or_false to build the wrapped call more directly.
    • This seems to make it ~10% faster
  • add a new helper that builds a wrapped call using a timeout and retry object, and then cache the result with @lru_cache
    • This seems to make it 50% faster
    • In practice, I think it's safe to assume most calls will be re-using timeout and retry values
    • I currently have the cache size of 4, but this can be changed

Benchmark:

from google.api_core.gapic_v1.method import _GapicCallablefrom google.api_core.retry import Retrycallable =  _GapicCallable(lambda *a, **k: 1, retry=Retry(), timeout=1010, compression=False)from timeit import timeittimeit(lambda: callable())

Before: 20.43s
After: 9.48s

BEGIN_COMMIT_OVERRIDE
chore: add caching to GapicCallable
END_COMMIT_OVERRIDE

@product-auto-labelproduct-auto-labelbot added the size: sPull request size is small. labelSep 6, 2023
@product-auto-labelproduct-auto-labelbot added size: mPull request size is medium. and removed size: sPull request size is small. labelsFeb 10, 2024
@daniel-sanchedaniel-sanche marked this pull request as ready for reviewFebruary 10, 2024 01:35
@daniel-sanchedaniel-sanche changed the title[DRAFT] feat: optimize GapicCallablefeat: add caching to GapicCallableFeb 10, 2024
@vchudnov-gvchudnov-g self-assigned thisFeb 12, 2024
Copy link
Collaborator

@partheaparthea left a comment

Choose a reason for hiding this comment

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

This seems to make it 50% faster

Thanks for fixing this!

Please could you add a simple benchmarking presubmit, similar to the test that you ran manually, to avoid future regressions in performance?

@parthea
Copy link
Collaborator

Assigning back to@daniel-sanche to resolve the presubmit failure

@daniel-sanche
Copy link
ContributorAuthor

Hmm good point, the benchmark result will be machine-specific, and I was doing my tests locally instead of with the CI workers.

I guess I'll have to find an assertion value that works well for the CI nodes, and I'll add a comment explaining that it may be flake on slower hardware. Or let me know if you have other suggestions for how to approach this

@parthea
Copy link
Collaborator

parthea commentedFeb 14, 2024
edited
Loading

Can you set it high enough that we don't get flaky results, but low enough that we can detect performance regressions.

Perhaps set the threshold to 0.4 for now and create an issue inhttps://github.com/googleapis/python-api-core/issues to add a proper benchmarking test ? I believe@ohmayr started looking into a benchmarking presubmit so please tag him on the issue.

@daniel-sanche
Copy link
ContributorAuthor

Sure, I opened an issue to track this here:#616

I adjusted the value to 0.4. Feel free to merge it with that number, but I suspect we can find a lower value that still avoids flakiness. Let me know if you want me to do some investigation

@parthea
Copy link
Collaborator

@vchudnov-g Please could you review?

Copy link
Contributor

@vchudnov-gvchudnov-g left a comment

Choose a reason for hiding this comment

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

Minor code comment, and an idea about tightening benchmarks.

Note: The threshold has been tuned for the CI workers. Test may flake on
slower hardware

https://github.com/googleapis/python-api-core/pull/527
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you mean to self-reference this PR?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

It was intentional, to give the context on this test. But on second thought,git blame should be enough. Removed

lambda *a, **k: 1, retry=Retry(), timeout=1010, compression=False
)
avg_time = timeit(lambda: gapic_callable(), number=10_000)
assert avg_time < 0.4
Copy link
Contributor

@vchudnov-gvchudnov-gMar 29, 2024
edited
Loading

Choose a reason for hiding this comment

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

Idea: If the assertion fails, print both the actual time it took and enough platform information so that in the future we can add the right threshold for the platform. The latter would be something like this

platform_threshold = { "foo": 0.2, "bar": 0.6 }current_platform = ......assert avg_time < platform_threshold.get(current_platform, 0.4)

In fact, you could implementplatform_threshold now, and start with whatever your current machine is.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

That's an interesting idea, but it's not completely clear to me what we'd need to capture for the platform. Number of CPUs? Architecture? OS? Let me know if you have thoughts

We already have#616 to track improving this though, so if it's alright with you, I'll merge this as-is and we can discuss follow-up there

@daniel-sanchedaniel-sanche merged commitd96eb5c intomainMay 3, 2024
27 checks passed
@daniel-sanchedaniel-sanche deleted the optimize_gapic_callable branchMay 3, 2024 20:05
@release-pleaserelease-pleasebot mentioned this pull requestMay 3, 2024
@partheaparthea restored the optimize_gapic_callable branchJune 4, 2024 11:48
parthea added a commit that referenced this pull requestJun 4, 2024
@partheaparthea added the release-please:force-runTo run release-please labelJun 4, 2024
@release-pleaserelease-pleasebot removed the release-please:force-runTo run release-please labelJun 4, 2024
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@partheapartheaparthea approved these changes

@vchudnov-gvchudnov-gvchudnov-g approved these changes

Assignees

@vchudnov-gvchudnov-g

Labels
size: mPull request size is medium.
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3 participants
@daniel-sanche@parthea@vchudnov-g

[8]ページ先頭

©2009-2025 Movatter.jp