You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@gravitino.apache.org by "danhuawang (via GitHub)" <gi...@apache.org> on 2026/06/24 00:31:55 UTC

[I] [Improvement] Group-based authorization adds 2-3x latency overhead compared to user-based authorization [gravitino]

danhuawang opened a new issue, #11781:
URL: https://github.com/apache/gravitino/issues/11781

   ### What would you like to be improved?
   
   Group-based authorization (built-in IDP with group→role mapping) introduces significant latency overhead compared to direct user-based authorization for single-table operations.
   
   **Performance test results** (30 concurrent users, Auth:ON, Cache:ON, CredentialVending:ON, schema `load3000` with 10,496 tables):
   
   | Service | Auth Mode | Samples | RPS | P50 | P75 | P95 |
   |---------|-----------|---------|-----|-----|-----|-----|
   | Iceberg REST | User Auth | 4001 | 13.36 | 130ms | 140ms | 180ms |
   | Iceberg REST | Group Auth | 3673 | 12.27 | 300ms | 360ms | 510ms |
   | Gravitino | User Auth | 4142 | 13.83 | 65ms | 75ms | 110ms |
   | Gravitino | Group Auth | 3834 | 12.81 | 210ms | 270ms | 430ms |
   
   Key observations:
   - **Group Auth adds ~130-170ms extra latency per request** compared to User Auth on the same operation.
   - P50 latency increases by **130% (Iceberg REST)** and **223% (Gravitino)** when switching from User Auth to Group Auth.
   - Tail latency (P95) is disproportionately affected — P95/P50 ratio grows from 1.38x to 1.70x (Iceberg) and 1.69x to 2.05x (Gravitino), suggesting occasional cache misses or extra lookups in the group→role resolution path.
   - RPS impact is moderate (~8% drop), but the latency increase is significant for latency-sensitive workloads.
   
   The extra latency likely comes from the additional group→role resolution step required on each request when using group-based authorization.
   
   ### Test Environment Background
   
   - **Metalake:** `irc_test`
   - **Catalog:** `iceberg` (Iceberg REST service at port 9001, Gravitino service at port 8090)
   - **Schema:** `load3000` containing **10,496 tables**
   - **Concurrent users:** 30 (user1 - user30)
   - **Group Auth setup:** All 30 users belong to a single group `perf_test_group`, which is granted `role_all` (full metalake access). The built-in IDP extension (`org.apache.gravitino.idp.web.rest.feature`) is enabled with `gravitino.authenticators = basic`.
   - **User Auth setup:** Each user is directly assigned `role_all` plus an individual role (`role1` - `role30`).
   - **Operation:** Load single table (random table from `load3000` schema)
   
   ### How should we improve?
   
   Potential solutions:
   1. **Cache group→role mapping** — Cache the resolution from group membership to role assignments so it does not require a lookup on every request.
   2. **Reduce IDP lookup round-trips** — Batch or pre-resolve user→group→role chain at authentication time rather than at each authorization check.
   3. **Session-level authorization context** — Resolve the full permission set once per session/token and reuse it for subsequent requests within the same session.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [Improvement] Group-based authorization adds 2-3x latency overhead compared to user-based authorization [gravitino]

Posted by "lasdf1234 (via GitHub)" <gi...@apache.org>.
lasdf1234 commented on issue #11781:
URL: https://github.com/apache/gravitino/issues/11781#issuecomment-4786918225

   > The difference is that, compared to user authorization, group authorization has the following extra steps, which will query database:
   > 
   > [gravitino/plugins/idp-basic/src/main/java/org/apache/gravitino/idp/auth/BasicAuthenticator.java](https://github.com/apache/gravitino/blob/d845d5cddc5bc208968a0e6bf4b594691afdb853/plugins/idp-basic/src/main/java/org/apache/gravitino/idp/auth/BasicAuthenticator.java#L147-L155)
   > 
   > Lines 147 to 155 in [d845d5c](/apache/gravitino/commit/d845d5cddc5bc208968a0e6bf4b594691afdb853)
   > 
   >  private UserPrincipal authenticate(BasicCredentials credentials, String authData) { 
   >    IdpUser user = userGroupManager.authenticate(credentials.username(), credentials.password()); 
   >   
   >    List<UserGroup> groups = 
   >        user.groupNames().stream() 
   >            .map(groupName -> new UserGroup(Optional.empty(), groupName)) 
   >            .collect(Collectors.toList()); 
   >    return new UserPrincipal(user.name(), groups, authData); 
   >  } 
   > We need to use a cache to avoid repeatedly accessing database.
   > 
   > cc [@lasdf1234](https://github.com/lasdf1234)
   
   Got I'll do some research.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [Improvement] Group-based authorization adds 2-3x latency overhead compared to user-based authorization [gravitino]

Posted by "danhuawang (via GitHub)" <gi...@apache.org>.
danhuawang commented on issue #11781:
URL: https://github.com/apache/gravitino/issues/11781#issuecomment-4784787311

   @yuqi1129  


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [Improvement] Group-based authorization adds 2-3x latency overhead compared to user-based authorization [gravitino]

Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on issue #11781:
URL: https://github.com/apache/gravitino/issues/11781#issuecomment-6491927637

   Since this benchmark (2026-06-24), the Basic auth and authorization paths have changed a lot. In particular, #13342 cut the built-in IdP password hash from 100k to 5k SHA3-512 iterations. That hash ran on every Basic request, at about 40 ms each. The issue does not say which authenticator the User Auth run used. If it was `simple`, most of the gap is likely authentication cost, not group→role resolution. The group path still issues a single prefetch query and caches group roles.
   
   @danhuawang could you rerun both modes on current main, with the same authenticator (`basic`) for both? Until we can reproduce the gap, I'm removing the 2.0.0 label.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [Improvement] Group-based authorization adds 2-3x latency overhead compared to user-based authorization [gravitino]

Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on issue #11781:
URL: https://github.com/apache/gravitino/issues/11781#issuecomment-4784985138

   I see. I already work on this one. 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [Improvement] Group-based authorization adds 2-3x latency overhead compared to user-based authorization [gravitino]

Posted by "lasdf1234 (via GitHub)" <gi...@apache.org>.
lasdf1234 commented on issue #11781:
URL: https://github.com/apache/gravitino/issues/11781#issuecomment-4794907159

   > The difference is that, compared to user authorization, group authorization has the following extra steps, which will query database:
   > 
   > [gravitino/plugins/idp-basic/src/main/java/org/apache/gravitino/idp/auth/BasicAuthenticator.java](https://github.com/apache/gravitino/blob/d845d5cddc5bc208968a0e6bf4b594691afdb853/plugins/idp-basic/src/main/java/org/apache/gravitino/idp/auth/BasicAuthenticator.java#L147-L155)
   > 
   > Lines 147 to 155 in [d845d5c](/apache/gravitino/commit/d845d5cddc5bc208968a0e6bf4b594691afdb853)
   > 
   >  private UserPrincipal authenticate(BasicCredentials credentials, String authData) { 
   >    IdpUser user = userGroupManager.authenticate(credentials.username(), credentials.password()); 
   >   
   >    List<UserGroup> groups = 
   >        user.groupNames().stream() 
   >            .map(groupName -> new UserGroup(Optional.empty(), groupName)) 
   >            .collect(Collectors.toList()); 
   >    return new UserPrincipal(user.name(), groups, authData); 
   >  } 
   > We need to use a cache to avoid repeatedly accessing database.
   > 
   > cc [@lasdf1234](https://github.com/lasdf1234)
   
   After conducting further research, I discovered that the reason for the slow performance of group authentication does not lie in the call to the 'authenticate' method. Both user authentication and group authentication involve calling this method.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [Improvement] Group-based authorization adds 2-3x latency overhead compared to user-based authorization [gravitino]

Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on issue #11781:
URL: https://github.com/apache/gravitino/issues/11781#issuecomment-4809049548

   Thanks for the benchmark. Before I start to optimize, I read the JCasbin code first. From the code, the result may be the opposite of what we think. A few things to check with real data:
   
   1. group→role is not an extra step per request.
   The code loads roles with one SQL query (batchGetAuthSubjectsForUser). This one query gets the user, its groups, its direct roles, and its group roles together — only one DB call. The result is also cached in groupRoleCache. So the two ideas in the issue ("cache group→role" and "batch the user→group→role chain") are mostly already done.
   
   2. There is no group inside the enforcer.
   Group roles are bound to the user with the same bindUserRoles(userId, roleId) as direct roles. So in JCasbin, every row is userId → roleId, no matter if the role comes from a user or a group.
   
   With this test setup (User Auth = 2 roles per user role_all + roleN; Group Auth = 1 shared role role_all), Group Auth has fewer roles per user. So the check should be equal or even a little faster, not 2–3× slower.
   
   So from the code, the extra latency is probably not from the JCasbin check. More likely places:
   - The benchmark may use an old version, before the prefetch + groupRoleCache were added.
   - The login part: Basic auth runs selectIdpUserWithGroups (a JOIN on idp_user_group_rel) on every request. In Group Auth every user has group rows to join. If this table has no index, this query gets slow — but this is login cost, not authorization.
   
   Next step: I will test on a real dataset and add timing for each part (login vs. the prefetch SQL vs. enforcer.enforce), to find where the ~130–170ms really goes, instead of adding another group→role cache that already exists. I will share the numbers later.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [Improvement] Group-based authorization adds 2-3x latency overhead compared to user-based authorization [gravitino]

Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on issue #11781:
URL: https://github.com/apache/gravitino/issues/11781#issuecomment-4786902616

   The difference is that, compared to user authorization, group authorization has the following extra steps, which will query database:
   https://github.com/apache/gravitino/blob/d845d5cddc5bc208968a0e6bf4b594691afdb853/plugins/idp-basic/src/main/java/org/apache/gravitino/idp/auth/BasicAuthenticator.java#L147-L155
   
   We need to use a cache to avoid repeatedly accessing database.
   
   cc @lasdf1234 
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [Improvement] Group-based authorization adds 2-3x latency overhead compared to user-based authorization [gravitino]

Posted by "lasdf1234 (via GitHub)" <gi...@apache.org>.
lasdf1234 commented on issue #11781:
URL: https://github.com/apache/gravitino/issues/11781#issuecomment-4787941665

   > The difference is that, compared to user authorization, group authorization has the following extra steps, which will query database:
   > 
   > [gravitino/plugins/idp-basic/src/main/java/org/apache/gravitino/idp/auth/BasicAuthenticator.java](https://github.com/apache/gravitino/blob/d845d5cddc5bc208968a0e6bf4b594691afdb853/plugins/idp-basic/src/main/java/org/apache/gravitino/idp/auth/BasicAuthenticator.java#L147-L155)
   > 
   > Lines 147 to 155 in [d845d5c](/apache/gravitino/commit/d845d5cddc5bc208968a0e6bf4b594691afdb853)
   > 
   >  private UserPrincipal authenticate(BasicCredentials credentials, String authData) { 
   >    IdpUser user = userGroupManager.authenticate(credentials.username(), credentials.password()); 
   >   
   >    List<UserGroup> groups = 
   >        user.groupNames().stream() 
   >            .map(groupName -> new UserGroup(Optional.empty(), groupName)) 
   >            .collect(Collectors.toList()); 
   >    return new UserPrincipal(user.name(), groups, authData); 
   >  } 
   > We need to use a cache to avoid repeatedly accessing database.
   > 
   > cc [@lasdf1234](https://github.com/lasdf1234)
   
   The user's group has already been cached, but the account password verification still queries the database.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org