-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add DB connection pool helper #23
Comments
Simply add note to the docs and close it :) |
There are 2 options:
This issue is about 2 |
Hi @dselivanov, |
@long-do I'm think The easiest way to tackle this is to use RestRserve behind proxy (such as HAproxy) and let proxy manage persistent connections to the RestRserve. This way child session will hold the state till the time there is connection between proxy and RestRserve. In order to re-use DB connections you might need to structure your code in a way that it tries to perform DB query and if it fails you request handler re-initialise it. library(RestRserve)
con = NULL
reconnect = function() {
message("reconnecting")
con <<- create_connection()
invisible(TRUE)
}
app = Application$new()
app$add_get("/hello", function(req, res) {
tryCatch(do_something_with_db(req),
error = function() {
# re-init connections
reconnect()
# re-do your staff
do_something_with_db(req)
})
}) But keep in mind that if your app will create new connection for each request (this is by default for all new clients) then db connection will be open for each requests and it might cause significant overhead. |
Hi @dselivanov, |
Just a friendly request. Please add a vignette for working with Databases. Almost all of the R user work with databases. I used RestRserve for a project and was not able to use pool because it leaked every few seconds. I had to create a new connection every request which had a huge overhead. with pool -- 15 - 30 ms This overhead and the fact that I had to use a HaProxy to keep all the connection open throughout allowed my IT team to reject the entire architecture because plumber was performing better and was more scalable without proxy server. There are many people like me who will not be able to make it work in a production environment. Please write a page for best practises working with RestRserve as well. I know it is time consuming to write documentation but it's very essential for new users and advanced alike. Even if you don't have a solution for it. It's good to document it. In future when you have one you can update the document. Just wanted to share my experience with the project. Hope you will understand my point of view. It's a nice project. Keep up the good work. 👍 |
I'm doing my research. Has this issue of database connections across threads been solved in I'm looking at using I like the fact that I was looking at using Also, I don't like the comment style syntax I came across However, if @vikram-rawat and @long-do I think you both seem to know what you're talking about any input is appreciated :) |
@dereckmezquita It's fairly complex to make database connection pool work with Rserve's fork mechanism. It's recommended to open and close connection each time you process request. Yes, there is an overhead, but again I the effort to even develop "workaround" solution (not covering all edge cases) is not trivial. |
Needs IPC communication between Rserve child processes. Related to s-u/Rserve#105
The text was updated successfully, but these errors were encountered: