I'm facing a problem with an app in Java for Android, the app apparently arrives at a point that consumes excessive server resource, if many users connect in the app comes to the point of knocking down the server, the app is in integrated Java with webservice in Laravel.
Below I will post the routine that apparently causes a problem from what we detected on the server, since this routine calls the url that we detected to be consuming excessive resources on the server.
private class UploadDataToServer extends AsyncTask<String, String, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected String doInBackground(String... params) {
try {
HttpParams myParams = new BasicHttpParams();
myParams.setParameter("http.useragent", "Apache-HttpClient/UNAVAILABLE (java 1.4)");
myParams.setIntParameter("http.socket.timeout", 60 * 1000);
myParams.setBooleanParameter("http.connection.stalecheck", false);
myParams.setIntParameter("http.connection.timeout", 60 * 1000);
myParams.setBooleanParameter("http.protocol.handle-redirects", false);
myParams.setIntParameter("http.socket.buffer-size", 8192);
//HttpConnectionParams.setConnectionTimeout(myParams, 100000); //100000
//HttpConnectionParams.setSoTimeout(myParams, 100000); //100000
HttpClient httpClient = new DefaultHttpClient(myParams);
ResponseHandler<String> res = new BasicResponseHandler();
HttpPost postMethod = new HttpPost(
AndyConstants.ServiceType.UPDATE_PROVIDER_LOCATION);
// HttpRequest httpRequest = new HttpRequest();
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair(
AndyConstants.Params.ID, id));
nameValuePairs.add(new BasicNameValuePair(
AndyConstants.Params.TOKEN, token));
nameValuePairs.add(new BasicNameValuePair(
AndyConstants.Params.LATITUDE, latitude));
nameValuePairs.add(new BasicNameValuePair(
AndyConstants.Params.LONGITUDE, longitude));
nameValuePairs.add(new BasicNameValuePair(
AndyConstants.Params.BEARING, bearing + ""));
preferenceHelper.putLatitude(Double.parseDouble(latitude));
preferenceHelper.putLongitude(Double.parseDouble(longitude));
postMethod.setEntity(new UrlEncodedFormEntity(nameValuePairs));
String response = httpClient.execute(postMethod, res);
// String response = httpRequest.postData(
// AndyConstants.ServiceType.UPDATE_PROVIDER_LOCATION,
// nameValuePairs);
AppLog.Log("TAG", "location send Response:::" + response);
JSONObject jsonObject = new JSONObject(response);
if (jsonObject.getBoolean("success")) {
if (jsonObject.getString("is_active").equals("1"))
preferenceHelper.putIsActive(true);
else
preferenceHelper.putIsActive(false);
}
return response;
} catch (Exception exception) {
exception.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(String result) {
stopSelf();
}
}
This routine is in the LocationUpdateService.java file, this file sends the user's location (Latitude / Longitude) to the server from time to time.
I would like to count on your help to get an idea at least of what can be done to solve this problem.