wlminimal
Drab is slow in production
Hi I am using Drab for live updating page.
in commander file
defhandler show_dashboard_stats(socket, sender) do
order_id = sender.params["campaign_id"]
user_id = socket.assigns.current_user_id
order = Sales.get_order_by_id(order_id, user_id)
message_status = Messenger.get_all_message_status(order_id)
total_sent = Enum.count(message_status)
deilvered_count = Analytics.get_delivered_message_status_count(message_status)
undelivered_count = Analytics.get_undelivered_message_status_count(message_status)
bitly = Bitly.get_bitly_by_order_id(order_id)
total_clicks = Analytics.load_clicks(bitly)
IO.puts(" ++++++++++++ poking +++++++++++++")
poke(socket,
total_sent: total_sent,
deilvered_count: deilvered_count,
undelivered_count: undelivered_count,
total_clicks: total_clicks
)
IO.puts("+++++++++++++ poking is done ++++++++++")
socket |> exec_js!("DashboardChart.update()")
end
In local server it tooks less than second. but in production it took more than 5 seconds.
I tried to find where is bottleneck and checked function execution time.
Longest time I measured was 1 second from Analytics.load_clicks(bitly) (this function does external api request)
I added IO.puts function before and after poke. and it took more than 5 seconds to print “poking is done”
I think “poke” is the one cause the problem.
Am I correct?
I deployed in Heroku and using Hobby dynos
Marked As Solved
grych
OMG. 2 seconds on DEV? It is definitely not a problem with latency, but with the complexity of your page! Either you page renders for 2 seconds, or you have a plenty of big assigns on the page.
I suggest two solutions for this:
- cut your page into pieces by using partials - here you can see the advantage of this approach
- do not use
Drab.Live, as it must re-render the page at every poke you do; useDrab.Elementto update the page instead
Also Liked
metabren
For what it’s worth:
I was using Drab in production on Google Cloud Platform. Everything was lightning quick. Switched to Heroku and now there’s a noticeable delay in all Drab actions. (but I can’t comment on things taking 2 or more seconds in dev though)
grych
It may make sense that the latency of the network increase time from one to five seconds.
@wlminimal, can you measure how long this single poke takes in dev and prod? Just measure the time difference:
IO.puts(" ++++++++++++ poking +++++++++++++")
t0 = :os.system_time(:milli_seconds)
poke(socket,
total_sent: total_sent,
deilvered_count: deilvered_count,
undelivered_count: undelivered_count,
total_clicks: total_clicks
)
IO.puts("+++++++++++++ poking is done ++++++++++")
IO.puts("it took #{:os.system_time(:milli_seconds) - t0} ms")
OvermindDL1
What is your latency to your heroku server? Like just access a path that doesn’t exist on it and how long does it take to respond 404 from that request?
EDIT: For note, Drab works over Phoenix Channels, it would absolutely not be slow, either the work being done is slow or the network connection is slow.
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









