3

I'm evaluating i-jetty on android. I saw that i-jetty supports NIO and that it enabled by default. This brings me to the point: How does NIO and traditional IO compare on android?

At first glance, it seems that on mobile platform NIO would do better since it may save more memory. On the other hand, the OIO can fit better since usually we don't need many open sockets like we do on Java EE.

Arjan Tijms
  • 37,782
  • 12
  • 108
  • 140
ApriOri
  • 2,618
  • 29
  • 48
  • Test and measure. NIO will save on threads, if you do it right, i.e. in one thread, and therefore saves on thread stacks, which saves memory. At wifi or 4G speeds you are going to be network-bound anyway, not CPU-bound. – user207421 Jun 22 '12 at 00:41
  • According to this http://blog.codepainters.com/2012/02/17/why-java-nio-is-a-better-idea-for-android/ there can be an advantage with NIO avoiding some bugs in the non-NIO socket code. – RenniePet Jul 20 '13 at 10:05

1 Answers1

2

This is not meant to be an answer. Just want to share the result of a quick manual test with two implementations:

  1. NIO with ION (1.1.5) by Koushik Dutta
  2. OIO with OkHttp (1.1.1) by guys in Square

The test is done on the same device (Android 4.0.4) with LTE. Within 8 mins, 108 requests are made one by one (with no concurrency). The requests break down in 5 parts: NIO -> OIO -> NIO -> OIO -> NIO . The request is a HTTP PUT request to UserGrid API that return the same response that is turned to a String and processed in the same way.

In milliseconds:

NIO/ION 60 times   OIO/OkHttp for 48 times        
 Min.   :  889      Min.   :  629.0
 1st Qu.: 1086      1st Qu.:  774.5
 Median : 1426      Median : 1241.0
 Mean   : 1659      Mean   : 1712.2
 3rd Qu.: 1697      3rd Qu.: 1881.2
 Max.   :10913      Max.   :16333.0

 Std Dev: 1329.406  Std Dev: 2254.099

Remarks:

  • The app is restarted between each part. So the NIO/ION test has one more "first run" that is slightly slower. It shouldn't make a big difference to the average/mean, however.

From this test, you can say NIO is more predictable in response time.

As I said, this is not meant to be answer. I'm interested to see other test result and figure out in which scenario NIO/OIO is better. thx

mingfai
  • 1,065
  • 1
  • 10
  • 10
  • This test is favorable to OIO but the NIO result is better. 1) single thread. 2) 3 parts for NIO with one extra initialization. But the difference is not significant so I wouldn't even say it's better to use ION than OkHttp on Android 4.0.4 – mingfai Jul 28 '13 at 21:05