Tuesday, January 26, 2010

Re: [android-developers] Re: First HTTP/S requests are slow. [Android 1.5]


Yeah probably it has something to do with all the initialization stuff...I just tried *not* using the Apache HttpClient, with the following code:

String myHttpsUrl = "https://mip.sunrise.ch";
URL url = new URL(myHttpsUrl);
URLConnection urlConnection = url.openConnection();

BufferedReader br = new BufferedReader(new InputStreamReader(ucon.getInputStream()));
String line;
StringBuilder htmlContent = new StringBuilder();
while ((line = br.readLine()) != null) {
    htmlContent.append(line);
}

(I'm reading the whole content just to make sure my request has been executed and fetched..).

Anyway....it seems much faster!! (first request around 2 seconds, compared to the HttpClient's 6, 10 or 20 seconds).

However there is a problem: with the current https url it actually doesn't work (it worked for other https addresses). I get back the following error (with the url "https://mip.sunrise.ch"):

java.io.IOException: SSL handshake failure: Failure in SSL library, usually a protocol error
error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol (external/openssl/ssl/s23_clnt.c:585 0xaf589f78:0x00000000)
    at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.nativeconnect(Native Method)
    at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:308)
    at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.getSecureSocket(HttpConnection.java:173)
    at org.apache.harmony.luni.internal.net.www.protocol.https.HttpsURLConnection$HttpsEngine.connect(HttpsURLConnection.java:408)
    at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection.sendRequest(HttpURLConnection.java:1227)
    at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection.doRequestInternal(HttpURLConnection.java:1554)
    at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection.doRequest(HttpURLConnection.java:1547)
    at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1055)
    at org.apache.harmony.luni.internal.net.www.protocol.https.HttpsURLConnection.getInputStream(HttpsURLConnection.java:257)

It seems like an ssl version error...mmmm....
Maybe I have to specify explicitly this version somewhere? Or maybe some certificates? :S

If anyone has an idea please let me know :)


Thanks everyone!
Yuvi

On Tue, Jan 26, 2010 at 8:29 PM, Jason Proctor <jason.android.lists@gmail.com> wrote:
SSL requires a good chunk of crypto code. maybe its initialisation & code-loading time is causing the delay on first use?

one way to find out is to write something as bare-bones as possible (ie without the Apache HTTP library, which is large and complex) and profile it to see where the time is going.




Hi

we're experiencing the same thing - pretty much identical code
initial connection can take up to 30secs but subsequent connections
are only a sec or two

have reproduced on both 1.5 and 2.0 emulators as well as on devices
HTC Hero, Motoral Cliq and Droid

if we change the URL back to HTTP behavior is expected i.e a second or
two

Ronan

On Jan 23, 11:31 pm, Yuvi <yuvidr...@gmail.com> wrote:
 Hi!

 I'm developing my first android app, which needs to make some http and https
 requests.
 I'm using the apache HttpClient. So far everything works fine...but I
 noticed something strange:
 almost every time I start the app, the first request is taking really a long
 time, while the next requests take much less. I tried executing the same
 request several times in a row, and with the same result.

 Here's part of the code I use to make an http request:

 HttpParams httpParams = new BasicHttpParams();
 HttpConnectionParams.setConnectionTimeout(httpParams, 30000);
 HttpConnectionParams.setSoTimeout(httpParams, 30000);
 client = new DefaultHttpClient(httpParams);

 try {
    HttpGet getRequest = new HttpGet ("https://mip.sunrise.ch");
    HttpResponse response = client.execute(getRequest);
    // ....

 } catch (Exception e) { }

 I tested the app on the various versions of the emulator, and on the htc
 hero (android 1.5). With the emulator with android 2.0 it seems that problem
 doesn't occur...mmm? hehe

 Someone has an idea of what am I doing wrong?

 Thanks!!
 Yuvi

--
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+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


--
jason.vp.engineering.particle


--
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+unsubscribe@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+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate