You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Explore a connection pool API in client drivers #281
If we end up having a connection pool, I'd be happy if we didn't have to check in / check out connections from the pool. But connections are not stateless, cursors and asynchronous/noreply requests adds state to the connection. Chances are, we'll have to explicitly get a connection from the pool, and give it back. I'd rather have a thread safe connection. There should be only little benefit from having a connection pool, except perhaps better scheduling reducing the latency (e.g. one thread is in the process of doing a huge bulk insert, and another one wants to do a very simple read).
Connection pools are very useful when you want to issue a bunch of queries that don't need to see each other's writes. (For example, two big inserts into different tables.) Handling connection state might be a pain, but I think we could probably work it out in the official drivers. (I'm more worried about the maintenance burden on third-party drivers.)
So all the node.js packages were using the gen-pool package where you have to manually acquire and release a connection. I think it's not really good for two reasons
obviously, it's not super friendly
it doesn't prevent users from doing errors (releasing a connection that could be re-used by another query)
And I think I came up with something better for rethinkdbdash. When you call run on a query, it's going to:
acquire a connection available
run a query
then if the result is
a datum, error, or complete sequence, the connection is released
an incomplete sequence, the connection is NOT released and will be released only when the user close the cursor or retrieve all the data from the cursor
If no connection is available, create one or wait for one to be released.
The only drawback from this implementation is that if users don't fetch all the data from a cursor and don't close it, the connection will never be released.
How much demand has there been for this? Do we know the interface people basically want? Do they want a pool that they can treat abstractly as a single connection, or do they want a way to check out and return connections from a pool for temporary use?
run() should always accept a connection if given one. If I want to connect to two different rethinkdb instances in the same thread (for example to do some data copying), I should be able to do so.
And if I wish to have a connection pool for each of the databases, I should be able to do so.
Having a connection pool is an orthogonal concept from which connection to use by default.
I don't see what's wrong with repl, even if there are connection pools. Maybe the name could be better, for example default_connection=.
One option might be to make the argument that is passed to run() an abstract class, and to document it.
Something like a ConnectionProvider type, with an abstract function getConnection() -> Connection and probably something like lock(Connection) and unlock(Connection) to implement what @neumino described (so connections are not closed if there are active cursors around). The exact interface might look slightly different depending on the client language.
We could ship with a default SingleConnectionProvider, but people could easily implement their own connection pool mechanisms.
For convenience, we could make run(conn) accept a Connection object as well, which would have the same behavior as connProvider = new SingleConnectionProvider(conn); query.run(connProvider).
Yep, in the case of rethinkdbdash, you can pass a connection to run.
It's only when you don't pass a connection that run is going to try to get a connection from the pool.
When I wrote rethinkdbdash I didn't think of multiple pools. I saw the pool as a way to not have to pass a connection to run, but I can see why it can be useful.
I also currently don't let people manually get a connection from the pool and put it back.
@neumino Would it ever be possible for rethinkdbdash to become the official JS driver, and have the other official drivers follow in it's footsteps? Or would it be impossible due to licensing issues?
The first point is almost done and will be released soon.
The second point is discussed here.
So the official driver is getting close to rethinkdbdash.
The differences then will be mostly about the environment (how you run the tests, etc.), and the code itself (rethinkdbdash is written in JavaScript, and the official driver in CoffeeScript).
For now, rethinkdbdash cannot be the official driver because
it uses only node-protobuf and doesn't work with protobufjs
it doesnt support http connections
#1868 will remove the need for protobuf and I plan to move rethinkdbdash to the JSON API. rethinkdbdash will have to support http connections at least to become the main driver.
So it may happen at some point, but I don't know when.
Yes. We push as much work as possible to the shards, but some work has to be done on the machine that accepted the connection, and you'll also be limited by network bandwidth on that machine if all your clients are connecting to it. (Also, if you have an unsharded table, you can drastically reduce intracluster traffic by connecting the only node hosting the table.)
r.table('whatever').config() should tell you what nodes are acting as shards for the table.
HI, I created a connection pool implementation for Java driver. It wraps connections and provides them in a round-robin fashion, creating new connections as needed. It supports connecting to multiple cluster nodes.
query.run() // use the global pool
query.run(pool) // use the pool and automatically lease/return the connection when done
query.run(connection) // the legacy way
I'm exploring RethinkDB and would like to settle on the best Node driver. It appears pooling is now the main differentiator between this and rethinkdbdash. Although this thread talks about pooling to be in the works for the official driver as well since 2014, there doesn't seem to be a recent update on it. Can somebody please help me choose, depending on what's on the current roadmap?
But it isn't as much of a "must have" as you'd think. For Postgresql, a connection pool is definitely a must have, but that's not true for Rethinkdb which automatically closes connections after 60 seconds if I recall correctly. (citation needed)
We utilize Rethinkdb very heavily without a connection pool and everything works smoothly and is quite speedy, but if you're just starting off I'd recommend using rethinkdbdash right off the bat.
Like @chrisvariety , we too utilize Rethinkdb heavily (from node.js) without a connection pool and everything works extremely well.
Also, we have some node.js based applications that pull data from a number of different RethinkDB databases depending on a number of properties on the incoming request. That kind of situation gets messy if you try to pool connections.
Hi @chrisvariety and @raffi-minassian
You are saying that connection pool and reconnection strategy is not a must have, so how do you deal with this ?
It happens everytime rethinkdb instance need to be restarted or crashes, and right now I have to restart the whole app.
You are saying for me to use rethinkdbdash but I'm not sure I have the time to (once again) refactor all the api methods and implement it with rethinkdash having in mind that people are now focusing on thinky.
I don't need any of the "goods" of rethinkdash for this particular api method. I just want this thing to reconnect, any ideas ?
Cheers.
info: ReqlDriverError: Connection is closed.
at ReqlDriverError.ReqlError [as constructor] (/app/node_modules/rethinkdb/errors.js:23:13)
at new ReqlDriverError (/app/node_modules/rethinkdb/errors.js:68:50)
at TcpConnection.Connection._start (/app/node_modules/rethinkdb/net.js:417:13)
at /app/node_modules/rethinkdb/ast.js:146:29
at tryCatcher (/app/node_modules/bluebird/js/main/util.js:26:23)
at Promise._resolveFromResolver (/app/node_modules/bluebird/js/main/promise.js:483:31)
at new Promise (/app/node_modules/bluebird/js/main/promise.js:71:37)
at Limit.TermBase.run (/app/node_modules/rethinkdb/ast.js:135:12)
at getOneBySecondaryIndex (/app/app/server/_api.js:96:10)
ReqlDriverError: Connection is closed.
at Command.callback (/app/app/server/server.js:617:9)
at ReqlDriverError.ReqlError [as constructor] (/app/node_modules/rethinkdb/errors.js:23:13)
at normal_reply (/app/node_modules/redis/index.js:714:21)
at new ReqlDriverError (/app/node_modules/rethinkdb/errors.js:68:50)
at RedisClient.return_reply (/app/node_modules/redis/index.js:816:9)
at TcpConnection.Connection._start (/app/node_modules/rethinkdb/net.js:417:13)
at JavascriptRedisParser.Parser.returnReply (/app/node_modules/redis/index.js:188:18)
at /app/node_modules/rethinkdb/ast.js:146:29
at JavascriptRedisParser.execute (/app/node_modules/redis-parser/lib/parser.js:415:12)
at tryCatcher (/app/node_modules/bluebird/js/main/util.js:26:23)
at Socket.<anonymous> (/app/node_modules/redis/index.js:267:27)
at Promise._resolveFromResolver (/app/node_modules/bluebird/js/main/promise.js:483:31)
at new Promise (/app/node_modules/bluebird/js/main/promise.js:71:37)
at emitOne (events.js:90:13)
at Limit.TermBase.run (/app/node_modules/rethinkdb/ast.js:135:12)
at Socket.emit (events.js:182:7)
at readableAddChunk (_stream_readable.js:153:18)
at getOneBySecondaryIndex (/app/app/server/_api.js:96:10)
at Socket.Readable.push (_stream_readable.js:111:10)
at TCP.onread (net.js:534:20)
at Command.callback (/app/app/server/server.js:617:9)
at normal_reply (/app/node_modules/redis/index.js:714:21)
at RedisClient.return_reply (/app/node_modules/redis/index.js:816:9)
at JavascriptRedisParser.Parser.returnReply (/app/node_modules/redis/index.js:188:18)
at JavascriptRedisParser.execute (/app/node_modules/redis-parser/lib/parser.js:415:12)
at Socket.<anonymous> (/app/node_modules/redis/index.js:267:27)
at emitOne (events.js:90:13)
at Socket.emit (events.js:182:7)
at readableAddChunk (_stream_readable.js:153:18)
at Socket.Readable.push (_stream_readable.js:111:10)
at TCP.onread (net.js:534:20)
@thomasmodeneis If you already have an existing app then no need to rewrite everything in Rethinkdbdash (though it should be mostly drop-in)
You shouldn't have to restart your whole app after encountering an error like that (assuming Rethinkdb is up), just a retry should make the problem go away. Happy to look at your code if you paste it here.
Ye right I could code the retry myself, but there are dozens of api methods in use and I would have to spend time doing a reconnection strategy just for me. That does not seem constructive for the community.
My question is rather going straight to the point of this ticket:
"We should explore various connection pool designs here and see if implementing one might be beneficial." from Feb 2, 2013 and still today Nov 8 2016, the problem still unresolved.
Correct me if I'm wrong, but this ticket is a must have in any database driver, and the fact that this is the official JS driver and lack of reconnection strategy after +3 years of discussion worries me a little bit.
@thomasmodeneis I don't know the details around your layout but in the few apps that we have running against rethinkdb we either open a new connection when we need it, use it, then close it ... OR ... if keeping connections around we have some functions we pass them through before use to make sure they are still good and if not act accordingly, etc.
I don't know your layout so either style may not be a good approach. Also, either approach would require you to refactor a bunch I guess. So in the end I guess I agree with you that having a connection pool would be nice as it could solve some cases like yours easily. But I also think that it should always be possible to use the driver while managing the connections manually. From what I understand about Rethinkdbdash it is all or nothing in that you have to use the built in pooling.
Without rethinkdbdash, I found a trick: hard-crash on connection errors, and hopefully your server process is wrapped in while(true) or forever or pm2, etc.
Basically:
if(err.name==='ReqlDriverError') {
console.log("Connection error. Crashing and restarting.")
process.exit(1)
}
Activity
nviennot commentedon Mar 13, 2014
If we end up having a connection pool, I'd be happy if we didn't have to check in / check out connections from the pool. But connections are not stateless, cursors and asynchronous/noreply requests adds state to the connection. Chances are, we'll have to explicitly get a connection from the pool, and give it back. I'd rather have a thread safe connection. There should be only little benefit from having a connection pool, except perhaps better scheduling reducing the latency (e.g. one thread is in the process of doing a huge bulk insert, and another one wants to do a very simple read).
mlucy commentedon Mar 13, 2014
Connection pools are very useful when you want to issue a bunch of queries that don't need to see each other's writes. (For example, two big inserts into different tables.) Handling connection state might be a pain, but I think we could probably work it out in the official drivers. (I'm more worried about the maintenance burden on third-party drivers.)
nviennot commentedon Mar 13, 2014
I would argue that managing a connection pool is not a driver concern, but an application / ORM concern.
neumino commentedon Mar 13, 2014
So all the node.js packages were using the gen-pool package where you have to manually acquire and release a connection. I think it's not really good for two reasons
And I think I came up with something better for
rethinkdbdash. When you callrunon a query, it's going to:If no connection is available, create one or wait for one to be released.
The only drawback from this implementation is that if users don't fetch all the data from a cursor and don't close it, the connection will never be released.
mlucy commentedon Apr 1, 2014
How much demand has there been for this? Do we know the interface people basically want? Do they want a pool that they can treat abstractly as a single connection, or do they want a way to check out and return connections from a pool for temporary use?
neumino commentedon Apr 1, 2014
People basically wants to call
run()without passing a connection (and opening/closing it).Like this https://github.com/stingraze/Twitter-RethinkDB/blob/master/twitter-rethinkdb-search-insert.py#L3
If we have a connection pool, we can also take out
repl.nviennot commentedon Apr 2, 2014
run()should always accept a connection if given one. If I want to connect to two different rethinkdb instances in the same thread (for example to do some data copying), I should be able to do so.And if I wish to have a connection pool for each of the databases, I should be able to do so.
Having a connection pool is an orthogonal concept from which connection to use by default.
I don't see what's wrong with
repl, even if there are connection pools. Maybe the name could be better, for exampledefault_connection=.danielmewes commentedon Apr 2, 2014
One option might be to make the argument that is passed to
run()an abstract class, and to document it.Something like a
ConnectionProvidertype, with an abstract functiongetConnection() -> Connectionand probably something likelock(Connection)andunlock(Connection)to implement what @neumino described (so connections are not closed if there are active cursors around). The exact interface might look slightly different depending on the client language.We could ship with a default
SingleConnectionProvider, but people could easily implement their own connection pool mechanisms.For convenience, we could make
run(conn)accept aConnectionobject as well, which would have the same behavior asconnProvider = new SingleConnectionProvider(conn); query.run(connProvider).neumino commentedon Apr 2, 2014
Yep, in the case of
rethinkdbdash, you can pass a connection torun.It's only when you don't pass a connection that
runis going to try to get a connection from the pool.When I wrote
rethinkdbdashI didn't think of multiple pools. I saw the pool as a way to not have to pass a connection torun, but I can see why it can be useful.I also currently don't let people manually get a connection from the pool and put it back.
jcspencer commentedon Apr 3, 2014
@neumino Would it ever be possible for
rethinkdbdashto become the official JS driver, and have the other official drivers follow in it's footsteps? Or would it be impossible due to licensing issues?neumino commentedon Apr 3, 2014
The main two differences with the two drivers are
The first point is almost done and will be released soon.
The second point is discussed here.
So the official driver is getting close to
rethinkdbdash.The differences then will be mostly about the environment (how you run the tests, etc.), and the code itself (
rethinkdbdashis written in JavaScript, and the official driver in CoffeeScript).For now,
rethinkdbdashcannot be the official driver becausenode-protobufand doesn't work withprotobufjs#1868 will remove the need for protobuf and I plan to move
rethinkdbdashto the JSON API.rethinkdbdashwill have to support http connections at least to become the main driver.So it may happen at some point, but I don't know when.
83 remaining items
mlucy commentedon May 7, 2015
r.table('whatever').config()should tell you what nodes are acting as shards for the table.PeterKnego commentedon Apr 10, 2016
HI, I created a connection pool implementation for Java driver. It wraps connections and provides them in a round-robin fashion, creating new connections as needed. It supports connecting to multiple cluster nodes.
This is the basic test: https://github.com/PeterKnego/rethinkdb/blob/connection_pool/drivers/java/src/test/java/com/rethinkdb/FixedConnectionPoolTest.java
coffeemug commentedon Apr 11, 2016
👍
prashaantt commentedon Sep 20, 2016
I'm exploring RethinkDB and would like to settle on the best Node driver. It appears pooling is now the main differentiator between this and
rethinkdbdash. Although this thread talks about pooling to be in the works for the official driver as well since 2014, there doesn't seem to be a recent update on it. Can somebody please help me choose, depending on what's on the current roadmap?internalfx commentedon Sep 20, 2016
@prashaantt If you use rethinkdbdash, you will not be disappointed.
thomasmodeneis commentedon Nov 7, 2016
hey guys any update here ? connection pool and reconnection strategy is must have for javascript driver.
chrisvariety commentedon Nov 8, 2016
@thomasmodeneis #3771 would be the best solution for a JS connection pool.
But it isn't as much of a "must have" as you'd think. For Postgresql, a connection pool is definitely a must have, but that's not true for Rethinkdb which automatically closes connections after 60 seconds if I recall correctly. (citation needed)
We utilize Rethinkdb very heavily without a connection pool and everything works smoothly and is quite speedy, but if you're just starting off I'd recommend using rethinkdbdash right off the bat.
raffi-minassian commentedon Nov 8, 2016
Like @chrisvariety , we too utilize Rethinkdb heavily (from node.js) without a connection pool and everything works extremely well.
Also, we have some node.js based applications that pull data from a number of different RethinkDB databases depending on a number of properties on the incoming request. That kind of situation gets messy if you try to pool connections.
thomasmodeneis commentedon Nov 8, 2016
Hi @chrisvariety and @raffi-minassian
You are saying that connection pool and reconnection strategy is not a must have, so how do you deal with this ?
It happens everytime rethinkdb instance need to be restarted or crashes, and right now I have to restart the whole app.
You are saying for me to use rethinkdbdash but I'm not sure I have the time to (once again) refactor all the api methods and implement it with rethinkdash having in mind that people are now focusing on thinky.
I don't need any of the "goods" of rethinkdash for this particular api method. I just want this thing to reconnect, any ideas ?
Cheers.
chrisvariety commentedon Nov 8, 2016
@thomasmodeneis If you already have an existing app then no need to rewrite everything in Rethinkdbdash (though it should be mostly drop-in)
You shouldn't have to restart your whole app after encountering an error like that (assuming Rethinkdb is up), just a retry should make the problem go away. Happy to look at your code if you paste it here.
thomasmodeneis commentedon Nov 8, 2016
Ye right I could code the retry myself, but there are dozens of api methods in use and I would have to spend time doing a reconnection strategy just for me. That does not seem constructive for the community.
My question is rather going straight to the point of this ticket:
"We should explore various connection pool designs here and see if implementing one might be beneficial." from Feb 2, 2013 and still today Nov 8 2016, the problem still unresolved.
Correct me if I'm wrong, but this ticket is a must have in any database driver, and the fact that this is the official JS driver and lack of reconnection strategy after +3 years of discussion worries me a little bit.
Cheers.
raffi-minassian commentedon Nov 10, 2016
@thomasmodeneis I don't know the details around your layout but in the few apps that we have running against rethinkdb we either open a new connection when we need it, use it, then close it ... OR ... if keeping connections around we have some functions we pass them through before use to make sure they are still good and if not act accordingly, etc.
I don't know your layout so either style may not be a good approach. Also, either approach would require you to refactor a bunch I guess. So in the end I guess I agree with you that having a connection pool would be nice as it could solve some cases like yours easily. But I also think that it should always be possible to use the driver while managing the connections manually. From what I understand about Rethinkdbdash it is all or nothing in that you have to use the built in pooling.
marshall007 commentedon Nov 11, 2016
@raffi-minassian you can initialize rethinkdbdash with
pool: falseand just pass your connection to.run()like you would in the official driver.raffi-minassian commentedon Nov 11, 2016
@marshall007 Sweet. I missed that ... should have looked more carefully....
GeoffreyPlitt commentedon Oct 23, 2017
Without rethinkdbdash, I found a trick: hard-crash on connection errors, and hopefully your server process is wrapped in
while(true)orforeverorpm2, etc.Basically:
Hoping somebody has a better suggestion