cpu hungry index on mongo ticket registry

74 views
Skip to first unread message

Pascal Rigaux

unread,
Apr 1, 2023, 6:23:41 AM4/1/23
to CAS Community
Hi,

To avoid performance issues with Redis ticket registry on 6.6.x, we switched to MongoDB ticket registry.
I was really astonished that MongoDB was using as much CPU as CAS Java, and was causing a lot of iowait.

After looking around, I found a mostly unused text index:

name: 'json_text_type_text_ticketId_text',
weights: { json: 1, ticketId: 1, type: 1 },

Looking at the code, it seems to be useful for

| TextQuery.queryText(TextCriteria.forDefaultLanguage().matchingAny(principalId))

used by

- countSessionsFor (but only if crypto not enabled)
which is used by UniquePrincipalAuthenticationPolicy (cf https://apereo.github.io/cas/development/authentication/Configuring-Authentication-Policy-UniquePrincipal.html#unique-principal---authentication-policy )

- getSessionsFor to get all sessions for a user... but only if crypto not enabled.
If crypto is enabled it now uses the new "principal" field.


I suggest using "principal" field in any case (crypto enabled or not), and remove the costly json_text_type_text_ticketId_text indexes.

Here is the trivial commits I applied here:
https://github.com/prigaux/cas/commits/remove-mongo-ticket-registry-textindex-6.6
https://github.com/prigaux/cas/commits/remove-mongo-ticket-registry-textindex


NB: you can remove thoses indexes with

db.proxyGrantingTicketsCollection.dropIndex('json_text_type_text_ticketId_text')
db.proxyTicketsCollection.dropIndex('json_text_type_text_ticketId_text')
db.serviceTicketsCollection.dropIndex('json_text_type_text_ticketId_text')
db.ticketGrantingTicketsCollection.dropIndex('json_text_type_text_ticketId_text')

but they will come back at apereo CAS startup.


On the index subject, you may add the following useful one:

db.ticketGrantingTicketsCollection.createIndex({ ticketId: 1 })
db.serviceTicketsCollection.createIndex({ ticketId: 1 })
db.proxyTicketsCollection.createIndex({ ticketId: 1 })
db.proxyGrantingTicketsCollection.createIndex({ ticketId: 1 })


cu

martin....@springer.com

unread,
Feb 12, 2024, 5:59:18 AMFeb 12
to CAS Community, Pascal Rigaux

Pascal Rigaux

unread,
Feb 26, 2024, 4:55:05 AMFeb 26
to cas-...@apereo.org
Hi,

Thanks for the info. Looking at current code:

- index on "ticketId" has been created :-)
- text index IDX_JSON_TYPE_ID is now only created on TGTs (no more for STs)... which may still be costly. Need testing though...

cu


On 12/02/2024 10:54, 'martin....@springer.com' via CAS Community wrote:
> seems your declined PR at https://github.com/apereo/cas/pull/5627/files got now adopted by re-worked MongoDB support
> https://github.com/apereo/cas/commit/d7830d0d6ab47234abfd89b145c17f240f053170
>
> On Saturday, April 1, 2023 at 12:23:41 PM UTC+2 Pascal Rigaux wrote:
>
> Hi,
>
> To avoid performance issues with Redis ticket registry on 6.6.x, we switched to MongoDB ticket registry.
> I was really astonished that MongoDB was using as much CPU as CAS Java, and was causing a lot of iowait.
>
> After looking around, I found a mostly unused text index:
>
> name: 'json_text_type_text_ticketId_text',
> weights: { json: 1, ticketId: 1, type: 1 },
>
> Looking at the code, it seems to be useful for
>
> | TextQuery.queryText(TextCriteria.forDefaultLanguage().matchingAny(principalId))
>
> used by
>
> - countSessionsFor (but only if crypto not enabled)
> which is used by UniquePrincipalAuthenticationPolicy (cf
> https://apereo.github.io/cas/development/authentication/Configuring-Authentication-Policy-UniquePrincipal.html#unique-principal---authentication-policy
> <https://apereo.github.io/cas/development/authentication/Configuring-Authentication-Policy-UniquePrincipal.html#unique-principal---authentication-policy> )
>
> - getSessionsFor to get all sessions for a user... but only if crypto not enabled.
> If crypto is enabled it now uses the new "principal" field.
>
>
> I suggest using "principal" field in any case (crypto enabled or not), and remove the costly json_text_type_text_ticketId_text indexes.
>
> Here is the trivial commits I applied here:
> https://github.com/prigaux/cas/commits/remove-mongo-ticket-registry-textindex-6.6 <https://github.com/prigaux/cas/commits/remove-mongo-ticket-registry-textindex-6.6>
> https://github.com/prigaux/cas/commits/remove-mongo-ticket-registry-textindex <https://github.com/prigaux/cas/commits/remove-mongo-ticket-registry-textindex>
Reply all
Reply to author
Forward
0 new messages