-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Improve cleanUpExpiredSessions query #847
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@vpavic also MAX_INACTIVE_INTERVAL column might be not necessary. It can be added to necessary queries by just calculating. This can also eliminate a necessary update in session tables in case a change in this value. |
It seems that you are not taking into account that both Servlet API (via There's an example of such API usage in Spring Session's public final void loginSuccess(HttpServletRequest request,
HttpServletResponse response, Authentication successfulAuthentication) {
if (!this.alwaysRemember
&& !rememberMeRequested(request, this.rememberMeParameterName)) {
logger.debug("Remember-me login not requested.");
return;
}
request.setAttribute(REMEMBER_ME_LOGIN_ATTR, true);
request.getSession().setMaxInactiveInterval(this.validitySeconds);
} With that in mind, naturally we need to persist the max inactive interval in a dedicated column in order for session cleanup to work correctly. Regarding the SQL statement used for cleanup of expired sessions, actually the statement originally was basically the same as @okohub suggested but this was problematic in some scenarios - see #679. Finally, note that you can always use |
Thanks for the clarification @vpavic. It seems dedicated column is required for the Servlet Session API. What about adding another column to find a workaround speed up deleting process? There is a column |
@rwinch and I have discussed this, and we agree that pre-calculating session's expiry time and persisting it in dedicated column seems as the way to go considering the performance of session cleanup. We're targeting this enhancement at the 2.0 release. |
This commit improves session cleanup handling in `JdbcOperationsSessionRepository#cleanUpExpiredSessions` by optimizing the used SQL statement. This is done by calculating the session expiry time when persisting the session, which in turn allows the cleanup SQL statement to be more index-friendly. Closes spring-projectsgh-847
This commit improves session cleanup handling in `JdbcOperationsSessionRepository#cleanUpExpiredSessions` by optimizing the used SQL statement. This is done by calculating the session expiry time when persisting the session, which in turn allows the cleanup SQL statement to be more index-friendly. Closes spring-projectsgh-847
This commit improves session cleanup handling in `JdbcOperationsSessionRepository#cleanUpExpiredSessions` by optimizing the used SQL statement. This is done by calculating the session expiry time when persisting the session, which in turn allows the cleanup SQL statement to be more index-friendly. Closes gh-847
It seems OK at first glance. 🥇 |
Hello,
I was profiling our production database, which is MySQL, and found that expiration query is not optimized.
This query is not using any index. However, if you change query to something like this you will get a point;
We know that MAX_INACTIVE_INTERVAL is constant in our table, so this expression can be evaluated before query execution
Now, final query will be one of these:
Simple and index friendly.
Is there a chance to review this?
Thank you.
The text was updated successfully, but these errors were encountered: