Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #28459 > unrolled thread

Upload using java nio

Started byWilliam Lopes <williamlopes.dev@gmail.com>
First post2014-05-13 11:37 -0700
Last post2014-05-14 11:38 -0700
Articles 11 — 4 participants

Back to article view | Back to comp.lang.java.programmer


Contents

  Upload using java nio William Lopes <williamlopes.dev@gmail.com> - 2014-05-13 11:37 -0700
    Re: Upload using java nio Arne Vajhøj <arne@vajhoej.dk> - 2014-05-13 20:37 -0400
      Re: Upload using java nio William Lopes <williamlopes.dev@gmail.com> - 2014-05-13 18:38 -0700
      Re: Upload using java nio William Lopes <williamlopes.dev@gmail.com> - 2014-05-13 18:38 -0700
        Re: Upload using java nio Arne Vajhøj <arne@vajhoej.dk> - 2014-05-13 22:00 -0400
          Re: Upload using java nio Arne Vajhøj <arne@vajhoej.dk> - 2014-05-13 22:08 -0400
            Re: Upload using java nio William Lopes <williamlopes.dev@gmail.com> - 2014-05-13 19:35 -0700
              Re: Upload using java nio markspace <markspace@nospam.nospam> - 2014-05-13 20:22 -0700
                Re: Upload using java nio William Lopes <williamlopes.dev@gmail.com> - 2014-05-14 11:35 -0700
    Re: Upload using java nio Josip Almasi <joe@vrspace.org> - 2014-05-14 13:46 +0200
      Re: Upload using java nio William Lopes <williamlopes.dev@gmail.com> - 2014-05-14 11:38 -0700

#28459 — Upload using java nio

FromWilliam Lopes <williamlopes.dev@gmail.com>
Date2014-05-13 11:37 -0700
SubjectUpload using java nio
Message-ID<459ec56a-b369-4261-b819-a4f232362f74@googlegroups.com>
Hi, I'm building a network test with source code (basically) here: http://toolongdidntread.com/android/android-multipart-post-with-progress-bar/

My server contains a php script that contains just a field with name = $_FILES['uploaded_file']['name']

But, this java script file isn't very good, it is using the io lib, and I want change to the nio lib, because of the perfomance.

My doubt is, how do I can set the field 'uploaded_file' or create a channel that connects with it?

Thanks!

[toc] | [next] | [standalone]


#28460

FromArne Vajhøj <arne@vajhoej.dk>
Date2014-05-13 20:37 -0400
Message-ID<5372bab4$0$296$14726298@news.sunsite.dk>
In reply to#28459
On 5/13/2014 2:37 PM, William Lopes wrote:
> Hi, I'm building a network test with source code (basically) here: http://toolongdidntread.com/android/android-multipart-post-with-progress-bar/
>
> My server contains a php script that contains just a field with name = $_FILES['uploaded_file']['name']
>
> But, this java script file isn't very good, it is using the io lib, and I want change to the nio lib, because of the perfomance.
>
> My doubt is, how do I can set the field 'uploaded_file' or create a channel that connects with it?

Why do you expect a file upload to be faster client side with NIO?

Arne

[toc] | [prev] | [next] | [standalone]


#28464

FromWilliam Lopes <williamlopes.dev@gmail.com>
Date2014-05-13 18:38 -0700
Message-ID<e0149c20-6681-4be1-b166-b2dfbf71ebdd@googlegroups.com>
In reply to#28460
Em terça-feira, 13 de maio de 2014 21h37min07s UTC-3, Arne Vajhøj  escreveu:
> On 5/13/2014 2:37 PM, William Lopes wrote:
> 
> > Hi, I'm building a network test with source code (basically) here: http://toolongdidntread.com/android/android-multipart-post-with-progress-bar/
> 
> >
> 
> > My server contains a php script that contains just a field with name = $_FILES['uploaded_file']['name']
> 
> >
> 
> > But, this java script file isn't very good, it is using the io lib, and I want change to the nio lib, because of the perfomance.
> 
> >
> 
> > My doubt is, how do I can set the field 'uploaded_file' or create a channel that connects with it?
> 
> 
> 
> Why do you expect a file upload to be faster client side with NIO?
> 
> 
> 
> Arne

