1

I'm using milton server to support webdav protocol in my project but there is a problem. This is my upload (PUT) method code:

public DavFile upload(InputStream is, String name) {
    DavFile davFile = null;

    if (is != null) {
        File newFile = new File(name);
        BufferedOutputStream os = null;
        byte[] buffer = new byte[1024 * 1024];
        int size;

        try {
            os = new BufferedOutputStream(new FileOutputStream(newFile, false), buffer.length);
            while ((size = is.read(buffer)) > 0) {
                System.out.println("Log: " + name + " | " + size);
                os.write(buffer, 0, size);
            }

            Util.closeOutputStream(os);
            davFile = new DavFile(newFilePath);
        } catch (Exception ex) {
            Util.writeLog(ex);
        } finally {
            Util.closeInputStream(is);
            Util.closeOutputStream(os);
        }
    }

    return davFile;
}

and this is the output:

Log: 722267_119335884931029_2021941220_n.mp4 | 7834
Log: 722267_119335884931029_2021941220_n.mp4 | 7834
Log: 722267_119335884931029_2021941220_n.mp4 | 7834
Log: 722267_119335884931029_2021941220_n.mp4 | 7834
Log: 722267_119335884931029_2021941220_n.mp4 | 7834
Log: 722267_119335884931029_2021941220_n.mp4 | 7834
Log: 722267_119335884931029_2021941220_n.mp4 | 7834
Log: 722267_119335884931029_2021941220_n.mp4 | 7834
Log: 722267_119335884931029_2021941220_n.mp4 | 7834
Log: 722267_119335884931029_2021941220_n.mp4 | 7834
Log: 722267_119335884931029_2021941220_n.mp4 | 7834
Log: 722267_119335884931029_2021941220_n.mp4 | 7834
Log: 722267_119335884931029_2021941220_n.mp4 | 7834
Log: 722267_119335884931029_2021941220_n.mp4 | 7834
Log: 722267_119335884931029_2021941220_n.mp4 | 7834
Log: 722267_119335884931029_2021941220_n.mp4 | 7834
Log: 722267_119335884931029_2021941220_n.mp4 | 3145

How can i increase the read size of InputStream in milton server? I can not change InputStream to any other type like BufferedInputStream!

In my local computer uploa speed is 27KB/s and this is too slow!!!

S.Yavari
  • 876
  • 8
  • 25

2 Answers2

3

There's no reason why that code should be fast or slow. Bytes will be received at the rate they're provided by the network adapter, and using a BufferedInputStream won't help because bytes are already effectively by the network adapter.

I'm very surprised to see local upload speed of 27KB/s, I've never seen antthing that slow before.

I just did a quick test on the milton server i'm currently working on which does very complex processing of files, including chunking and SHA1 calculation, and it gave the following results: UPLOAD time=8541ms SIZE=82,954,392bytes bandwidth= 9,712,491bytes/sec

How have you tested the upload speed, was that from the client or at the server? You can get apparently slow uploads sometimes when measured from the client because of high latency of all the PROPFIND requests the client does before and after the actual upload. That should not be a factor for large files though (Eg 50Mb or more).

If you're testing with Win7 make sure you have cookie authentication enabled otherwise Windows will do every upload twice, first without credentials then again with credentials.

/Brad

brad
  • 857
  • 7
  • 8
  • Thanks Brad. The problem was from my local network. When I published my web application on a real server and test it from my local computer the problem was solved. – S.Yavari Oct 05 '13 at 07:17
0

"Milton, an open-source WebDAV library implemented in a Java Servlet, which allows any data from your application to be exposed via WebDAV. Here's an example using Milton, Hibernate, and Tomcat together, in which Milton, running on Tomcat, is used to provide WebDAV-based access to Hibernate data. Other Java-based WebDAV projects that may be useful to reference when building your own include Jigsaw, Apache Jackrabbit, and the now-retired Jakarta Slide."

based on this, if Milton indeed runs on top of a Tomcat server, you may try to enable gzip compression in tomcat.

John Donn
  • 1,718
  • 2
  • 19
  • 45
  • I did not try that myself but I found the following comment on the web: "Can I compress mp4 files to zip? If I compress mp4 files to zip they reduce to about a third in size. does that mean ... ". So I don't think I understand your comment. – John Donn Oct 03 '13 at 07:46
  • There's a lot of non-sense on the web... especially on the page you're referring to I see something about losing quality when zipping. :D I've tried it myself with some files I downloaded recently: original: 993420 KB, zipped: 990440 KB. I could try `-9` and get more than 0.3%, but I don't think it's worth it. – maaartinus Oct 03 '13 at 08:22
  • That said, there might be a possibility to specify the compression level of mp4 and if you'd use something corresponding with `zip -0`, then you might get something compressible. However, I guess that most of mp4 around is heavily compressed already. Given the ratio of the CPU speed to disk or network speed, you usually can compress everything well. – maaartinus Oct 03 '13 at 08:26