【发布时间】:2015-08-01 06:56:23
【问题描述】:
我们已经开发了几个月的 Shiny 应用程序。但是当我们的 Shiny 应用尝试加载大量数据时,它会非常缓慢。我们甚至使用reactive 函数来重用数据。但是当我们请求不同的数据集时,它仍然像以前一样慢。
我们有一个日志文件,它显示 Shiny 每次从我们的数据库加载数据需要 至少 30.12672 秒或 52.24799 秒。
Shiny 这么慢的原因是什么?是服务器还是数据库?我们可以做些什么来加快速度?
我们正在使用 SQLite 数据库。是Shiny变慢的原因吗?
如果是这样,我们应该使用哪些其他类型的数据库系统来处理大量数据集?卡桑德拉? HBase? Apache Spark?
编辑:
例如,
query <- "SELECT
s.timestamp,
s.particle_concentration as `PM2.5`,
n.code as site
FROM speckdata AS s
LEFT JOIN nodes AS n
ON n.nid = s.nid
AND n.datatype = 'speck'
WHERE strftime('%Y', s.localdate) = 'YEAR'
"
# Match the pattern and replace it.
dataQuery <- sub("YEAR", as.character(year), query)
# Store the result in data1.
data = dbGetQuery(DB, dataQuery)
if(nrow(data) > 0) {
# Convert timestamp to date and bind it to the data.
data$date <- as.POSIXct(as.numeric(as.character(data$timestamp)), origin="1970-01-01", tz="GMT")
}
# Chosen to group the data in one panel.
timePlot(
data,
pollutant = c(species, condition),
avg.time = avg_time,
lwd = 2,
lty = 1,
name.pol = c(species_text_value, condition_text_value),
type = "site",
group = TRUE,
auto.text = FALSE
)
这在 Shiny 中非常慢。
但是当我们使用 SQLite 管理器查询数据集时,4719282 行只需要 1.9 秒!
【问题讨论】:
-
我们谈论的内容有多大?您究竟是如何与 SQLite 后端交互的?您是否尝试过在没有闪亮的情况下测量查询的性能?
-
Have you tried measuring performance of your queries without shiny- 我如何在没有闪亮的情况下衡量您的查询的性能? -
How exactly do you interact with the SQLite backend?- 使用 SQLite 查询。 -
How huge are we talking? How exactly do you interact with the SQLite backend?至少大约 14,000 行。 -
数据存储在 .sqlite3 文件中。请参阅上面的编辑我如何在没有 Shiny 的情况下查询数据。