Note that there are some explanatory texts on larger screens.

plurals
  1. POOptimal networking
    primarykey
    data
    text
    <p>I am trying to make the networking part of my app more stable, more optimal, since I recieved some issues, stating it takes too much time for the queries to run. Before I share the pieces of my code, here are some infos:</p> <ul> <li>it is an android app, so a lot of the users may use it on weak mobile data connection</li> <li>currently, there are 50k active users, so the server may have high load during peak hours</li> <li>a third party develops the server, so I can make improvements on the client side only</li> </ul> <p>Most likely, a lot of the issues are coming from weak mobile data connection in the peak hours, but still, if I can do anything to improve the connection, then I would do it.</p> <p>I am managing the queries in an AsyncTask. In <code>onPreExecute()</code> I am doing some initialization only, and showing a Dialog, nothing really happens here. I am doing every important piece in <code>doInBackGround(Void... arg)</code>, here is the exact code:</p> <pre><code>try { HttpClient hc = new DefaultHttpClient(); hc.getParams().setParameter("http.protocol.content-charset", "UTF-8"); HttpParams hp = hc.getParams(); HttpConnectionParams.setConnectionTimeout(hp, Stat.TIMEOUT); HttpConnectionParams.setSoTimeout(hp, Stat.TIMEOUT); HttpProtocolParams.setUserAgent(hp, ActMain.userAgent); httpGet=new HttpGet(item.buildQuery()); HttpResponse resp = hc.execute(httpGet); Stat.result=_result=EntityUtils.toString(resp.getEntity(), HTTP.UTF_8); } catch(MalformedURLException e){} catch(IOException e){} return null; </code></pre> <p>After this, in <code>onPostExecute(Void param)</code> I am processing the result, setting up the needed variables, then launching the <code>Activity</code> to show the results to the users, nothing really important part here.</p> <p>The weird error which happens quite a few times is: instead of a pure JSON formatted result, sometimes the server responds with an almost plaintext formatted 404 error message. I am guessing it is server related, so I cannot do anything to solve it, maybe I could relaunch the query 2-3 times, to make sure the user would recieve results.</p> <p>My real question is: can I improve the pasted code snippet, so it would be a bit more stable/optimal on the client side? Thanks in advance!</p> <p>EDIT: I have managed to trace the issue back to the server, my app has a bigger active user count than I thought, they simply overload the server at times, so everything is fine on my end of the things.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload