Slow response times on Heroku

Hey guys. I’m pretty new to Elixir and Phoenix after swapping from NodeJS & MongoDB. Some of my requests are taking 1-2 seconds on the first attempt. Each request thereafter is about 300-400ms. How do I increase the speed of these responses? The smaller responses range from 40-60ms to 100-150ms on my local machine on the first request. The server is located in the US and I’m in Australia. (This adds about 300ms automatically)

Do these numbers sound normal? What steps can I take to increase these speeds?

  • I’ve tried increasing the Ecto pool size to 20
  • I’m running a Heroku Hobby plan

Well, they kinda sound normal to me but it’s hard to judge without codebase. The only thing thing that is really strange is increased first attempt speed and i have no clue what could case that. Anyway the first thing that i would look is the database. check indexes and n+1 stuff.

The reason for the slower response on the first hit is that you are most likely running your application via mix, which will lazy load code. If you were running a release, the code would be eagerly loaded, and you would most likely not notice such a large initial slowdown.

As for other slow responses - without knowing the details of the query being made, we won’t be much help. Is it using indexes? 50-100ms isn’t too bad though. If you’re still not happy, perhaps consider using a service to profile the request. That would provide greater insight into what is going on.

1 Like

I was experiencing the same on test deploys to Heroku, but that was because I was using the free plan, where the dyno will sleep after 30 minutes of inactivity.

2 Likes

When I was first experimenting with Elixir I used Herokus free hosting tier and experienced exactly the behaviour OP is describing. However he’s on the Hobby plan (which doesn’t sleep) that I later used and found to be very quick, with no delays on the first request.

I’m not 100% on the minutiae of Elixir on Heroku — I don’t think it’s a full blown release a la Distillery, but it also seems faster than straight mix. Again, when I used to run on their Hobby plan I found it to be very fast from the off. I used the build packs which AFAIK is the only way to deploy to Heroku?

It sounds like something else is going on here. Running on Heroku it’s unfortunately harder to debug and see what’s going on using things like the observer. The only thing that does stand out was your use of a POOL_SIZE=20. The docs suggest less than the max to allow for running admin tasks.

Have you tried using standard web speed tools like Pingdom? Whilst not specific to your app’s architecture, it might give you an idea if you’re just suffering from DNS issues. The fact that the first load is slow but future ones are fast could be due to DNS…

We recently have had the same thing on a Ruby on Rails-repository. We moved to Heroku for ease of installation, but ended up moving away because of:

  • The inability to easily direct www.* to your normal application because Heroku requires you to point your DNS at a dynamic IP which DNS does not natively support.
  • The difficulty in properly managing environment variables. It is possible to manage these, but only from within their UI, AFAIK.
  • Most importantly, the slow response times: They were four-five times slower than on our own VPS, and with that easily took more than a second (and often five or six), which is simply unacceptable for a modern web-application.

Because that was a Rails-application (using Sqlite as DB), I’m not sure if Elixir/Ecto pool sizes are the bottleneck here, but I’d love to hear your thoughts, because we also were unable to find out what caused this issue.

I’ve been using some $3 OVH VM’s to host some elixir stuff recently and I’m surprised how well it runs, only 2 gigs ram and a single core but it’s worked really well and it’s easy enough to upgrade if I need, plus it’s a full root OS install so you can do whatever you want.

1 Like

Isn’t 1-core crippling for Elixir though?

Not really, all IO is async, and these aren’t loaded down by any stretch (IRC/Discord bots, git webhooks, static website rebuilder, etc… and these all run on the same $3 VM). Anything big will run on my big servers.

2 Likes