janhendrik-rust
I have a table with several columns of floating point numbers in a MSSQL 2019 database.
When I try to naively query all the rows in the table the connection times out with an arror
Tds.Protocol (pid<0.621.0>) disconnected: ** (DBConnection.ConnectionError) client pid<0.677.0> timed out because it queued and checked out the connection for longer than 5000ms
Eventually the data is returned, but I am concerned that it takes 2000x longer with the Tds adapter than with the Postgres adapter.
I have created a demo repo that seeds some data and can be used to easily see the performance difference:
(GitHub - janhendrik-rust/slow_going · GitHub)[GitHub - janhendrik-rust/slow_going · GitHub]
The postgres and odbc connections complete the query and return in under 50ms, the Tds adapter takes over 90 seconds on the same size dataset.
Is there a better way to query medium sized datasets using Ecto connecting to a MSSQL server? Or do I have something missing in my configuration?
Trending in Questions
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #hex
- #security











Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
benwilson512
Hey @janhendrik-rust welcome! I’m trying to understand what databases you have set up. Are you connecting to the MSSQL 2019 database via the postgres adapter? If so, how? I was not aware that MSSQL had a postgres compatible interface.
D4no0
Wha
, is this a thing?
sbuttgereit
Pretty sure it doesn’t; unless its third party… and even then not sure how (or why) you’d do it. I’m just about to start a gig helping with a MS SQL Server migration to PostgreSQL which includes a temporary integration piece. Connectivity mismatches is one of the issues which led to them brining me in. Lots of differences from authentication techniques, to data types, etc. not sure it would be feasible to make it work, let alone any reason/benefit at that level.
While the person you’re responding to would need to answer to be sure (naturally), I read their comment as, “2000x longer with Tds connecting to MSSQL server than the PostgreSQL adapter connecting to PostgreSQL.” (with against the same data implied).
If I get some time, and since I just happen to have a MSSQL Server setup on my workstation now due to this other project, I might try the repo the questioner posted to see if I can help; weekend stuff though, I’m afraid.
Onor.io
Couple of things to consider:
1.) Are the MSSQL DB and the Postgres DB both on the same machine? If the Postgres is local and the MSSQL DB isn’t that’d explain the speed difference. Try setting them both up on the same machine and see if that impacts your performance at all.
2.) I’d check the DB parameters mentioned here: Ecto.Adapters.Tds — Ecto SQL v3.11.1 to insure you’re matching everything.
3.) There’s a built-in adapter for TDS in ecto_sql. What happens if you take out the seperate Tds hex package? I’d definitely try the ecto_sql version because if there were any changes made to support better performance they’re likely to have been made to that driver.
Onor.io
It’s hard to imagine a case where you could be assured of an “apples to apples” comparison across DB’s. I mean there are so many things which would factor in to performance. Are all the tables indexed the same? Are all the field types the same? etc. etc.
sbuttgereit
Oh sure… but sometimes something simple can be informative, even if all you get a vague hints or suggestions of what kinds of problems might be present in the actual scenario. The key is to understand the limits of what it is your looking at, if you aren’t looking at the “real thing”.
cmo
Can you show the results using a schema instead of a raw query?
janhendrik-rust
Thanks for everyone’s interrest.
I’m really not trying to do an “apples to apples” comparrison - this is not a database showdown :).
Up until recently I’ve exclusively used Ecto with the Ecto.Adapters.Postgres adapter connecting to a local Postgres 15 container. The query performace has never been an issue. Then I switched the database over to a local MSSQL 2019 Express container and the Ecto.Adapters.Tds adapter.
When I perform the exact same query using the ecto_sql Tds {:tds, “~> 2.3”} adapter the query is up to 2000 times slower than when using the ecto_sql Postgres {:postgrex, "~> 0.17}, adapter on the seeded dataset. Have a look at the repo I posted for the migration and seed script I used.
At first I thought I must be doing something wrong, or there must be something misconfigured on the MSSQL side, or my code - and there still might be. But performing the same queries in DBeaver or sqlcmd/psql utilities had no decernable speed difference between the two local databases.
If I do small queries - returning les than 1000 rows the Tds adapter performs admirably. As the result set increases the time the query takes grows exponentially
Tds Adapter to local MSSQL2019 Express:
The iex code snippet I used to query the MSSQL Ecto Repo
{time, result} = :timer.tc(Ecto.Adapters.SQL, :query!, [MyApp.Repo, "Select top 10000 float_one, float_two, float_three, float_four, float_five, float_six, float_seven, float_eight, float_nine, int_one, int_two, int_three from floats_test", []])Postgrex Adapter to local Postgres 15:
The iex code snippet I used to query the Postgres Ecto Repo
{time, result} = :timer.tc(Ecto.Adapters.SQL, :query!, [MyApp.Repo, "Select float_one, float_two, float_three, float_four, float_five, float_six, float_seven, float_eight, float_nine, int_one, int_two, int_three from floats_test limit 10000", []])This gives me the impression that the serialization of the dataset might be to blame, but I am completely out of my depth as to how to troubleshoot this issue.
I get similar perfomance when using Ecto.Query queries - so the issue seems to be in the Tds adapter implementation.
benwilson512
Great, this is the bit that was missing then. The indication that there is an issue is that other queries by other clients are fast, not that the queries against postgres are fast.
The TDS response time does look a bit N^2, so perhaps there is a bug inside its implementation? If you turn debug logging on what is the log output you get from Ecto? It should tell you how long the query took vs how long parsing the responses took. That may not be a smoking gun depending on where the bug is but it might help.
D4no0
First of all I would ensure that you are using the latest versions of the dependencies. Check the
mix.lockand cross-reference with the releases or do amix deps.update --allto upgrade all of the dependencies to their latest versions.