Which method is faster for loading multi table in Ecto?

Hello, I am creating a new web service which needs to be faster. for this purpose, I guess to have a few solutions.

solution one :

I’ll be trying to get tabels like single-by-one , that is not good solution.

solution two :

I’ll be trying to get tabels with many Tasks, for example :

{ Task 1 = tabel One, Task 2 = tabel Two, Task 3 = tabel Three } if 3 Tasks is complete or 3 Tasks = 3 Array, then I use this.

if my solution is Invalid, please tell me how can I be faster in this ?

Note :These tables have nothing to do with each other for joining.

If I do understand you correctly you are asking whether you should issue the queries one after the other or concurrently, I have trouble to understand your pseudo code…

You need to benchmark this on realistic resultsets, under realistic load…

  1. Doing the queries concurrently will result in more copying of the result sets as each query happens in another process
  2. Doing the queries concurrently will result in more exhaustive use of your connection pool, so other requests/processes in your application might need to wait more time until they get a connection to the database

These are my two main issues I do see with querying concurrently.


Hamm :thinking: , Thank you @NobbZ , but what is your suggestion for this? What should I do for loading faster?

it’s clear that I think I haven’t understood it. sorry :frowning_face:

Try to set up a benchmark and evaluate both of your solutions.

Like in http://engineering.liefery.com/2018/02/27/the-mysterious-query.html

Maybe you can add a view with a UNION which would load all data necessary from multiple tables in a single query.

1 Like
  1. I wouldn’t even bother until I have identified the queries as the bottleneck.
  2. Then I’d start to optimise the queries itself. Probably using raw SQL over Queries DSL.
1 Like