2 Replies Latest reply on Apr 18, 2011 7:20 PM by rafaelcba

    get the HttpSession's size from a WebApp using Byteman

    rafaelcba

      Hello!

       

      Anyone had already used ByteMan to get the HttpSession instaces size from a WebApp using ByteMan? Is it possible?

       

      Regards.

        • 1. get the HttpSession's size from a WebApp using Byteman
          adinn

          Hi Rafael,

          Rafael Soares wrote:

           

          Anyone had already used ByteMan to get the HttpSession instaces size from a WebApp using ByteMan? Is it possible?

          Java does not normally expose object sizes to application code because it is normally of almost no use whatsoever to anything other than the JVM implementation code. Is there a good reason why you need to know the in-memory size of an object?

           

          Also, it's not clear what is meant when you refer to an object's size? Does that include just the storage used for member fields? or also the object header, and/or padding words internal to the object and/or padding which accumulate because of how objects are carved out of heap blocks? Then again maybe you might also want to know how much storage was allocated when the session object was created, both for the object itself and for auxiliary data created to populate its fields? Or maybe you want to include the size of all the data currently referenced from the session object whether it existed before the session was created, was created as part of constructing the session, or was assigned to a member field after creation? All of these might give you a number useful for some purposes but not for others. But none of them taken in isolation will give you much idea about the 'cost' associated with an object. That's why the JVM chooses to expose different memory/GC stats and does not expose per-instance measures.

          • 2. Re: get the HttpSession's size from a WebApp using Byteman
            rafaelcba

            Hi Andrew!

             

            Thanks a lot by the reply!

             

            Java does not normally expose object sizes to application code because it is normally of almost no use whatsoever to anything other than the JVM implementation code. Is there a good reason why you need to know the in-memory size of an object?

            Yes! This is an important information when you've a WebApp in a production env putting a lot of objs on HttpSession. When you need to known what app deployed in AS that's contributing for a possible OOM error. It's like a "profiling" without a profiling tool :-)

             

            Also, it's not clear what is meant when you refer to an object's size? Does that include just the storage used for member fields? or also the object header, and/or padding words internal to the object and/or padding which accumulate because of how objects are carved out of heap blocks? Then again maybe you might also want to know how much storage was allocated when the session object was created, both for the object itself and for auxiliary data created to populate its fields? Or maybe you want to include the size of all the data currently referenced from the session object whether it existed before the session was created, was created as part of constructing the session, or was assigned to a member field after creation? All of these might give you a number useful for some purposes but not for others. But none of them taken in isolation will give you much idea about the 'cost' associated with an object. That's why the JVM chooses to expose different memory/GC stats and does not expose per-instance measures.

            I need the aproximate size of an user's HttpSession at a given time. The size of the HttpSession itself and all objects that it holds. I found a little tool that archive this information - Project SizeOf [1]. As its description says:

             

            "A very simple implementation of C++ keyword sizeof for Java 5+. Developers can use it to know the real size of objects in memory."

             

            It give a size of an specific object instance at a given time.

             

            I used this tool to implement a simple Byteman rule that inspect the HttpSessions created by a WebApp deployed in a JBossWeb instance. The simple Rule is:

             

            RULE JBossWeb Active Sessions info

            CLASS ^org.apache.catalina.session.ManagerBase

            METHOD add

            AT EXIT

            IF TRUE

            DO System.out.println("   ---> Active sessions for the webapp [" + $session.getSession().getServletContext().getContextPath() + "] is: " + $size);

               System.out.println("      ---> List of sessions' ID for this webapp is: " + $this.listSessionIds());

               System.out.println("      ---> The size of all active sessions for this webapp is: " + net.sourceforge.sizeof.SizeOf.humanReadable(net.sourceforge.sizeof.SizeOf.deepSizeOf($this.findSessions())))

            ENDRULE

             

             

            The problem is the SizeOf project needs a Intrument impl instance to calculate the object's size. Because it was designet to be used as a javaagent (them I've created the discussion [2]).

             

            JavaOpts on JBoss' run.conf

             

            JAVA_OPTS="-Xms512m -Xmx512m -XX:MaxPermSize=256m -Dorg.jboss.resolver.warning=true -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000 -Dsun.lang.ClassLoader.allowArraySyntax=true"

             

            #ByteMan agent

            BYTEMAN_HOME="/home/rsoares/java/tools/byteman-1.5.1"

            BYTEMAN_SCRIPT_HOME="/home/rsoares/java/tools/byteman-1.5.1/scripts"

            JAVA_OPTS="$JAVA_OPTS -javaagent:$BYTEMAN_HOME/lib/byteman.jar=script:$BYTEMAN_SCRIPT_HOME/MyBMTests.btm,prop:org.jboss.byteman.debug=true,prop:org.jboss.byteman.verbose=true"

             

            #SizeOf agent

            JAVA_OPTS="$JAVA_OPTS -javaagent:/home/rsoares/java/tools/SizeOf_0_2_1/SizeOf.jar"

             

            When I access a WebApp on JBoss each time a new object is and stored in a active session the rule is fired. The following output apperar on jboss server log:

             

            18:56:03,319 INFO  [STDOUT] Rule.execute called for JBossWeb Active Sessions info_0

            18:56:03,328 INFO  [STDOUT] HelperManager.install for helper classorg.jboss.byteman.rule.helper.Helper

            18:56:03,330 INFO  [STDOUT] calling activated() for helper classorg.jboss.byteman.rule.helper.Helper

            18:56:03,331 INFO  [STDOUT] Default helper activated

            18:56:03,331 INFO  [STDOUT] calling installed(JBossWeb Active Sessions info) for helper classorg.jboss.byteman.rule.helper.Helper

            18:56:03,331 INFO  [STDOUT] Installed rule using default helper : JBossWeb Active Sessions info

            18:56:03,331 INFO  [STDOUT] JBossWeb Active Sessions info execute

            18:56:03,333 INFO  [STDOUT]    ---> Active sessions for the webapp [/jmx-console] is: 1

            18:56:03,333 INFO  [STDOUT]       ---> List of sessions' ID for this webapp is: B79C76EF3266EF09886C3520F288A0C1

            18:56:03,404 INFO  [STDOUT]       ---> The size of all active sessions for this webapp is: 151.1640625Kb

            18:56:38,494 INFO  [STDOUT] Rule.execute called for JBossWeb Active Sessions info_0

            18:56:38,494 INFO  [STDOUT] JBossWeb Active Sessions info execute

            18:56:38,494 INFO  [STDOUT]    ---> Active sessions for the webapp [/jmx-console] is: 2

            18:56:38,494 INFO  [STDOUT]       ---> List of sessions' ID for this webapp is: 1800DAAEEDDC5549B8188B4A94166903 B79C76EF3266EF09886C3520F288A0C1

            18:56:38,552 INFO  [STDOUT]       ---> The size of all active sessions for this webapp is: 154.90625Kb

             

            [1] http://sourceforge.net/projects/sizeof/

            [2] http://community.jboss.org/message/600554