R 그림자가있는 R 반짝이 풀을 사용하여 oracle 데이터베이스에 연결했습니다. 나는 더 간단한 버전을 만들었고 오류를 재현 할 수있었습니다. 데이터베이스 풀/연결 중 어느 것이 사용되는지에 관계없이 잠시 동안 작동 한 다음 임의로 연결을 끊습니다. 큰 응용 프로그램에서는 처음으로 작동하고 모든 후속 요청이 실패합니다. 이 코드는 랩톱의 RStudio를 통해 정상적으로 작동하지만 리눅스와 R Shiny Pro 대신 Windows를 통해 배포됩니다. 언제든지 POOL
에 disconnect
을 부르지 않을 것입니다. 풀 코드가 패키지에 캡슐화되어R Shiny App이 데이터베이스에서 R Shiny Pro
library(DT)
POOL <<- MyDB::openPool()
server <- function(input, output, session) {
output$db_studies <- DT::renderDataTable(
DT::datatable(
DBI::dbReadTable(POOL, "STUDY") %>%
data.table::data.table() %>%
dplyr::arrange(desc(DATE_CREATED)),
)
)
output$db_studies2 <- DT::renderDataTable(
DT::datatable(
dplyr::tbl(POOL, "SAMPLE") %>%
dplyr::filter(DATASET_ID %in% 57) %>%
dplyr::collect(n = Inf)
)
)
}
server.R
library(shiny)
library(shinythemes)
library(dplyr)
library(readr)
ui <- fluidPage(theme = shinytheme("lumen"),
titlePanel("Google Trend Index"),
sidebarLayout(
sidebarPanel(
),
mainPanel(
DT::dataTableOutput("db_studies", width = "100%"),
DT::dataTableOutput("db_studies2", width = "100%")
)
)
)
ui.R
:
openPool <- function(..., keyFilename = "db_key.RData",
credentialsFilename = "db_login.txt",
connectionInfoFilename = "db_connection.Rdata") {
credentials <- getCredentials(keyFilename = keyFilename, filename = credentialsFilename)
connectionInfo <- getConnectionInfo(filename = connectionInfoFilename)
POOL <- pool::dbPool(...,
drv = ROracle::Oracle(),
dbname = paste(
"(DESCRIPTION=",
"(ADDRESS=(PROTOCOL=tcp)",
"(HOST=", connectionInfo$host, ")",
"(PORT=", connectionInfo$port, "))",
"(CONNECT_DATA=(SID=", connectionInfo$sid, ")))", sep = ""),
host = connectionInfo$host,
port = connectionInfo$port,
username = credentials$username,
password = credentials$password
)
POOL
}
패키지의 목적이었다 그 (것)들을 분리하기 위하여 데이터베이스 자격 증명 및 처리, 그러나 위의 간단한 테스트를 위해 데이터베이스를 직접 쿼리하고 몇 가지 새로 고침 후에도 데이터베이스 풀이 무효화되고 실패합니다.
처음에는 POOL
개체를 인스턴스화하고 전달했습니다. 예제가 어떻게 수행되지 않는지 보면서 대신 글로벌 POOL
개체를 만들어 직접 참조하려고했습니다. 또한 openConnection
을 통해 또는 풀 checkout
을 통해 직접 연결을 시도하고 몇 번 시도한 후에 두 연결을 끊습니다.
## In your pool function, put maximum connection in drv as below
drv = ROracle::Oracle(max.con=128)
또한, 항상 풀 연결을 누출 종종 문제가있는 것입니다 :
응답을 보내 주셔서 감사합니다. 그러나 max.con은 오라클의 매개 변수가 아닌 것 같습니다. 그리고 나는 Pool의 기본값이 Inf입니다. lapply를 호출하면 사용 가능한 모든 연결이 닫히고 더 빨리 실패하는 것처럼 보입니다. – ysaletore