Douvi

Douvi

API heartbeat take around 100ms to reply

I created an API to check if my server is alive, after checking the log I saw my reply take >= 100s from the server but on my computer, it takes about 8ms… Can someone tell me why?

Log

14:06:29.154 request_id=XXX [info] GET /api/heartbeat
14:06:29.154 request_id=XXX [info] Sent 200 in 306s
14:06:34.155 request_id=XXX [info] GET /api/heartbeat
14:06:34.155 request_id=XXX [info] Sent 200 in 86s
14:06:39.153 request_id=XXX [info] GET /api/heartbeat
14:06:39.153 request_id=XXX [info] Sent 200 in 112s

API

def api_heartbeat(conn, _params) do
    send_resp(conn, :ok, "")
end

Route

pipeline :api do
    plug :accepts, ["json"]
  end

scope "/api", PhoenixTWeb do
    pipe_through :api

    get "/heartbeat", PageController, :api_heartbeat
end

mix.exs

defmodule PhoenixT.MixProject do
  use Mix.Project

  def project do
    [
      app: :phoenix_t,
      version: "1.1.0",
      elixir: "1.8.2",
      elixirc_paths: elixirc_paths(Mix.env()),
      compilers: [:phoenix, :gettext] ++ Mix.compilers(),
      start_permanent: Mix.env() == :prod,
      deps: deps(),
      test_coverage: [tool: ExCoveralls],
      preferred_cli_env: [coveralls: :test, "coveralls.detail": :test, "coveralls.post": :test, "coveralls.html": :test]
    ]
  end

  # Configuration for the OTP application.
  #
  # Type `mix help compile.app` for more information.
  def application do
    [
      mod: {PhoenixT.Application, []},
      extra_applications: [:logger, :runtime_tools, :peerage]
    ]
  end

  # Specifies which paths to compile per environment.
  defp elixirc_paths(:test), do: ["lib", "test/support"]
  defp elixirc_paths(_), do: ["lib"]

  # Specifies your project dependencies.
  #
  # Type `mix help deps` for examples and options.
  defp deps do
    [
      {:phoenix, "~> 1.4.6"},
      {:phoenix_pubsub, "~> 1.1"},
      {:phoenix_html, "~> 2.11"},
      {:phoenix_live_reload, "~> 1.2", only: :dev},
      {:gettext, "~> 0.11"},
      {:jason, "~> 1.0"},
      {:plug_cowboy, "~> 2.0"},
      {:excoveralls, "~> 0.10", only: :test},
      {:distillery, "~> 2.0", override: true},
      {:peerage, "~> 1.0"},
    ]
  end
end

conf.exs

use Mix.Config

# Configures the endpoint
config :phoenix_t, PhoenixTWeb.Endpoint,
  url: [host: "localhost"],
  secret_key_base: "secret_key_base",
  render_errors: [view: PhoenixTWeb.ErrorView, accepts: ~w(html json)],
  pubsub: [name: PhoenixT.PubSub, adapter: Phoenix.PubSub.PG2]

# Configures Elixir's Logger
config :logger, :console,
  format: "$time $metadata[$level] $message\n",
  metadata: [:request_id]

# Use Jason for JSON parsing in Phoenix
config :phoenix, :json_library, Jason

# Import environment specific config. This must remain at the bottom
# of this file so it overrides the configuration defined above.
import_config "#{Mix.env()}.exs"

prod.exs

config :phoenix_t, PhoenixTWeb.Endpoint,
  http: [:inet6, port: "${PORT}"],
  url: [host: "${HOST}", port: "${PORT}"], # This is critical for ensuring web-sockets properly authorize.
  cache_static_manifest: "priv/static/cache_manifest.json",
  server: true,
  secret_key_base: "secret_key_base",
  root: ".",
  # TODO - Need to remove the ligne below
  check_origin: false,
  version: Application.spec(:phoenix_t, :vsn)

# Do not print debug messages in production
config :logger, level: :info

Marked As Solved

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

Mix lazy loads code. The first request always takes longer since it needs to get the code loaded. After that your 86microseconds and 112 microseconds are all pretty close. Keep in mind we’re talking about a difference of 20 millionths of a second.

Also Liked

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

This looks like a terminal output problem, mine displays as Sent 200 in 92µs. Your terminal is probably having trouble displaying the µ

Where Next?

Popular in Questions Top

aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
LegitStack
I’m trying to make a websocket server in Phoenix or raw Elixir. I heard about gun, I think I could use cowboy, but since I’m not that sma...
New
Lily
In templates/appointment/index.html.eex: <%= for appointment <- @appointments do %> <tr> <td><%= appoi...
New
vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New

Other popular topics Top

marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 41539 114
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

We're in Beta

About us Mission Statement