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 +++++++++++++")
      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()")

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

Sounds like Heroku is adding latency. Do you have a URL to your test instance so I can trace the network connection?

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)
  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")
1 Like

I tried…
in dev it took 2031 ms
in prod it took 8691 ms.

umm. I really want to do it
But my problem is in logged in dashboard.
I don’t know the way to show you :(:sweat_smile:

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.

1 Like

few seconds, 1 or less

tried this https://www.texty.marketing/non-exist

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; use Drab.Element to update the page instead

I figured that would just be from the HTTP request the server makes to that other server they mentioned earlier?

This 2 seconds is just a poke. What poke does is:

  • get the current assign values from the browser (it can be a long operation if you have a lot of big assigns); it is cached later
  • re-render the page, which also can be a long operation if the page is big
1 Like

Oh wait that’s from the server to the client with response back to server (not client to server with response back to client)? That is crazy slow then, I’ve never seen that be slow in dev! (I use a lot of shared commanders though)

1 Like

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)


Thanks for your help!
I changed from poke to set_props and got much faster.
less than 50ms in dev and less than 1000ms in prod

1 Like

Do you have any idea what causes this delay?

Nope, sorry!