Application consuming a lot of server resource

0

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.

    
asked by anonymous 28.03.2018 / 20:45

2 answers

0

I'll put together some ideas for this optimization here, to help or start debating some of them.

I think you will not have a cake batter solution in this case, we'll need to test.

  • Limit the time the request is sent in the APP
  • Is it possible to send, for example, a request every two seconds?

  • Check the webserver configuration to see if it is maintaining the process for a long time even after completing the request (this maintains an unnecessary consumption)
  • Apache / Nginx creates a process for each request, a process that can be optimized if you better understand the need for the application. In other words, a process might not have to start consuming 20mb of memory, so it may not have to have a very high timeout. But here we are starting to optimize the same webserver.

  • Test the 'unitary' consumption of the request in order to make it leaner.
  • Is it possible to make the process simpler? Less query, maybe a simpler loop. Things that can make consumption less.

        
    28.03.2018 / 23:30
    0

    I'm also developing a WS (RESTfull)

  • Check your server.
  • Check the machine where the Server is.
  • I make a unit test of 10 requisition / second.
  • Break your time like 100 / 1s, 100 / 0.5s, 100 / 0.25s until you pick up the stack overflow.
  • This is done right now, you know that if you synchronize the req / s you could handle thousands of requests very well in a minute.
  • Note: Some Web Service like Américas.com Shoptime Submarine control access. In 2014 in Black fraud thousands of people stayed in front of the pc for a few minutes in a virtual queue at the time I was not a programmer but I understood that it was not to bring down or even slow the site. Today I know why to do this. Summary The problem is not meeting 3600 requisitions per minute the problem is if they are received in the last second of the last minute. Control your stack overflow.

        
    29.03.2018 / 18:53