Open pdeva opened 10 years ago
Here are the bean attributes that Jetty exposes with its nosql session manager. I believe Spring Session should support a similar set.
Jetty's nosql session support uses mongodb and not redis, but these values do not seem mongo-centric. The mongo-centric beans are separate.
The values above are provided from http://download.eclipse.org/jetty/stable-9/apidocs/org/eclipse/jetty/server/session/AbstractSessionManager.html
+1
+1
I may be overlooking something obvious here, but what exactly is the "size" of a session?
Question for the project maintainers. Would there be an objection to creating an implementation of SessionRepository that uses a DropWizard Counter and DropWizard Histogram to provide stats similar to what Jetty does? (see my previous Post)
I am curious if there is a philosophical problem with adding the dependency on DropWizard.
@solidjb I don't know a lot about these portions of DropWizzard so it is hard to say definitively. Practically speaking, we are open to adding new dependencies so long as they are part of Spring IO Platform (as we must be Spring IO compliant) and they are optional.
I am still working on the testing, but the class itself is pretty simple.
package org.springframework.session.dropwizard;
import static java.lang.Math.round;
import com.codahale.metrics.Counter;
import com.codahale.metrics.Histogram;
import org.springframework.session.ExpiringSession;
import org.springframework.session.SessionRepository;
/**
* This class will use dropwizard metrics to record statistics about the number of sessions and their durations.
*/
public class DropWizardMetricsRecordingSessionRepository implements SessionRepository<ExpiringSession> {
private final SessionRepository<ExpiringSession> repository;
private final Counter sessionCountingStats;
private final Histogram sessionTimingStats;
public DropWizardMetricsRecordingSessionRepository(
SessionRepository<ExpiringSession> repository,
Counter sessionCountingStats,
Histogram sessionTimingStats
) {
this.repository = repository;
this.sessionCountingStats = sessionCountingStats;
this.sessionTimingStats = sessionTimingStats;
}
@Override
public ExpiringSession createSession() {
final ExpiringSession createdSession = repository.createSession();
sessionCountingStats.inc();
return createdSession;
}
@Override
public void save(ExpiringSession session) {
repository.save(session);
}
@Override
public ExpiringSession getSession(String id) {
return repository.getSession(id);
}
@Override
public void delete(String id) {
final ExpiringSession session = getSession(id);
repository.delete(id);
sessionCountingStats.dec();
if (session != null) {
sessionTimingStats.update(calculateSessionDuration(session));
}
}
private long calculateSessionDuration(ExpiringSession session) {
return round((System.currentTimeMillis() - session.getCreationTime()) / 1000.0);
}
}
What do you think?
The above code would only have the following dependencies:
dependencies {
compile (
libraries.dropWizardCore,
libraries.springSession,
)
testCompile (
libraries.mockitoCore
)
}
I think that meets your criteria. When I am done with the tests, can I create a pull request?
@solidjb Thanks for the reply. The dependencies look like it will work. However, the implementation looks like it lacks support for handling an expired session. Can you create a new ticket that we can use to discuss this (since this does not appear to address this specific issue).
Done - #535
.. Using a JMX metric ideally. Very useful when you want to make sure the session size doesn't go out of hand when using frameworks like Vaadin or gwt