janhendrik-rust

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?

Showing Posts 1 to 10

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

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

D4no0

Wha :open_mouth: , is this a thing?

sbuttgereit

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

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

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

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

cmo

Can you show the results using a schema instead of a raw query?

janhendrik-rust

janhendrik-rust OP

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:

Result Set size Query Time in ms
10 3.861
100 5.083
1_000 53.342
2_000 178.746
4_000 3_467.661
8_000 20_511.550
16_000 88_519.569

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:

Result Set size Query Time in ms
10 2.902
100 1.699
1_000 5.838
2_000 8.308
4_000 10.226
8_000 28.109
16_000 78.704

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

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

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

D4no0

First of all I would ensure that you are using the latest versions of the dependencies. Check the mix.lock and cross-reference with the releases or do a mix deps.update --all to upgrade all of the dependencies to their latest versions.

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews