Determining session size

Hi,

I wanted to see how much data was getting stored in the session, but have some difficulties determining. Please see my code below, as described in the below article:

http://stackoverflow.com/questions/1077892/jee-find-session-size

When I use the SizeOfAgent, I get a session size of about 750k for an almost empty application. This is after subtracting the starting session size from the current session because session references a bunch of other JEE objects and would get counted even though it shouldn’t be. I believe this to be inaccurate, but don’t know any other way…

I don’t care how its implemented, but I do need to know how to calculate the session size.

Please help!

Thanks,

Mark

PS. I also tried LambdaProbe, but it isn’t granular enough, and showed even much larger session sizes!


package com.example.testvaadinproject;

import javax.servlet.http.HttpSession;

import sizeof.agent.SizeOfAgent;

import com.vaadin.Application;
import com.vaadin.terminal.gwt.server.WebApplicationContext;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Button.ClickListener;
import com.vaadin.ui.Label;
import com.vaadin.ui.Window;

@SuppressWarnings("serial")
public class TestApplication extends Application {
	private long startingSessionSize = 0;
  
	private Label startingSessionSizeLabel = new Label();
	
	private Label currentSessionSizeLabel = new Label();
	
  @Override
	public void init() {
    WebApplicationContext context = (WebApplicationContext) getContext();
    final HttpSession session = context.getHttpSession();
    startingSessionSize = getSessionSize(session);
    startingSessionSizeLabel.setCaption("Starting session size:");
    startingSessionSizeLabel.setValue(startingSessionSize);
    
    currentSessionSizeLabel.setCaption("Current session size:");
    
		final Window mainWindow = new Window("Test Vaadin Application");
    
		Button memoryButton = new Button("Memory");
		memoryButton.addListener(new ClickListener() {
      @Override
      public void buttonClick(ClickEvent event) {
        currentSessionSizeLabel.setValue(getSessionSize(session));
        mainWindow.showNotification("Memory Used:" + (getSessionSize(session) - startingSessionSize));
      }

    });
		mainWindow.addComponent(memoryButton);
		mainWindow.addComponent(startingSessionSizeLabel);
		mainWindow.addComponent(currentSessionSizeLabel);
		
		setMainWindow(mainWindow);
	}

	private Long getSessionSize(HttpSession session) {
    return SizeOfAgent.fullSizeOf(session);
  }
	
}

Hi Mark,

did you already try to serialize the session and see how large is the result? That should give some kind of an estimate of the session size.

  • Teemu

Hi Teemu,

At your suggestion, I tried to, but got:

Cause: java.lang.RuntimeException: java.io.NotSerializableException: org.apache.catalina.session.StandardSessionFacade

I’m not sure that serializing the session as someone said there is a bunch of ‘stuff’ in the session that should be ignored (hence subtracting starting size of session in my earlier example). But I’m not sure, so need some guidance as to what should be considered…

Thanks,

Mark