[keycloak-dev] session caching questions

Scott Rossillo srossillo at smartling.com
Mon Jun 4 16:48:38 EDT 2018


Hi Matt,

I’m not an active Keycloak dev but we used to run our Keycloak cluster on AWS Beanstalk. My advice would be to not use AWS Beanstalk for Keycloak. AWS Beanstalk is OK for simple applications but we had to write custom Beanstalk hooks to get Infinspan to behave correctly. I would suggest using AWS Elastic Cluster Service (ECS) and if you don’t want to manage the instances use Fargate instead of EC2.

Just to be clear: this isn’t a criticism of either Keycloak / WildFily / Infinispan or AWS Beanstalk. It’s just advice from another engineer who has experience with the combination of these two products. Since moving to to ECS we haven’t had any issues with the cache during deployments.

As for your suggested configuration: I don’t think the user, realm and key caches should be changed. These caches are not an issue during deployments and they reduce DB load significantly the way they’re configured out of the box.

Best,
Scott

Scott Rossillo
Smartling | Senior Software Engineer
srossillo at smartling.com

> On Jun 4, 2018, at 2:19 PM, Matt Domsch (mdomsch) <Matt.Domsch at quest.com> wrote:
> 
> While we're at it, shouldn't the realm, user, and key caches all be invalidation caches too, with a limit on the number of objects in each?  The objects are persisted to disk.  In our case, I've got >85k user records, and suspect that the <local> user cache is growing unbounded, hence I'm seeing steadily increasing memory usage.
> 
> Thanks,
> Matt
> 
> 
> --
> Matt Domsch
> Executive Director & Senior Distinguished Engineer
> Quest | Engineering
> Matt.Domsch at quest.com
> Mobile 512.981.6486
> 
> -----Original Message-----
> From: keycloak-dev-bounces at lists.jboss.org [mailto:keycloak-dev-bounces at lists.jboss.org] On Behalf Of Matt Domsch (mdomsch)
> Sent: Thursday, May 31, 2018 4:06 PM
> To: keycloak-dev at lists.jboss.org
> Subject: [keycloak-dev] session caching questions
> 
> CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you recognize the sender and know the content is safe.
> 
> 
> In our deployments, we have need for the individual nodes in our standalone-ha cluster to be able to be stopped and restarted at any time, without loss of user sessions.  We deploy into AWS Elastic Beanstalk, and join the "new" nodes into the existing JGroups cluster of "old" nodes, switch CNAMEs, then shut down the "old" nodes.  The default suggested model of using <distributed-cache> for the session and clientSession caches fails in this scenario, as sessions stored only in memory on the "old" nodes are lost.  As such, we've switched to <replicated-cache> for most of the caches.  Does this make sense?  Are most people using Keycloak running >10 nodes per cluster such that replicated cache doesn't make sense for performance reasons?  If not, can the example standalone-ha.xml be adjusted to use replicated-cache?
> 
> When items are placed into the caches, it seems that they are not put() with a lifetime or expiry time associated with them.  This has led us to run into out-of-memory issues as the sizes of these caches grows without bound.  We've added expiration times in the XML config to adjust for maximum lifetimes based on the longest session timeouts across all realms.  This seems not ideal. It would be better to put() including the current active session timeouts for the realm for the object from which it originates.
> 
> We cannot evict items in the sessions and clientSessions caches as they are not persisted to disk. The Offline variants are persisted to disk, so evicting these seem OK.  Should this then be an invalidation-cache rather than a replicated-cache?
> 
> 
> XML snippet:
>        <subsystem xmlns="urn:jboss:domain:infinispan:4.0">
>            <cache-container name="keycloak" jndi-name="infinispan/Keycloak" statistics-enabled="true">
>                <replicated-cache name="sessions" mode="SYNC" statistics-enabled="true">
>                    <!-- NOT persisted to the database, so cannot evict within their valid lifetime -->
>                    <!-- max-idle = refresh_token:1 day -->
>                    <expiration max-idle="86700000" interval="300000"/>
>                </replicated-cache>
>                <replicated-cache name="clientSessions" mode="SYNC" statistics-enabled="true">
>                    <!-- NOT persisted to the database, so cannot evict within their valid lifetime -->
>                    <!-- max-idle = refresh_token:1 day -->
>                    <expiration max-idle="86700000" interval="300000"/>
>                </replicated-cache>
>                <replicated-cache name="authenticationSessions" mode="SYNC" statistics-enabled="true">
>                    <!-- NOT persisted to the database, so cannot evict within their valid lifetime -->
>                    <!-- max-idle = login timeout:1 day -->
>                    <expiration max-idle="86700000" interval="300000"/>
>                </replicated-cache>
>                <replicated-cache name="offlineSessions" mode="SYNC" statistics-enabled="true">
>                    <!-- max-idle = refresh_token:30 days -->
>                    <eviction max-entries="10000" strategy="LRU"/>
>                    <expiration max-idle="2592000000" interval="300000"/>
>                </replicated-cache>
>                <replicated-cache name="offlineClientSessions" mode="SYNC" statistics-enabled="true">
>                    <eviction max-entries="10000" strategy="LRU"/>
>                    <expiration max-idle="2592000000" interval="300000"/>
>                </replicated-cache>
> 
> 
> Thanks,
> Matt
> 
> --
> Matt Domsch
> Executive Director & Senior Distinguished Engineer Quest | Engineering Matt.Domsch at quest.com<mailto:Matt.Domsch at quest.com>
> Mobile 512.981.6486
> 
> _______________________________________________
> keycloak-dev mailing list
> keycloak-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/keycloak-dev
> 
> _______________________________________________
> keycloak-dev mailing list
> keycloak-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/keycloak-dev



More information about the keycloak-dev mailing list