Fly multi-region causes high latency

Hello everyone,

with following setup i have around 0.9s latency:

3 APPs in FRA region
1 postgres DB in FRA region

Whenever I add a new region:
That means, another APP but in LHR region ( fly scale count 1 --region lhr)
and then I add another postgres DB ( fly machine clone <PG_PRIMARY> --region lhr)

After i scale the infrastructure to LHR and make a request to my application using fly-prefer-region header, with value set to lhr - the respons time of my request will be around 10 seconds or more.

I am using Fly.Postgres and Repo.Local

defmodule Nexus.Repo.Local do
  @moduledoc """
  This module is used to interact with the database using Ecto.
  It uses the Postgres adapter and the otp_app is set to :nexus.
  """
  use Ecto.Repo,
    otp_app: :nexus,
    adapter: Ecto.Adapters.Postgres

  @env Mix.env()

  # Dynamically configure the database url based on runtime and build
  # environments.
  def init(_type, config) do
    Fly.Postgres.config_repo_url(config, @env)
  end
end

defmodule Nexus.Repo do
  use Fly.Repo, local_repo: Nexus.Repo.Local
end

i am also starting Fly.Postgres process
{Fly.Postgres.LSN.Supervisor, repo: Nexus.Repo.Local}, in my application.ex file

The Oban jobs are also configured not to run on any other region

# background jobs {Oban, oban_config()},

    primary_region = System.get_env("PRIMARY_REGION")
    fly_region = System.get_env("FLY_REGION")

    case primary_region do
      nil ->
        Logger.info("Oban running in dev mode.")
        Application.fetch_env!(:nexus, Oban)

      _ ->
        if primary_region == fly_region do
          Logger.info("Oban running in primary region. Activated.")
          Application.fetch_env!(:nexus, Oban)
        else
          Logger.info("Oban disabled when running in non-primary region.")
          [repo: Nexus.Repo.Local, queues: false, plugins: false]
        end
    end
  end

Could anyone give me an idea where to look for, what exactly might cause the high latency?

Thanks.

Added elixir, postgres

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.