5 Replies Latest reply on Feb 24, 2009 1:46 PM by Ravi Kiran Bhaskar

    FileUpload keepalive memory issue

    Ravi Kiran Bhaskar Newbie

      Hello,
      Iam utilizing rich:fileupload for uploading multiple images with flash, createTemporaryFiles set to true in web.xml. Instead of using session scope Iam using keepalive because the referencing bean is of request scope and hence uploading bean cannot have a session scope. I am using STATE_SAVING_METHOD as server.

      As images are uploaded the memory keeps growing, it never gets cleaned and hence after a couple of days it brings down the server.

       <a4j:status id="resizestatusId">
       <f:facet name="start">
       <rich:progressBar value="100"
       label="Resizing Please Wait..."
       enabled="false" minValue="-1" maxValue="100">
       </rich:progressBar>
       </f:facet>
       </a4j:status>
       <rich:fileUpload id="uploderId"
       uploadData="#{uploaderBean.files}"
       fileUploadListener="#{uploaderBean.listener}"
       listWidth="350"
       listHeight="700"
       maxFilesQuantity="100"
       acceptedTypes="jpg,jpeg,bmp,gif,png,mp3"
       allowFlash="true">
       <f:facet name="label">
       <h:outputText value="{_KB}KB from {KB}KB uploaded --- {mm}:{ss}"></h:outputText>
       </f:facet>
       <a4j:support event="onuploadcomplete" action="#{uploaderBean.resize}" status="resizestatusId"/>
       </rich:fileUpload>
      


      As seen from code I perform resizing of images using image magick after upload is completed.

      Am I doing anything wrong? Can anybody suggest how to alleviate the memory pile up.


      Ravi Kiran Bhaskar
      Principal Software Engineer
      Washington Post Digital
      1515 N Courthouse Rd. Arlington, VA 22201

        • 1. Re: FileUpload keepalive memory issue
          Andrei Markavtsov Apprentice

          Hi,

          I tried to upload a lot of files in flash mode and I didn't see that server's memory heap was increased. Seems that fileupload component is not a cause of the problem.
          Please try to test without resizing.

          • 2. Re: FileUpload keepalive memory issue
            Ravi Kiran Bhaskar Newbie

            Thank you very much andrei for your prompt response. I shall try your suggestion and get back to you with the results

            Ravi Kiran Bhaskar
            Principal Software Engineer
            Washington Post Digital
            1515 N Courthouse Rd. Arlington, VA 22201

            • 3. Re: FileUpload keepalive memory issue
              Ravi Kiran Bhaskar Newbie

              OK andrei here are the results without resizing (Instead of resizing I just copied the files as is to a destination folder in docroot of the server). I was testing this on a sun java application server 9.1 which did not have any other application apart from my app still I see jump in memory usage. Can you tell me when will the AjaxStateManager/AjaxStateHolder clear the cache? I see the same memory even after the session has expired and even if I closed the window. The results are as follows

              before uploading the 'top' showed me the following

              load averages: 0.01, 0.05, 0.20; up 117+01:05:13 13:27:05
              38 processes: 37 sleeping, 1 on cpu
              CPU states: 98.9% idle, 0.0% user, 1.1% kernel, 0.0% iowait, 0.0% swap
              Memory: 8192M real, 5435M free, 2631M swap in use, 20G swap free

              PID USERNAME LWP PRI NICE SIZE RES STATE TIME CPU COMMAND
              5635 wlogic 101 59 0 2791M 1593M sleep 7:47 0.05% java


              After uploading 21.8 MB worth of photographs the 'top' shouwed me the following..

              load averages: 0.64, 0.40, 0.27; up 117+01:14:40 13:36:32
              38 processes: 37 sleeping, 1 on cpu
              CPU states: 99.5% idle, 0.0% user, 0.3% kernel, 0.2% iowait, 0.0% swap
              Memory: 8192M real, 5316M free, 2635M swap in use, 20G swap free

              PID USERNAME LWP PRI NICE SIZE RES STATE TIME CPU COMMAND
              5635 wlogic 103 59 0 2795M 1714M sleep 9:11 2.23% java

              • 4. Re: FileUpload keepalive memory issue
                Andrei Markavtsov Apprentice

                Ravi,

                I think that if state is hold in session scope it should be cleared after session terminated.
                I see that you have memoty encresed after upload, but i still cannot reproduce this. I used tomcat 6 for the test and uploaded a ot of MBs to server. My javaw.exe process still takes memoty heap that it took before upload. Sometimes memory heap increases and then does not clear.

                I think that stateManager is not a cause of the problem. I think JVM keeps already ordered memory for next usage if server allows it. And it should not be cause of server failed after long running time.

                I can suggest you to perform load test of your application to investigate behavior of memoty heap in case of a lot of concurrent users.

                Best regards.

                • 5. Re: FileUpload keepalive memory issue
                  Ravi Kiran Bhaskar Newbie

                  Thnaks andrei for your reply. I shall do profiling of my code. I did another test

                  FYI when I removed keepalive for the uploaderbean and made it immediateupload=true with request scope, The fileUploadListener processed files one by one and sent it through the same Image Magick resizing code with no memory jump, that is why I was thinking that it could be related to keepalive state.