wlminimal

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

grych

Creator of Drab

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

Also Liked

metabren

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

grych

Creator of Drab

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

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.

Where Next?

Popular in Questions Top

sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
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
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
tduccuong
Hi, is there any work on GUI with Elixir, that is similar to Electron/Javascript? My idea is to bundle Phoenix and BEAM into a single se...
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
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
earth10
Hi, I’m just starting to build a side-project with Elixir and Phoenix and doing some basic test with Elixir alone. What strikes me is th...
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
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

danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 29603 241
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
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
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
Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3271 127089 1222
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
jaysoifer
Is there a way to rollback a specific migration and only that one (“skipping” all the other ones)? Would mix ecto.rollback -v 200809061...
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

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement