Skip to content
This repository was archived by the owner on Aug 28, 2024. It is now read-only.

Keyvault performance#905

Merged
chenrujun merged 11 commits intomicrosoft:masterfrom
mnriem:keyvault-performance
Jun 16, 2020
Merged

Keyvault performance#905
chenrujun merged 11 commits intomicrosoft:masterfrom
mnriem:keyvault-performance

Conversation

@mnriem
Copy link
Collaborator

@mnriem mnriem commented May 29, 2020

Summary

Rework refreshing logic to increase performance

Issue Type

  • Bug fixing

Starter Names

  • key vault spring boot starter

Additional Information

};
timer.scheduleAtFixedRate(task, 0, refreshInMillis);
} else {
refreshProperties();

Choose a reason for hiding this comment

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

If refreshInMillis <= 0, we will not use cache, we should get the result(secret name list and secret value) from key-vault in every request.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Also not going to change this as this setting is for refreshing the cached values, not for not caching at all. Should we allow for no caching at all? I do not think that is wise as the underlying Spring runtime can also be calling this at any given time (we do not control that).

Choose a reason for hiding this comment

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

Should we allow for no caching at all?

I already discussed with @jialindai , we think that we allow no caching at all.

Let user configure whether need to cache.

If user configure refreshInMillis == 0, not cache make sense.

Maybe can can use kay-vault.cache.ms instead of refresh-interval as configure item?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No caching will be detrimental to any application as you are not in control of when the PropertySource gets consulted. I strongly advice against that.

Choose a reason for hiding this comment

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

Your concern make sense.

But current behavior is no cache.

IMU,

  • About 80%(just guess) of key-vault property will only get one time. (when start the app).
  • It's OK to let our customer determine whether to use cache.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If we set the refresh interval to -1 to indicate we do NO caching at all then I will go ahead and implement that, but I still think this is bad from a user experience point of view. Our code now can slow down any part of their application because we do NOT control the order in which PropertySources are consulted, nor at what time! So agreed on the -1?

Choose a reason for hiding this comment

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

As discussed in email. Let our customer to decide the TTL of cache.

refreshProperties();
}
};
timer.scheduleAtFixedRate(task, 0, refreshInMillis);

Choose a reason for hiding this comment

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

If refreshInMillis equal to 1 second, and task will cost 1 minute to finish, then many task will run at the same time? That's not good.

Choose a reason for hiding this comment

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

And it's not necessary to refreshProperties() again and again if the app only need to read the properties once.

(cc @jialindai FYI.)

Choose a reason for hiding this comment

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

I mean, if getPropertyNames() and getProperty are not called, refreshProperties() should not execute.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I disagree. A refresh interval is exactly that, aka the interval after which the keys/values are refreshed from the backend. So not going to change this. If the application developer does not need a refresh of the keys/values after startup the refresh interval can be set to 0.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

From the JavaDoc of Timer, "Corresponding to each Timer object is a single background thread that is used to execute all of the timer's tasks, sequentially."

Choose a reason for hiding this comment

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

I feel you are looking to implement a TTL for each secret, if so we would have to rearchitect this.

Not for each secret, use current configure item refresh-interval as TTL of all secrets is my purpose.

Can we proceed as it currently stands? And IF we decide that TTL is appropriate to do that later?

Can we use current configure item refresh-interval as TTL of all secrets?

Choose a reason for hiding this comment

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

But even with that said why on earth would anyone want to refresh the cache every minute?

Just as I said above: our customer may update key-value pair in key-vault (manually or by java code), then get the pair by environment.getProperty() minutes latter. if customer can not get the updated data, it may make our customer confused.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I feel you are looking to implement a TTL for each secret, if so we would have to rearchitect this.

Not for each secret, use current configure item refresh-interval as TTL of all secrets is my purpose.

Can we proceed as it currently stands? And IF we decide that TTL is appropriate to do that later?

Can we use current configure item refresh-interval as TTL of all secrets?

Great then I can leave the code I wrote as is as that is what the refresh interval does. It refreshes all the secrets after a specific time (Time To Live)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

But even with that said why on earth would anyone want to refresh the cache every minute?

Just as I said above: our customer may update key-value pair in key-vault (manually or by java code), then get the pair by environment.getProperty() minutes latter. if customer can not get the updated data, it may make our customer confused.

See my comments above

Choose a reason for hiding this comment

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

It refreshes all the secrets after a specific time (Time To Live)

To save the resource of network and key-vault server:

I mean, if getPropertyNames() and getProperty are not called, refreshProperties() should not execute.

@chenrujun
Copy link

chenrujun commented Jun 9, 2020

Hi, @mnriem ,
(cc @yiliuTo , FYI).

Is there any progress in this PR?
If you are busy, maybe I can help to finish the logic of cache key vault values.

@yiliuTo yiliuTo linked an issue Jun 9, 2020 that may be closed by this pull request
@chenrujun
Copy link

@jialindai said that

Manfred had some discussion with us on PR 905, the conclusion is go ahead with Manfred’s current approach which eagerly pull key vault. Please help to approve it.

There may be some further fine tuning, which will be tracked by further PR.

So I'll approve it now.

@AbhijeetAvaghade
Copy link

if this is part of 2.3.2 release?

@yiliuTo
Copy link
Member

yiliuTo commented Jul 28, 2020

if this is part of 2.3.2 release?

We plan to release it in 2.3.3 version

@AbhijeetAvaghade
Copy link

Any tentative date for 2.3.3 release?

@yiliuTo
Copy link
Member

yiliuTo commented Jul 29, 2020

Any tentative date for 2.3.3 release?

We plan to release 2.3.3 around mid-August.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Key Vault Secrets loaded multiple times

4 participants