4

Hello I have used File Upload in struts2 with commons-fileuplod .

Edit : When i run my demo from eclipse with right click and run on server so time taken to upload File is very small

**Run From ECLIPSE :**   
 File Size : 247 MB
    Time TAken By upload using Run On server From eclipse  :--> 2989 MS

On other side when i deploy same demo war file to Tomcat in webapps folder and run . So it take more time to upload file compare to previous case . (Why this big time difference ?)

**Run Using Deploy Demo In Tomcat :**
File Size : 247 MB
Time TAken By upload By deploed war file to tomcat web apps folder  :--> 14162 MS

I have change java.io.tmpdir in MonitoredMultiPartRequest.java:

        System.setProperty("java.io.tmpdir", "D:\\ankit");
        System.out.println("java.io.tmpdir :--> " + System.getProperty("java.io.tmpdir"));

        UploadListener listener = new UploadListener(servletRequest);
        // Create a factory for disk-based file items
        FileItemFactory factory = new MonitoredDiskFileItemFactory(listener);
        // Create a new file upload handler
        ServletFileUpload upload = new ServletFileUpload(factory);

        try{
            long start = System.currentTimeMillis();
            List items = upload.parseRequest(servletRequest);
            long end = System.currentTimeMillis();
            System.out.println("Time TAken By upload 3.2.1 :--> " + (end - start));
            getsystemDetail();
      } catch (Exception e){
        errors.add(e.getMessage());
    }

Here I mention My Log:

Run From ECLIPSE :

==== System Property =========
java.io.tmpdir :--> D:\ankit
================================
Time TAken By upload File :--> 2989
==================================
##### Heap utilization statistics [MB] #####
Used Memory:46
Free Memory:85
Total Memory:132
Max Memory:675
File system root: C:\
Total space (mb): 79899
Free space (mb): 31833
Usable space (mb): 31833
File system root: D:\
Total space (mb): 158472
Free space (mb): 117366
Usable space (mb): 117366
This is ServletContext RealPath path ::--> D:\eclipseWorkSpace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\FILEUPLOAD_DEMO_OldLIB\
File Uploaded Succ. TO ::-> D:\ankit\eclipse.zip

Run Using Deploy Demo In Tomcat :

==== System Property =========
java.io.tmpdir :--> D:\ankit
================================
Time TAken By upload File :--> 14162
==================================
##### Heap utilization statistics [MB] #####
Used Memory:100
Free Memory:31
Total Memory:132
Max Memory:1820
File system root: C:\
Total space (mb): 79899
Free space (mb): 31830
Usable space (mb): 31830
File system root: D:\
Total space (mb): 158472
Free space (mb): 117358
Usable space (mb): 117358
This is ServletContext RealPath path ::--> D:\tools\tomcat7-6\webapps\FILEUPLOAD_DEMO_OldLIB\
File Uploaded Succ. TO ::-> D:\ankit\eclipse.zip
HybrisHelp
  • 5,518
  • 2
  • 27
  • 65
  • Nobody have random Idea ! . – HybrisHelp Oct 10 '13 at 08:12
  • 4
    I notice your tomcat lives in you d:/ drive and your eclipse on your c:/. When you upload the file of goes to the temporay directory that is corresponding harddive. Is one of your harddrives faster than the other? Are you uploading the file from your c:/? Thought being the file has to transfer harddrives causing a loss in performance. – ug_ Oct 16 '13 at 07:13
  • 1
    I think ns47731 has good suggestion. @ankit337, Can you test it using java.io.tmpdir on c: drive? – Vitalii Pro Oct 16 '13 at 14:09
  • No my eclipse and tomcat both on same drive . (d:/) I don't think..it could be this much difference..in primary and secondary drives.. – HybrisHelp Oct 17 '13 at 07:14
  • 2
    @ankit337 Im sorry I should have made my comment more clear, If you look at the java.io.tmpdir property you will see where the file is transfered to. In eclipse it is set to your windows temporary directory, in tomcat it is set to the tomcat temorary direction. If the file is located in your c:\ try moving it to your d:\ then uploading it, and/or try moving your tomcat instillation to your c:\. – ug_ Oct 17 '13 at 08:04
  • It must be that. ankit337, try copying the 247MB file from C:\ to D:\ and viceversa. If each operations is ~ 10 seconds, you got it. Nice @ns47731 – Andrea Ligios Oct 17 '13 at 13:04
  • `@ To all` I have edit my question and tested on same `java.io.tmpdir :--> D:\ankit` in both case than after its find big time difference to upload same file . – HybrisHelp Oct 18 '13 at 06:57

1 Answers1

4

Say your 250mb file is on your C:\ and you run from eclipse, it would be copying the file to the same drive to your temp directory. Even when your eclipse lives in your D:\ it is using your Windows OS temp directory as seen on your eclipse config. In your Tomcat test it uses Tomcats temp directory as seen in the config.

So if your file was in the C:\ it would be as follows:

Run from eclipse:

C:\myLargeFile.dat -> C:\Users\ANKITV~1.PAT\AppData\Local\Temp\myLargeFile.dat

Run Using Deploy Demo In Tomcat

C:\myLargeFile.dat -> D:\tools\tomcat7-6\temp\myLargeFile.dat

I do not know your hardware setup but the results would vary greatly if your C:\ was a solid state and your D:\ was not. There are also performance losses when transferring between hard drives even with high performance hard drives, you can witness this outside java by copying a large file between the 2 drives and do the same but just copying the file to a different location in the same drive and keep an eye on how long it takes (make sure you copy it not move it).

Some good ways to test if this is the issue:

  1. Change the temporary directory for your tomcat test to your C:\ . Check this post for more information on how to do so: How is the Tomcat temp directory location defined?
  2. Move your tomcat insallation to your C:\ and test it again. Pretty self explanatory but could be more work if you have system variables or scripts pointing to it.
  3. Put your 250mb file in your D:\ and try to upload it to your tomcat test and see if the time gap lowers.

Could you test this for us and let us know what you find? I am interested to hear the results! Below are the points in the configuration file I am referring to:

Run from eclipse:

...
java.io.tmpdir=C:\Users\ANKITV~1.PAT\AppData\Local\T...
...

Run Using Deploy Demo In Tomcat

...
java.io.tmpdir=D:\tools\tomcat7-6\temp
...
Community
  • 1
  • 1
ug_
  • 11,267
  • 2
  • 35
  • 52
  • Thanks for respond , `@ To all` I have edit my question and As per your suggestion tested on same `java.io.tmpdir :--> D:\ankit` in both case than after its find big time difference to upload same file . – HybrisHelp Oct 18 '13 at 06:58
  • @ankit337 have you tried putting the file in your d:\ and uploading it? I dont have much else to run on here. – ug_ Oct 19 '13 at 07:08
  • Heres some final thoughts, 1. deploy the war to Eclipse's tomcat instillation manually and try it (would rule out eclipse playing a role in it). 2. Copy Eclipses's tomcat outside the eclipse installation and put it somewhere else in your file system. Basically break apart tomcat from eclipse to see if it is the compiler playing a role in speed. – ug_ Oct 21 '13 at 18:48
  • I am newbie in eclipse . I tested This on same tomcat say `tomcat7-6`. Already tomcat is in my file system say `D:/Tools/tomcat7-6` .From the eclipse i also give reference to this same tomcat say `D:/Tools/tomcat7-6` . I tested Like 1> Run On server From eclipse 2> Put `.war` in tomcat webapp DIR . – HybrisHelp Oct 22 '13 at 08:11