darnahsan

darnahsan

JSON api: plug+cowboy inconsistent request handling

I am new to elixir and did a slack bot(https://github.com/ahsandar/ultronex) few months ago and now added a simple JSON api (https://github.com/ahsandar/ultronex/tree/master/lib/ultronex/server) to it to check stats. The api has basically 5 paths

  • /heartbeat
  • /track
  • /stats
    */ favicon
  • _ (match all to 404)

The slowest of all these endpoint seem to be heartbeat while both track and stats have to fetch values from ets for their JSON response while heartbeat responds with a static JSON. It would be understandable for the _ match to be the slowest because of looking for a matching path before the request is dispatched to it.

I can see the avg time for heartbeat is over 1.7ms while stats and track are below 0.7ms. These are NewRelic numbers. Even in the logs I see the heartbeat to be 5X slower compared to other endpoints. It might seem weird to be questioning times as low as 1 ms but the performance variation is of interest as it adds unpredictability.

Can’t upload images as a new member to show the numbers.

Any help in understanding why this would be happening or did I get something misconfigured as I plan to take elixir and phoenix for my next project but this is a bit boggling why such varied performance. Any help or guidance over why this happens and how to fix this would be nice

The source code can be found on these links

Marked As Solved

darnahsan

darnahsan

Refactoring each path in to its own plug.Router with using forward to pass on the request seems to have made the results more realistic. I think this works for plug+cowboy best. Open to comments over how it can be improved further and whats a better approach or convention.

Where Next?

Popular in Questions Top

shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
logicmason
Hi there, I'm working through my first release with elixir/phoenix. I've built a release with distillery and found that it crashes when I...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list....
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
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
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
Mooodi
Given a string, how can I get access to its character by index? Enum.at("my_string", 2) doesn't work. Or rather, not char, but a substr...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
idi527
I’ve been re-reading swift book again and noticed that multiline strings there don’t have a trailing line break, unlike in elixir iex(2)...
New

Other popular topics Top

senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
Jim
As a follow up to my earlier question: I have the code compiling and running but not getting a successful login from the rest server. ...
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
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 42633 214
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers' Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
AstonJ
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including. What is Phoenix LiveV...
New
Nvim
Elixir appears to be a superior language to Python. I don’t see any advantage of Python over Elixir. Are there any?
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New

We're in Beta

About us Mission Statement