Repository navigation
Replies: 3 comments 4 replies
|
Hi @slaskawi - thank you for doing this detailed testing and sharing this with the Keycloak project. TL;DR: Deploying Keycloak to multiple AZs in a cluster (aka stretched) will be supported in KC 26.4 and also the default on Kubernetes. See #34504 for the epic, and the nightly release notes and upgrading guide. I'll reply to some comments here, and I might miss some. Please review the new nightly docs, and see if some of them are still unanswered. The multi-az is now called multi-cluster, and the single-cluster deployment support also deployments spanning multiple AZs. About latency: The nightly docs now state (subject to change before the release):
and https://www.keycloak.org/nightly/high-availability/single-cluster/building-blocks states
See https://www.cloudping.co/ for latencies in AWS within a region. Deployments with the KC Operator now deploy to different AZs automatically. The term "stretched cluster" is now avoided, and we use "multiple AZs in one region" in hopefully all places.
This is fixed in 26.3.4
This is an internal behavior, and I don't want people to rely on that. I know this is an opinionated view, feel free to change my mind.
What is not documented is not supported. We never tell people to change it. If we would document everything that is not supported, the docs would be huge. Again, I know this is an opinionated view, feel free to change my mind.
I doubt that given how JGroups works, and it would highly depend on the stack you are using. Odd numbers have no meaning in JGroups and Infinispan (at least not in the embedded one, and when using the built-in jdbc-ping which we recommend). Anyway, in KC 26.4 when using jdbc-ping, we're using the database to have one "winning" partition, while the other partitions mark themselves as "not ready". See #41561
There is no TLS certificate generation when a new node starts, still you might see some certificate store reloading. Let's have a different discussion around that. Also with embedded caches and sessions stored in the database, the rebalancing should be efficient / done within a short period of time. There might be more context variables to that, and also please share some numbers.
No, as described above.
No, as described above
Let's have a separate discussion on what the best HPA settings are. Again: I'll reply to some comments here, and I might miss some. Please review the new docs, and see if some of them are still unanswered. |
In order to avoid any confusion, the old "multi-site" guides are now referred to as multi-cluster. There was a mistake in our release notes, fixed by: #42703
I can clarify a little. The minority partition only enters Degraded mode when the |
|
Thank you both @ahus1 and @ryanemerson ! This is super useful and I'm absolutely happy to see the changes coming up! Most of my concerns have already been addressed and the only thing that remains and maybe deserves a bit of discussion is the HPA example and max instances. I think it would be great to have the latest perf tests at hand but as I mentioned in my original post, we got very descent figures with 3 nodes, which I would suggest as max. |
Uh oh!
There was an error while loading. Please reload this page.
Hey @pruivo @ryanemerson @shawkins @ahus1 👋🏻
I've been reading the Scaling User Guide for Keycloak, and wanted to ensure it provides up to date and correct information and suggest improvements. Please see the text below.
For some of the points, I'll be referring to the "SSO MAS Environment" presentation that probably hasn't been shared publicly (Ryan might still have a link to it and if not - I can distribute it via email). The presentation contains the performance figures and environment recommendations we identified during Keycloak Performance Testing (done by Pedro Igor, Marek, Ryan and me).
Stretched Clusters and Multi AZ deployments
The guide mentions:
During the SSO MAS Performance testing, we identified that Multi AZ is the cheapest way to ensure better resilience. In parallel to this, using embedded Infinispan Caches minimizes the maintenance overhead of maintaining a separate Infinispan cluster and lowers the overall resource consumption. The guide doesn't cover the essence of the problem which is the link stability and latency across AZs. According to this StackOverflow thread, the latency across AWS AZs is minimal (order of microseconds) and the link stability should be excellent, which should be perfectly fine to keep a well-performing and healthy Infinispan cluster.
The guide seems also to be imprecise on Pod Affinity Rules. For a Multi AZ deployments, the aim is to spread the Pods across multiple zones for resiliency reasons. However, I do agree that workloads sensitive to latency could be potentially co-located with Keycloak Pods but this also requires going further into the infrastructure layer and ensure the communication happens within an AZ and not across.
Finally, a term "stretched cluster" can refer to both Multi AZ and Multi Region setups. I used robots to help me find out what's the rough distribution is it's ~37% to Multi Region (I'm in this camp) and ~45% to Multi AZ (see this deep research results). I think it's a bit misleading in this context and would prefer to remove it entirely.
If my understanding is correct, I would like to propose the following modifications to the guide:
Infinispan considerations
The guide mentions:
Although the second part of the statement is true, using multiple joining members is absolutely fine for Infinispan. The problem appears if Multiple Pods boot up initially (or after the upgrade). Then, most likely they will clash on database migration as it happens within a transaction. One will succeed and the others will just crash (we observed this behavior in UDS Platform, which has been fixed here). The guide should also mention that using the
podManagementPolicyother thanOrderedReady(the default) is not supported. I would also clarify that multiple leavers may cause data loss as there are chances that both, the primary and the secondary owner of the data gets killed at the same time.If my understanding is correct, I would like to propose the following modifications to the guide:
podManagementPolicyother thanOrderedReady(the default) is not supported.Infinispan Split Brain and HPA
The guide does not mention what's the desired number of replicas to provide the best resilience guarantees. Based on Infinispan Network partitions and degraded clusters guide when a network split happens to the cluster, Infinispan puts the Minority Partition in the Degraded Mode. Even though it's not written directly in the Infinispan manual, the practical way to make this setup more stable is to use odd number of nodes (exactly as we did within the "SSO MAS Environment" testing). This practice follows the general recommendations for distributed systems (see this blog post for example).
If using an odd number of nodes is generally recommended in this case (and my intuition tells me that it should), the Horizontal Pod Autoscaler example needs a longer description or should be removed as HPAs doesn't have any way to enforce the odd number of nodes. In order to achieve this, we need an additional controller that will add +1 replica count every time HPA uses an even number.
The HPA example concerns me also from other reasons. It scales Keycloak out based on CPU utilization, however adding a new node to the cluster causes high CPU spikes (rebalancing, generating TLS certificates for Infinispan cluster etc). If we start the scaling process at 80% of the CPU limit, we'll actually saturate it for some period of time. This may result in lowering the availability for the external users (in other words result in more 504 errors). In many of these cases, scaling the CPU up vertically might be a better fit.
Finally, during the "SSO MAS Environment" performance testing, we discovered that Keycloak is extremely performant in 3 node configuration (please check the presentation for details). With these figures in mind, scaling it for performance reasons to more than 3 nodes seems impractical.
If the latest performance tests haven't drastically changed and my understanding is correct, I would like to propose the following modifications to the guide:
All reactions