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

feat: cache token for GCloudAuthorizedUser #57

Merged

Conversation

liufuyang
Copy link
Contributor

Current implementation for GCloudAuthorizedUser is not caching the token got by gcloud auth print-access-token. The token is valid for 60m but when using gcp_auth to run some service locally the gcloud command is run for each auth_manager.get_token(...) call.

This PR adds a token: RwLock<Token> in GCloudAuthorizedUser just like other accounts that implements ServiceAccount, also making the use cases more efficient when calling with auth_manager.get_token() by using GCloudAuthorizedUser.


Demo - effects when updated:
Before (gcloud auth print-access-token is run every time when using the manager get_token(...)):

fuyangl@Fuyangs-MacBook-Pro:~/workspace/bigtable_rs 
(main $) 🦀 👉  curlt localhost:3030/key1
    time_namelookup:  0.006677
       time_connect:  0.007068
    time_appconnect:  0.000000
   time_pretransfer:  0.007101
      time_redirect:  0.000000
 time_starttransfer:  0.800651
                    ----------
         time_total:  0.801008
fuyangl@Fuyangs-MacBook-Pro:~/workspace/bigtable_rs 
(main $) 🦀 👉  curlt localhost:3030/key1
    time_namelookup:  0.006588
       time_connect:  0.007086
    time_appconnect:  0.000000
   time_pretransfer:  0.007133
      time_redirect:  0.000000
 time_starttransfer:  0.688113
                    ----------
         time_total:  0.688453

After (token is cached):

fuyangl@Fuyangs-MacBook-Pro:~/workspace/bigtable_rs 
(main *) 🦀 👉  curlt localhost:3030/key1
    time_namelookup:  0.006734
       time_connect:  0.007171
    time_appconnect:  0.000000
   time_pretransfer:  0.007209
      time_redirect:  0.000000
 time_starttransfer:  0.047468
                    ----------
         time_total:  0.047594
fuyangl@Fuyangs-MacBook-Pro:~/workspace/bigtable_rs 
(main *) 🦀 👉  curlt localhost:3030/key1
    time_namelookup:  0.006815
       time_connect:  0.007263
    time_appconnect:  0.000000
   time_pretransfer:  0.007308
      time_redirect:  0.000000
 time_starttransfer:  0.049509
                    ----------
         time_total:  0.049676

@liufuyang
Copy link
Contributor Author

@hrvolapeter Please take a look? 😃

@liufuyang liufuyang force-pushed the increase-GCloudAuthorizedUser-performance branch from 849cd84 to ed4200e Compare October 9, 2022 14:12
@liufuyang
Copy link
Contributor Author

Code updated.

Copy link
Owner

@djc djc left a comment

Choose a reason for hiding this comment

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

Nice! One small nit.

src/gcloud_authorized_user.rs Outdated Show resolved Hide resolved
@hrvolapeter hrvolapeter merged commit c589190 into djc:master Oct 10, 2022
@hrvolapeter
Copy link
Collaborator

This have been released in 0.7.4

@liufuyang liufuyang deleted the increase-GCloudAuthorizedUser-performance branch October 11, 2022 18:33
@liufuyang
Copy link
Contributor Author

Thank you, that is nice to know :)

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

Successfully merging this pull request may close these issues.

3 participants