Skip to content

Disable ADAL cache - #2309

Merged
Peter (pmaytak) merged 11 commits into
masterfrom
pmaytak/adal-cache-fallback
Jan 9, 2021
Merged

Peter (pmaytak) merged 11 commits into
masterfrom
pmaytak/adal-cache-fallback

Conversation

@pmaytak

@pmaytak Peter (pmaytak) commented Dec 16, 2020 •

Copy link
Copy Markdown
Contributor

Issue #1770

  • Measure improvement (start with baseline and explore improvements for a small and large cache sizes)
  • Flag to disable ADAL cache fallback (.WithDisableAdalCache - suggestions welcome)
BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19042
Intel Core i7-9850H CPU 2.60GHz, 1 CPU, 12 logical and 6 physical cores
.NET Core SDK=5.0.101
  [Host]                      : .NET Core 3.1.10 (CoreCLR 4.700.20.51601, CoreFX 4.700.20.51901), X64 RyuJIT
  Job-GetAllAccessTokensTests : .NET Core 3.1.10 (CoreCLR 4.700.20.51601, CoreFX 4.700.20.51901), X64 RyuJIT

Job=Job-GetAllAccessTokensTests  
Method Cache Size ADAL Cache Enabled Mean Error StdDev Median
SaveToken 1 False 114.627 ΞΌs 5.0409 ΞΌs 14.3002 ΞΌs 110.700 ΞΌs
SaveToken 1 True 254.866 ΞΌs 15.1876 ΞΌs 43.0847 ΞΌs 249.400 ΞΌs
SaveToken 100 False 125.229 ΞΌs 7.9097 ΞΌs 22.8214 ΞΌs 117.900 ΞΌs
SaveToken 100 True 3,839.003 ΞΌs 426.3727 ΞΌs 1,250.4775 ΞΌs 3,531.600 ΞΌs
SaveToken 1000 False 311.947 ΞΌs 46.2354 ΞΌs 130.4077 ΞΌs 290.300 ΞΌs
SaveToken 1000 True 19,656.353 ΞΌs 1,146.5410 ΞΌs 3,233.8394 ΞΌs 18,760.100 ΞΌs
FindToken 1 False 6.064 ΞΌs 0.0728 ΞΌs 0.0681 ΞΌs 6.036 ΞΌs
FindToken 1 True 25.042 ΞΌs 0.2029 ΞΌs 0.1799 ΞΌs 25.029 ΞΌs
FindToken 100 False 292.248 ΞΌs 5.0886 ΞΌs 4.7599 ΞΌs 291.118 ΞΌs
FindToken 100 True 1,247.194 ΞΌs 13.2774 ΞΌs 12.4197 ΞΌs 1,244.227 ΞΌs
FindToken 1000 False 2,918.332 ΞΌs 29.1596 ΞΌs 25.8492 ΞΌs 2,916.822 ΞΌs
FindToken 1000 True 13,160.303 ΞΌs 68.0861 ΞΌs 56.8550 ΞΌs 13,175.005 ΞΌs
GetAllUsers 1 False 4.115 ΞΌs 0.0369 ΞΌs 0.0308 ΞΌs 4.122 ΞΌs
GetAllUsers 1 True 26.792 ΞΌs 0.3861 ΞΌs 0.3611 ΞΌs 26.760 ΞΌs
GetAllUsers 100 False 21.667 ΞΌs 0.3096 ΞΌs 0.2896 ΞΌs 21.775 ΞΌs
GetAllUsers 100 True 1,034.691 ΞΌs 5.3541 ΞΌs 5.0082 ΞΌs 1,033.355 ΞΌs
GetAllUsers 1000 False 176.886 ΞΌs 1.6854 ΞΌs 1.5765 ΞΌs 176.577 ΞΌs
GetAllUsers 1000 True 12,433.904 ΞΌs 247.6150 ΞΌs 433.6777 ΞΌs 12,483.295 ΞΌs
RemoveUser 1 False 1.033 ΞΌs 0.0075 ΞΌs 0.0062 ΞΌs 1.035 ΞΌs
RemoveUser 1 True 2.185 ΞΌs 0.0384 ΞΌs 0.0341 ΞΌs 2.192 ΞΌs
RemoveUser 100 False 5.625 ΞΌs 0.0164 ΞΌs 0.0137 ΞΌs 5.621 ΞΌs
RemoveUser 100 True 6.830 ΞΌs 0.0394 ΞΌs 0.0307 ΞΌs 6.838 ΞΌs
RemoveUser 1000 False 48.304 ΞΌs 0.9617 ΞΌs 0.9876 ΞΌs 48.550 ΞΌs
RemoveUser 1000 True 48.664 ΞΌs 0.9403 ΞΌs 0.9235 ΞΌs 48.667 ΞΌs

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I've left a few suggestions.

(jus so that we remember): We need to understand (and demonstrate) the impact on the https://github.com/Azure-Samples/active-directory-dotnet-v1-to-v2/tree/master/TokenCacheMigration sample

@bgavrilMS

Copy link
Copy Markdown
Member

Looks good so far, I think you should look at the auto-detection separately, as it is out of scope for this work item. Unit tests + a perf tests would be a better next step.

@jmprieur

Copy link
Copy Markdown
Contributor

Peter (@pmaytak) : could we please have an estimate of the performance gain (before the fix, and after the idea of the fix) ?
We probably want to understand if this is worth it?

@pmaytak

Peter (pmaytak) commented Dec 16, 2020 •

Copy link
Copy Markdown
Contributor Author

Bogdan Gavril (@bgavrilMS) Jean-Marc Prieur (@jmprieur) Thanks for the suggestions; I'll work on a perf assessment.

@pmaytak

Copy link
Copy Markdown
Contributor Author

henrikm (@henrik-me) Jean-Marc Prieur (@jmprieur) Bogdan Gavril (@bgavrilMS) jennyf19
I added the test results above for four methods that access the legacy cache (for different cache sizes and with enabled and disabled legacy cache). Seems like there's improvement even if cache has only one item.

@pmaytak
Peter (pmaytak) force-pushed the pmaytak/adal-cache-fallback branch from 2f9831e to 7883d6b Compare January 5, 2021 10:15
@pmaytak
Peter (pmaytak) marked this pull request as ready for review January 5, 2021 10:15
AssertCacheEntryCount(0);
}

private void PopulateLegacyCache(ILegacyCachePersistence legacyCachePersistence)

@pmaytak Peter (pmaytak) Jan 5, 2021 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Note: Just moved these helper methods to LegacyTokenCacheHelper for ease of access.

@pmaytak

Copy link
Copy Markdown
Contributor Author

Ready for review for the first two bullet points.
The telemetry and auto detection can be added in the next PRs.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks Peter (@pmaytak)
I've proposed an improvement for the XML comment of the new API.

@jennyf19

jennyf19 commented Jan 5, 2021

Copy link
Copy Markdown
Contributor

Is there a reason to have this exposed only in the confidential client application options? As it's more of a confidential client issue. Also, i'm a little concerned about discoverability of this, and it can only be used w/MSAL only applications. Any applications that might share w/ADAL should not use this, would there be a risk of losing the cache? Do we have an internal partner or customer that we can have try this out? From my understanding, first party customers tend to try in MSAL first, and then fall back to ADAL if the call fails, so they might have to use the ADAL cache. Do we have a customer who has complained about the ADAL cache lookup?

side note, not a fan of having "ADAL" in the MSAL public API, just like we were told not to have B2C, ADAL seems even worse as it's being deprecated. As a new customer, I wouldn't understand why i would need this or not (what is ADAL?). Maybe auto-detection is better?


In reply to: 754546278 [](ancestors = 754546278)

@pmaytak

Copy link
Copy Markdown
Contributor Author

Is there a reason to have this exposed only in the confidential client application options? As it's more of a confidential client issue. Also, i'm a little concerned about discoverability of this, and it can only be used w/MSAL only applications. Any applications that might share w/ADAL should not use this, would there be a risk of losing the cache? Do we have an internal partner or customer that we can have try this out? From my understanding, first party customers tend to try in MSAL first, and then fall back to ADAL if the call fails, so they might have to use the ADAL cache. Do we have a customer who has complained about the ADAL cache lookup?

side note, not a fan of having "ADAL" in the MSAL public API, just like we were told not to have B2C, ADAL seems even worse as it's being deprecated. As a new customer, I wouldn't understand why i would need this or not (what is ADAL?). Maybe auto-detection is better?

henrikm (@henrik-me) Bogdan Gavril (@bgavrilMS) What's you opinion on Jenny's 3 points above?

As far as the renaming, I could change it to WithLegacyCacheCompatiblity and just mention ADAL in the XML comment.

@henrik-me

Copy link
Copy Markdown
Contributor

Peter Marklund (@peter) did you explore the impact on the cache compat tests JM pointed out?

The concern is if we disable this functionality by default how many are going to be impacted, if it's opt in then none. I was considering we should auto detect to opt. out of this, however people should be able to opt. out of disabling. The only otherway to validate this would be to start adding telemetry and let us measure how many really still need this. I would think that there might be a few for public client applications in migration scenarios (thus though could have a way to opt out of the behavior change in case our auto detection doesn't work) but I don't see a need for this in confidential client applications. Typically the fallback to ADAL there is to a completely different cache as it's a completely different library. I think this change is safe on confidential client, and that is also where we need it the most. We can start by making this confidential client only.


In reply to: 755112571 [](ancestors = 755112571)

@henrik-me

Copy link
Copy Markdown
Contributor

Peter (@pmaytak) : having discussed the overall impact of implementing auto detection with Jean-Marc Prieur (@jmprieur), we suggest to not implement that at all. this feature should be opt. in and we will find other ways to encourage customers to opt.in. This means regardless of scenario it should only be disabled if a customer has opted in.

@henrik-me henrikm (henrik-me) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

:shipit:

@pmaytak
Peter (pmaytak) force-pushed the pmaytak/adal-cache-fallback branch from b1fca1b to 1381c11 Compare January 9, 2021 07:01
@pmaytak
Peter (pmaytak) merged commit 6b1cff8 into master Jan 9, 2021
@pmaytak
Peter (pmaytak) deleted the pmaytak/adal-cache-fallback branch January 14, 2021 03:12
@bgavrilMS

Copy link
Copy Markdown
Member

Oh wow, I just saw the numbers. These are super impressive. We should really disable ADAL by default.

@henrik-me

Copy link
Copy Markdown
Contributor

+1: to disable for confidential client asap (though we already discussed this... telemetry would help).
Jean-Marc Prieur (@jmprieur) jennyf19 ... perhaps we can do this in id.web?

@jmprieur

Copy link
Copy Markdown
Contributor

henrikm (@henrik-me) jennyf19 : AzureAD/microsoft-identity-web#961

@bgavrilMS

Copy link
Copy Markdown
Member

My thought for automatic detection of ADAL usage is:

  • if after saving tokens to the cache (all AcquireToken* operations do this), you do not use SerializeAdal / DeserializeAdal methods, then we disable ADAL caching because it's just in-memory.
  • in a migration sceanrio, where app A uses ADAL cache and app B uses ADAL + MSAL cache, app B should read / write at least one to the ADAL cache.

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.

[Feature Request] Add ability to disable ADAL CacheFallbackOperations

5 participants