pedrogarrett

pedrogarrett

I have a Phoenix app that has its Postgres data split over about 2,000 different dbs.

Basically, a main db contains the information needed to connect to all of the other dbs… I’ve managed to get this working in Phoenix by statically creating 2,000 different modules that use Ecto.Repo, and dynamically starting up supervisors for all of them after the main Repo is started.

This works fine, but I’ve noticed that compilation now takes a couple of minutes (as opposed to less than 1 second with about 50 modules). That seems over-long… and mix xref always takes a couple of minutes as well. I’ve tried putting the 2,000 module defs into 1 file, and also into 2,000 different files, but it doesn’t seem to make any difference as far as compilation and xref time goes.

Is this just because a couple thousands modules is a lot and it will always take a while, or is there maybe something else going on?

Thanks in advance for any help or information.

Showing Posts 1 to 4

michalmuskala

michalmuskala

Do you have an example project?

I suspect this is simply a question of there being a lot of modules, but I think there might be some things we could speed up.

pedrogarrett

pedrogarrett OP

You can just create a file with 2000 defmodules for repos into the lib folder of an existing Phoenix app (or create a new one) and see the difference.

For a new app, on my machine, it takes 1 second to compile a bare Phoenix app, and 135 seconds to compile it with that file in it.

Also, the “mix xref graph” time jumps from <1sec to about 55 seconds.

Here’s the ruby code I used to to create the file:

file_name = "repo_modules.ex"

code = <<-CODE
defmodule RepoTest.Repo__NDX__ do
  use Ecto.Repo, otp_app: :ebx, adapter: Ecto.Adapters.Postgres
  def init(_, opts) do
    {:ok, Keyword.put(opts, :url, System.get_env("DATABASE_URL"))}
  end
end
CODE

(1..2000).each{|ndx| File.open(file_name,"a"){|f| f.write(code.gsub(/__NDX__/,ndx.to_s))}}
OvermindDL1

OvermindDL1

Whoa, 2000 Repo files is… very big, each repo links to a variety of other Ecto things. use Ecto.Repo, ... is not at all lightweight. A question, why would you ever need that many repo’s, I can see needing a couple max, but that many? o.O?

Can you replicate the issue without using any other libraries? What is the xref graph results of linkages of the main library (not that 2000-repo test)?

pedrogarrett

pedrogarrett OP

Yeah, I realize it’s somewhat ridiculous. :slight_smile:

It’s a legacy application in which we are replacing some of the slower and more memory intensive ruby bits, and unfortunately the application has a couple thousand different dbs, due to a roll-your-own sharding scheme. Since Ecto can’t (as far as I can tell) have one Repo that connects to multiple dbs, this was the solution I came up with… and it’s actually working great, except for the slow compilation (which I can live with… I use a separate branch with just a few repos when doing heavy development).

When you say “without using any other libraries”, does that include Phoenix? I can replicate the issue with a brand new Phoenix app with only the default stuff, and just that one big repo file. The xref output includes just one extra line for that file.

— All posts loaded —

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
kpanic
Hi everyone, I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding. I sta...
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
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
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
apz
I’m new to elixir and just tried to install the elixirLS extension for VScode(ium) and it is throwing some errors that I would like help ...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
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

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews