1

I am using Aws SimpleDb to store data for my android app. Using AWS android SDK, I am getting very late responce, is there any way to improve it, in browser, it is getting data in 300 milliseconds for me it is taking about 5 to 10 seconds some times more then that also though i am sending request for 40 rows only.

here is what i am doing.

 private ThreadPoolExecutor threadPool = new ThreadPoolExecutor(poolSize, maxPoolSize,  keepAliveTime, TimeUnit.SECONDS, threadsQueue);

private void getArticles() {

String[] categories = {"kids", "Boys", "Girls",
    "Men", "Women"};

for(final String category : categories) {
runTask(new Runnable() {

  @Override
  public void run() {
    Log.e(TAG, "getting articles for category : " + category);
    String select = "select * from shopDatabase where category = '" + category + "' AND relationType " +
          "= 'none' AND articlePushTime > '2013-04-01 05:46:03.719 GMT+00:00' AND publishDateTime > '2013-04-01 05:46:03.719 GMT+00:00' " +
          " AND score > '0' order by score  desc limit 40";
  SelectRequest selectRequest = new SelectRequest(select);
  selectRequest.setConsistentRead(true);
    List<Item> articles = sdbClient.select(selectRequest).getItems();
    if(articles != null) {
      Logger.log("ERROR", "SQLiteActivity", "articles size is : " + articles.size() + " for category : " + category, runCount);
    } else {
      Logger.log("ERROR", "SQLiteActivity", "articles size is : articles.size() = 0 OR NULL for category : " + category, runCount);
     }
     onDownload.onDownload();
    }
   });
  }
}

public void runTask(Runnable task) { futures.add(threadPool.submit(task)); // threadPool.execute(task); }

I tried to profile it and i found that it is taking lot of time for Unmarshalling, and for every request it is getting credentials.

log responce time:

 04-05 11:39:30.724: E/SQLiteActivity(14448): getting articles for category : kids
 04-05 11:39:49.914: E/SQLiteActivity(14448): articles size is : 40 for category : kids


 04-05 11:39:30.754: E/SQLiteActivity(14448): getting articles for category : Boys
 04-05 11:39:47.644: E/SQLiteActivity(14448): articles size is : 40 for category : Boys


 04-05 11:39:48.964: E/SQLiteActivity(14448): getting articles for category : Girls
 04-05 11:40:02.464: E/SQLiteActivity(14448): articles size is : 40 for category : Girls


 04-05 11:39:49.924: E/SQLiteActivity(14448): getting articles for category : Men
 04-05 11:40:02.724: E/SQLiteActivity(14448): articles size is : 40 for category : Men


 04-05 11:40:02.664: E/SQLiteActivity(14448): getting articles for category : Women
 04-05 11:40:10.024: E/SQLiteActivity(14448): articles size is : 40 for category : Women
Suru
  • 697
  • 8
  • 20
  • What is `runTask()`? One thing to notice is that you are starting many tasks in parallel, which may not be a good idea. Also, these tasks have to live with 10% CPU time _altogether_ if they have background priority, [see here](http://stackoverflow.com/a/14217816/1856738). This means that unmarshalling can take much longer than necessary; also, the DB may not like the parallel requests too much. – class stacker Apr 05 '13 at 06:55
  • In runTask() i am using thread pool. i tried it with out thread pool then also the response is same. – Suru Apr 05 '13 at 07:48
  • Not sure what exactly you mean by "without Thread pool" but I'd suggest you try to set the Thread priority as suggested in the link of my other comment and see if it speeds up things -- chances are it'll speed up things by factor ten, if unmarshalling is really the issue here (AWS responses are typically very fast so I don't expect network latency to be a major issue). – class stacker Apr 05 '13 at 07:57
  • I have edited and added the runTask() method and ThreadPoolExecutor, this may give better picture. without thread pool means not using any thread. – Suru Apr 05 '13 at 09:52
  • Just follow the suggestion from my last comment, it's a single line of modification in the right place, and measure the times again. – class stacker Apr 05 '13 at 09:59
  • 1
    How large is your returned result set? You are calling `select *`, so it fetches all of the data in the 40 rows. How fast is your Internet connection? Does your device use WiFi or cellular network? Also, how are you providing credentials to the SimpleDB client object? – Yosuke Apr 09 '13 at 16:21

0 Answers0