我正在使用 Aws SimpleDb 为我的 android 应用程序存储数据。使用 AWS android SDK,我得到了很晚的响应,有什么办法可以改进它,在浏览器中,它在 300 毫秒内获取数据对我来说它需要大约 5 到 10 秒的时间,虽然我正在发送仅请求 40 行。
这就是我正在做的事情。
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); }
我试图对其进行分析,我发现解组需要花费大量时间,并且对于每个请求,它都会获取凭据。
日志响应时间:
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