I'm trying to upload a file from an android application, process it on the server and obtain a result. The server side processing takes about 10s, however on the android app, the process takes about 15s. I'm unable to account for the difference.
Here is the relevant part of code in the application:
HttpParams params = new BasicHttpParams();
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
HttpClient client = new DefaultHttpClient(params);
HttpPost httpPost = new HttpPost(url);
httpPost.setHeader("Authorization", getAuthString());
httpPost.setEntity(multipart);
httpPost.getParams().setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, false);
HttpResponse response;
try {
Long start = System.currentTimeMillis();
Log.v("Network Call", "Time start: " + start);
response = client.execute(httpPost);
Long end = System.currentTimeMillis();
Log.v("Network Call", "Time end:" + end);
Log.v("Network Call Response Time", "Time:" + (end - start));
}
The above Logs indicate total time to be about 15s (varies randomly between 11-17 seconds) On the server, I measured time when the HTTP Post request was made, and time taken for apache to complete the request. This was about 10s (Mostly consistent).
The difference happens to be the time difference between the end of the server php script and the time when the android client receives the data. (The data transferred is very small - < 5 characters)
This does not happen for other requests sent from the client to the server (GET requests) - where the total time is less than a second, and data transferred is larger (hence network latencies and bandwidth does not seem to be the problem)
My questions are the following:
add this :
HttpConnectionParams.setConnectionTimeout(httpParams,
TIMEOUT_MILLISEC);
HttpConnectionParams.setSoTimeout(httpParams, TIMEOUT_MILLISEC);