I have a similar use case, although I am only POSTing data and it's a
simple RESTful service, but the data exchange mechanism is the same.
I haven't actually timed it but your times don't seem wildly out from
what I have seen.

One thing that stands out in your code is the timer.  You should
probably separate the timing for the execution of the web service (the
GET) and the data download.  You could also try (just as a test)
replacing the domain with an IP address to avoid the DNS overhead.

Basically I'm saying I think you need to break down the timings to
narrow down the scope of the problem.

IMO I don't think the while loop is the problem.. despite the fact
that it's pretty much the only way to get the data, I don't see how
just using a while loop would cause a delay, although you "could" try
reading raw bytes into a buffer and then encoding to a String at the
end.. but I doubt it would make much difference.

The final "tip" (if you aren't already) is to make this process
asynchronous.  800 milliseconds is an age when you're looking at the
UI waiting for a response, but if this can be done as an asynchronous
task while the user is kept busy with other things then it just ceases
to be a problem.  May not be suitable for your situation, but as a
general rule I always try to design apps (not just mobile) where
anything that may take some time is put off to one side while I keep
the user busy elsewhere.

Oh.. also.. if there are things that don't change frequently on your
server, you could consider implementing a simple local cache.  So you
only go to the web service after some sort of timeout, or if several
services relate to each other (ie same data from different service
endpoints) then you could just have one service that just a diff check
(ie. just asks if anything has changed) and if not uses local cache.
Just key the cache entry on the endpoint URL.

Good luck!

On Nov 23, 6:18 pm, Kumar Bibek <coomar....@gmail.com> wrote:
> Well, my guess would be the long time can be attributed to the while loop
> you have. That is probably where your code is getting stuck.
>
> HttpResponse response = client.execute(request);
>
> Try putting the log after this line, and see the times. If its still quite a
> lot, then you have to worry.
>
> Kumar Bibekhttp://techdroid.kbeanie.comhttp://www.kbeanie.com
>
>
>
>
>
>
>
> On Fri, Nov 19, 2010 at 4:30 AM, Wipeout <4.9fi...@gmail.com> wrote:
> > Hey guys,
> > This is my first post to the Android Developers group. I have been
> > working with HTTP communication in the Android SDK and have noticed
> > that calls to a web service through my app are very slow (taking
> > 800+ms on high speed wifi). They take less than 100ms if I call the
> > web service through the phone's browser. I am developing on a Google
> > Nexus One. The size of the data returned is very small, <1K. I have
> > tried enabling gzip compression, and that helps slightly but I assume
> > there is another problem at hand. I have tried using SOAP with the
> > ksoap2-android library, as well as making things simple using
> > HttpClient and InputStreamReader. Below is my code for the fastest I
> > can make the app perform; using no SOAP, and using GZIP compression. I
> > apologize for the lengthy code -- I think all of it is beneficial for
> > determining the best way to make this request and response happen
> > faster.
>
> > [code]
> > public String GetRest()
> >        {
>
> >        long startTime = System.currentTimeMillis();
> >        String result = "";
>
> >        Log.v("time", "Beginning rest: " + (System.currentTimeMillis() -
> > startTime) + "ms");
>
> >            try
> >            {
> >                HttpClient client = new DefaultHttpClient();
> >                HttpGet request = new HttpGet("https://usad.enlyght.com/ws/
> > AndroidService.asmx/GetWebServiceVersion");
> >                request.addHeader("Accept-Encoding", "gzip");
>
> >                Log.v("time", "Before call: " + (System.currentTimeMillis()
> > -
> > startTime) + "ms");
> >                HttpResponse response = client.execute(request);
> >                InputStream instream = response.getEntity().getContent();
> >                Header contentEncoding = response.getFirstHeader("Content-
> > Encoding");
> >                if (contentEncoding != null &&
> > contentEncoding.getValue().equalsIgnoreCase("gzip")) {
> >                    instream = new GZIPInputStream(instream);
> >                }
> >                InputStreamReader isreader = new
> > InputStreamReader(instream);
> >                BufferedReader reader = new BufferedReader(isreader);
> >                StringWriter sw = new StringWriter();
>
> >                String read;
> >                while ((read = reader.readLine()) != null) {
> >                        result += read;
> >                }
>
> >                client.getConnectionManager().shutdown();
> >        }
> >        catch (Exception e) {}
> >        Log.v("time", "End rest: " + (System.currentTimeMillis() -
> > startTime) + "ms");
>
> >        return result;
> >        }
> > [/code]
>
> > Regards,
> > Adam Smith
> > Norsoft
>
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Android Developers" group.
> > To post to this group, send email to android-developers@googlegroups.com
> > To unsubscribe from this group, send email to
> > android-developers+unsubscr...@googlegroups.com<android-developers%2Bunsubs 
> > cr...@googlegroups.com>
> > For more options, visit this group at
> >http://groups.google.com/group/android-developers?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to