Because I read about this and I found that nio is it a better way, more efficient, like the native languages. I made tests in LTE network and the values are too lower than expected (using io lib). I did a download test on nio and was much better comparing with io lib, so I suppose that is a better ideia make on upload too.

[toc] | [prev] | [next] | [standalone]


#28465

FromWilliam Lopes <williamlopes.dev@gmail.com>
Date2014-05-13 18:38 -0700
Message-ID<d0766aef-64c8-4d72-b41e-d982e9868963@googlegroups.com>
In reply to#28460
Em terça-feira, 13 de maio de 2014 21h37min07s UTC-3, Arne Vajhøj  escreveu:
> On 5/13/2014 2:37 PM, William Lopes wrote:
> 
> > Hi, I'm building a network test with source code (basically) here: http://toolongdidntread.com/android/android-multipart-post-with-progress-bar/
> 
> >
> 
> > My server contains a php script that contains just a field with name = $_FILES['uploaded_file']['name']
> 
> >
> 
> > But, this java script file isn't very good, it is using the io lib, and I want change to the nio lib, because of the perfomance.
> 
> >
> 
> > My doubt is, how do I can set the field 'uploaded_file' or create a channel that connects with it?
> 
> 
> 
> Why do you expect a file upload to be faster client side with NIO?
> 
> 
> 
> Arne

Because I read about this and I found that nio is it a better way, more efficient, like the native languages. I made tests in LTE network and the values are too lower than expected (using io lib). I did a download test on nio and was much better comparing with io lib, so I suppose that is a better ideia make on upload too.

[toc] | [prev] | [next] | [standalone]


#28466

FromArne Vajhøj <arne@vajhoej.dk>
Date2014-05-13 22:00 -0400
Message-ID<5372ce46$0$298$14726298@news.sunsite.dk>
In reply to#28465
On 5/13/2014 9:38 PM, William Lopes wrote:
> Em terça-feira, 13 de maio de 2014 21h37min07s UTC-3, Arne Vajhøj  escreveu:
>> On 5/13/2014 2:37 PM, William Lopes wrote:
>>> Hi, I'm building a network test with source code (basically) here: http://toolongdidntread.com/android/android-multipart-post-with-progress-bar/
>>>
>>> My server contains a php script that contains just a field with name = $_FILES['uploaded_file']['name']
>>>
>>> But, this java script file isn't very good, it is using the io lib, and I want change to the nio lib, because of the perfomance.
>>>
>>> My doubt is, how do I can set the field 'uploaded_file' or create a channel that connects with it?
>>
>> Why do you expect a file upload to be faster client side with NIO?
>
> Because I read about this

Where?

NIO supports non-blocking IO and that could potentially have benefits
server applications with thousands of threads.

But for a client app with just a few threads??

> and I found that nio is it a better way, more efficient, like the native languages.

You found exactly what?

> I made tests in LTE network and the values are too lower than expected (using io lib). I did a download test on nio and was much better comparing with io lib, so I suppose that is a better ideia make on upload too.

It is very easy to get micro benchmarks wrong.

And when there are no logical explanation for why a result is at it is,
then the most likely explanation is that the benchmark is flawed.

Arne


[toc] | [prev] | [next] | [standalone]


#28467

