【问题标题】:Shiny + SQLite - why is Shiny extremely slow?Shiny + SQLite - 为什么 Shiny 非常慢?
【发布时间】: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 的情况下查询数据。

标签: r sqlite shiny


【解决方案1】:

我建议直接从数据库测试 SQLite 查询的性能。如果这是您的慢点,您将需要优化查询以使其更高效。在我提供进一步帮助之前,最好知道性能问题的确切位置。

【讨论】:

  • I would suggest testing the performance of your SQLite query directly off the database. - 我们使用 SQLite 管理器查询数据集,4719282 行只需要 1.9 秒。 (请在我上面制作的屏幕截图中查看这一点)。谢谢。
  • 您的查询似乎运行良好。应用程序是否执行任何其他预处理?如果是这样,我会使用“Sys.time()”来更好地了解缓慢的来源。将它们放入您的代码并手动运行(不要运行闪亮的应用程序),它会让您更好地了解您可能需要修复应用程序的位置。
猜你喜欢
  • 2019-03-07
  • 1970-01-01
  • 1970-01-01
  • 2013-06-29
  • 2020-06-11
  • 1970-01-01
  • 2017-01-29
  • 2021-12-03
  • 2011-10-19
相关资源
最近更新 更多