-
Notifications
You must be signed in to change notification settings - Fork 287
Use DBConnection #128
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
Use DBConnection #128
Conversation
❤️ 💚 💙 💛 💜 |
Chants: one two! one two! one two! We gotta give what the crowds ask for. |
Not sure I understand, what was changed and why? The parameters are used to get connection parameters which can be useful to get information like the server timezone. |
The full parameter map is passed to the client process on every checkout. By use cases, I rather meant to find out how often it is called and if it It is difficult to abstract using callbacks in two processes to something On Friday, 11 December 2015, Eric Meadows-Jönsson notifications@github.com
|
Sorry, I don't understand this at all. Are you talking about connection parameters?
What is the reason for this? Why was it changed from a function doing a |
There are no DBConnection is designed like this so that the state (i.e. Postgrex.Protocol.state) is fetched once at the start of a transaction and then stored in the client process until commit/rollback is handled. The callbacks (e.g. Postgrex.Protocol.execute/3) are all called in the client process and state changes are saved in the pdict. This means all the logic and state is held in one process for transactions and transactions are independent of pooling and disconnect/reconnection attempts. This independence makes the logic much simpler. I think the pdict usage is well worth it. I should have mentioned this design decision as it turns out to be an optimisation for transactions or prepare/execute/close because state is copied once end the socket only needs to be deactivated once when doing mutplie calls during a pool checkout, such as a transaction. However this PR does not add support for transactions or pooling so I forgot to mention it. |
I will fix the three issue tomorrow using a newer release of DBConnection and keep the requirement at Elixir 1.0.
|
The DBConnection.Connection will be running a timer that will close the socket on timeout of run.
9e7b93c
to
38bff4b
Compare
I haven't been able to fix The ability to use a prepared query prepared by another process has been added in 9e7b93c, which means using prepared queries with a pool just works. The method is efficient in that describing the query is skipped and the type information is reused. However it is inefficient in that a failed execute has to be sent and received to know the query needs to be prepared. This can be made more efficient at a later time. The (query) parameters have been outside the query struct to support this and will be needed for Ecto. |
38bff4b
to
f0e2798
Compare
Can we leave stop support outside of DBConnection and just call it directly José Valimwww.plataformatec.com.br |
Ecto doesnt need stop because it puts the pool under its own supervisor, On 16 December 2015 at 20:30, José Valim notifications@github.com wrote:
|
1.2 has the same issue as above though too On 16 December 2015 at 20:34, James Fish james@fishcakez.com wrote:
|
So why do we need stop? Can't we tell people to supervise it or something On Wednesday, December 16, 2015, James Fish notifications@github.com
José Valimwww.plataformatec.com.br |
@josevalim, @ericmj and I discussed on IRC and its gone. |
Glad to hear @fishcakez! The best way to solve problems ;) |
Moebius currently uses stop/1 so we may need to provide a simple one for On 17 December 2015 at 18:55, José Valim notifications@github.com wrote:
|
@fishcakez if they start the db_connection inside their own simple_one_for_one supervisor, wouldn't that be enough? |
@josevalim if they start one like that how will they stop it? Safely? |
I would like to:
|
9535dc1
to
1c03fb5
Compare
Fixed a bug where ArgumentErrors weren't being raised and added to_string implementation for Query for concise logging. |
Using this branch and a DBConnection fork of Ecto reduces basic query ( The large reduction in transaction overheard comes from more efficient use of postgres (removed 2 round trips) and more efficient pooling (removed 2 calls, 2 casts and 2 |
This is beautiful! I can't wait to get this merged and start the final push towards Ecto 2.0. |
This is ready for review. |
* `:decode` - Decode method: `:auto` decodes the result and `:manual` does | ||
not (default: `:auto`) | ||
* `:decode_mapper` - Fun to map each row in the result to a term, see |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we care about making this public? Would using a mapper offer any advantage over decode: :manual
? If so, maybe we should get rid of decode: :manual
altogether?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We dont need manual anymore. If we can make this backwards incompatible
change may be able to tidy up encode/decode a bit.
If we were to need it, likely it would make sense to add to db_connection.
On Monday, 4 January 2016, José Valim notifications@github.com wrote:
In lib/postgrex/connection.ex
#128 (comment):* `:decode` - Decode method: `:auto` decodes the result and `:manual` does not (default: `:auto`)
- *
:decode_mapper
- Fun to map each row in the result to a term, seeDo we care about making this public? Would using a mapper offer any
advantage over decode: :manual? If so, maybe we should get rid of decode:
:manual altogether?—
Reply to this email directly or view it on GitHub
https://github.com/ericmj/postgrex/pull/128/files#r48723821.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So kill it with 🔥. :)
I've cleaned up the encode/decode so the db_connection protocol is always used. |
…0 migration. Looks like I need to study elixir-ecto/postgrex@8a8ebd1 and eventually elixir-ecto/postgrex#128.
First issue appears to be this commit in Ecto, which changes the expected query result decoding behavior. Looks like I need to study elixir-ecto/postgrex@8a8ebd1 and eventually elixir-ecto/postgrex#128.
* Start moving forward into the Ecto 2.0 tree. First issue appears to be this commit in Ecto, which changes the expected query result decoding behavior. Looks like I need to study elixir-ecto/postgrex@8a8ebd1 and eventually elixir-ecto/postgrex#128. * WIP: Very basic version of decode is working, though we still fail tests related to date-time and binary/blob encoding. * Now handling binary decoding correctly. * Route column names through from sqlitex to Result object. WIP toward deferred value decoding. * Decode value types according to preference from column definitions.
This is WIP.
Issues:
Postgrex.Connection.stop/1
has not been replaced. I could not come up with a good method to stop a supervisor without requiring Elixir 1.2.There are two optimisations in this change because the
DBConnection
API is not exactly equivalent to the oldPostgrex.Connection
:Will need to do benchmark/profile to check performance does not regress before merging.
I have not added any new features in this PR and would prefer these to come one by one in separate PRs. The features (pooling, transactions, network failure handling, idle timeout) require implementing simple callbacks, documenting options and/or wrapping
DBConnection
calls so are almost free.