FromArne Vajhøj <arne@vajhoej.dk>
Date2014-05-13 22:08 -0400
Message-ID<5372d035$0$300$14726298@news.sunsite.dk>
In reply to#28466
On 5/13/2014 10:00 PM, Arne Vajhøj wrote:
> On 5/13/2014 9:38 PM, William Lopes wrote:
>> Em terça-feira, 13 de maio de 2014 21h37min07s UTC-3, Arne Vajhøj
>> escreveu:
>>> On 5/13/2014 2:37 PM, William Lopes wrote:
>>>> Hi, I'm building a network test with source code (basically) here:
>>>> http://toolongdidntread.com/android/android-multipart-post-with-progress-bar/
>>>>
>>>>
>>>> My server contains a php script that contains just a field with name
>>>> = $_FILES['uploaded_file']['name']
>>>>
>>>> But, this java script file isn't very good, it is using the io lib,
>>>> and I want change to the nio lib, because of the perfomance.
>>>>
>>>> My doubt is, how do I can set the field 'uploaded_file' or create a
>>>> channel that connects with it?
>>>
>>> Why do you expect a file upload to be faster client side with NIO?
>>
>> Because I read about this
>
> Where?
>
> NIO supports non-blocking IO and that could potentially have benefits
> server applications with thousands of threads.
>
> But for a client app with just a few threads??
>
>> and I found that nio is it a better way, more efficient, like the
>> native languages.
>
> You found exactly what?
>
>> I made tests in LTE network and the values are too lower than expected
>> (using io lib). I did a download test on nio and was much better
>> comparing with io lib, so I suppose that is a better ideia make on
>> upload too.
>
> It is very easy to get micro benchmarks wrong.
>
> And when there are no logical explanation for why a result is at it is,
> then the most likely explanation is that the benchmark is flawed.

Relevant links:

http://www.theserverside.com/discussions/thread.tss?thread_id=26700
http://mailinator.blogspot.com/2008/02/kill-myth-please-nio-is-not-faster-than.html
http://www.theserverside.com/news/thread.tss?thread_id=48449
http://www.thebuzzmedia.com/java-io-faster-than-nio-old-is-new-again/
http://stackoverflow.com/questions/7611152/nio-performance-improvement-compared-to-traditional-io-in-java

Only contradiction is:

http://www.idryman.org/blog/2013/09/28/java-fast-io-using-java-nio-api/

(but I strongly suspect that this result is because he buffer in his
NIO code but not in his IO code)

Arne



[toc] | [prev] | [next] | [standalone]


#28468

FromWilliam Lopes <williamlopes.dev@gmail.com>
Date2014-05-13 19:35 -0700
Message-ID<60090320-366b-4898-ad4c-b8144c42ce29@googlegroups.com>
In reply to#28467
Em terça-feira, 13 de maio de 2014 23h08min50s UTC-3, Arne Vajhøj  escreveu:
> On 5/13/2014 10:00 PM, Arne Vajh�j wrote:
> 
> > On 5/13/2014 9:38 PM, William Lopes wrote:
> 
> >> Em ter�a-feira, 13 de maio de 2014 21h37min07s UTC-3, Arne Vajh�j
> 
> >> escreveu:
> 
> >>> On 5/13/2014 2:37 PM, William Lopes wrote:
> 
> >>>> Hi, I'm building a network test with source code (basically) here:
> 
> >>>> http://toolongdidntread.com/android/android-multipart-post-with-progress-bar/
> 
> >>>>
> 
> >>>>
> 
> >>>> My server contains a php script that contains just a field with name
> 
> >>>> = $_FILES['uploaded_file']['name']
> 
> >>>>
> 
> >>>> But, this java script file isn't very good, it is using the io lib,
> 
> >>>> and I want change to the nio lib, because of the perfomance.
> 
> >>>>
> 
> >>>> My doubt is, how do I can set the field 'uploaded_file' or create a
> 
> >>>> channel that connects with it?
> 
> >>>
> 
> >>> Why do you expect a file upload to be faster client side with NIO?
> 
> >>
> 
> >> Because I read about this
> 
> >
> 
> > Where?
> 
> >
> 
> > NIO supports non-blocking IO and that could potentially have benefits
> 
> > server applications with thousands of threads.
> 
> >
> 
> > But for a client app with just a few threads??
> 
> >
> 
> >> and I found that nio is it a better way, more efficient, like the
> 
> >> native languages.
> 
> >
> 
> > You found exactly what?
> 
> >
> 
> >> I made tests in LTE network and the values are too lower than expected
> 
> >> (using io lib). I did a download test on nio and was much better
> 
> >> comparing with io lib, so I suppose that is a better ideia make on
> 
> >> upload too.
> 
> >
> 
> > It is very easy to get micro benchmarks wrong.
> 
> >
> 
> > And when there are no logical explanation for why a result is at it is,
> 
> > then the most likely explanation is that the benchmark is flawed.
> 
> 
> 
> Relevant links:
> 
> 
> 
> http://www.theserverside.com/discussions/thread.tss?thread_id=26700
> 
> http://mailinator.blogspot.com/2008/02/kill-myth-please-nio-is-not-faster-than.html
> 
> http://www.theserverside.com/news/thread.tss?thread_id=48449
> 
> http://www.thebuzzmedia.com/java-io-faster-than-nio-old-is-new-again/
> 
> http://stackoverflow.com/questions/7611152/nio-performance-improvement-compared-to-traditional-io-in-java
> 
> 
> 
> Only contradiction is:
> 
> 
> 
> http://www.idryman.org/blog/2013/09/28/java-fast-io-using-java-nio-api/
> 
> 
> 
> (but I strongly suspect that this result is because he buffer in his
> 
> NIO code but not in his IO code)
> 
> 
> 
> Arne

Thank you for explanations!

OK, even that I'm wrong, I would like to test using nio lib, just for test. The difference on download test reaches to be large. Maybe for my necessity the nio lib could be better, or not, but I would really like test it.

Do you could help me?

[toc] | [prev] | [next] | [standalone]


#28469

Frommarkspace <markspace@nospam.nospam>
Date2014-05-13 20:22 -0700
Message-ID<lkunhu$ko1$1@dont-email.me>
In reply to#28468
On 5/13/2014 7:35 PM, William Lopes wrote:

> OK, even that I'm wrong, I would like to test using nio lib, just for
> test. The difference on download test reaches to be large. Maybe for
> my necessity the nio lib could be better, or not, but I would really
> like test it.
>
> Do you could help me?


This is what I could find that seems relevant.  There's client 
information at the bottom of the page:

http://rox-xmlrpc.sourceforge.net/niotut/

The obvious search, which might help you find other relevant pages:

https://www.google.com/search?q=java+nio+network+tutorial

[toc] | [prev] | [next] | [standalone]


#28475

FromWilliam Lopes <williamlopes.dev@gmail.com>
Date2014-05-14 11:35 -0700
Message-ID<adb60405-94aa-44f7-bb27-a503a9fd0466@googlegroups.com>
In reply to#28469
Em quarta-feira, 14 de maio de 2014 00h22min36s UTC-3, markspace  escreveu:
> On 5/13/2014 7:35 PM, William Lopes wrote:
> 
> 
> 
> > OK, even that I'm wrong, I would like to test using nio lib, just for
> 
> > test. The difference on download test reaches to be large. Maybe for
> 
> > my necessity the nio lib could be better, or not, but I would really
> 
> > like test it.
> 
> >
> 
> > Do you could help me?
> 
> 
> 
> 
> 
> This is what I could find that seems relevant.  There's client 
> 
> information at the bottom of the page:
> 
> 
> 
> http://rox-xmlrpc.sourceforge.net/niotut/
> 
> 
> 
> The obvious search, which might help you find other relevant pages:
> 
> 
> 
> https://www.google.com/search?q=java+nio+network+tutorial

Thanks, but I already searched so much about this, and just after to research too much that I posted here.

[toc] | [prev] | [next] | [standalone]


#28472

FromJosip Almasi <joe@vrspace.org>
Date2014-05-14 13:46 +0200
Message-ID<lkvl26$vls$1@gregory.bnet.hr>
In reply to#28459
On 05/13/2014 08:37 PM, William Lopes wrote:
> Hi, I'm building a network test with source code (basically) here: http://toolongdidntread.com/android/android-multipart-post-with-progress-bar/
>
> My server contains a php script that contains just a field with name = $_FILES['uploaded_file']['name']
>
> But, this java script file isn't very good, it is using the io lib, and I want change to the nio lib, because of the perfomance.

I gave up nio because it introduces a number of platform specific 
troubles. 'Troubles' being both OS and JVM impl dependent.
You may get OOM with bogus description.
IBM JVM gives more precise OOM explanation, like was it ENOMEM or 
ENOBUFS, which gives you more info on how to tune OS.

Furthermore, there's just a few nio methods that actually utilize proper 
OS functions in order to avoid unnecessary transfer between kernel mem 
and userspace mem.
IIRC, with sun jvm on linux, I've found exactly one nio method that 
actually does the job. And apache mina did not use it:> So neither did 
software using it, many many server software.
(netty does though)

I have no idea how android nio works.

But as the man said, nio is not faster than io - it all depends on other 
threads and their synchronization.
In your case, setProgress() is blocking and synchronized.
Blocking = transfer waits for bar to render.
Synchronized = slow.

Recommendiation:
Make a thread to update progress bar(s). Let it have non-blocking calls 
to update volatile/atomic internal counter(s). Use these calls instead 
of setProgress(). Make it sleep for 100-1000 ms, then render bar(s).

Regards...

[toc] | [prev] | [next] | [standalone]


#28476

FromWilliam Lopes <williamlopes.dev@gmail.com>
Date2014-05-14 11:38 -0700
Message-ID<59a3228e-41fe-46bb-8f68-8d120b54b7e9@googlegroups.com>
In reply to#28472
Em quarta-feira, 14 de maio de 2014 08h46min14s UTC-3, Josip Almasi  escreveu:
> On 05/13/2014 08:37 PM, William Lopes wrote:
> 
> > Hi, I'm building a network test with source code (basically) here: http://toolongdidntread.com/android/android-multipart-post-with-progress-bar/
> 
> >
> 
> > My server contains a php script that contains just a field with name = $_FILES['uploaded_file']['name']
> 
> >
> 
> > But, this java script file isn't very good, it is using the io lib, and I want change to the nio lib, because of the perfomance.
> 
> 
> 
> I gave up nio because it introduces a number of platform specific 
> 
> troubles. 'Troubles' being both OS and JVM impl dependent.
> 
> You may get OOM with bogus description.
> 
> IBM JVM gives more precise OOM explanation, like was it ENOMEM or 
> 
> ENOBUFS, which gives you more info on how to tune OS.
> 
> 
> 
> Furthermore, there's just a few nio methods that actually utilize proper 
> 
> OS functions in order to avoid unnecessary transfer between kernel mem 
> 
> and userspace mem.
> 
> IIRC, with sun jvm on linux, I've found exactly one nio method that 
> 
> actually does the job. And apache mina did not use it:> So neither did 
> 
> software using it, many many server software.
> 
> (netty does though)
> 
> 
> 
> I have no idea how android nio works.
> 
> 
> 
> But as the man said, nio is not faster than io - it all depends on other 
> 
> threads and their synchronization.
> 
> In your case, setProgress() is blocking and synchronized.
> 
> Blocking = transfer waits for bar to render.
> 
> Synchronized = slow.
> 
> 
> 
> Recommendiation:
> 
> Make a thread to update progress bar(s). Let it have non-blocking calls 
> 
> to update volatile/atomic internal counter(s). Use these calls instead 
> 
> of setProgress(). Make it sleep for 100-1000 ms, then render bar(s).
> 
> 
> 
> Regards...

My network test is for android plataform, on my test already I modified like you said. Is a few better now, but I still wait found the answer of how use nio lib.

Thank you!

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.java.programmer


csiph-web