1

I have a website using Django that loads about 100 rows from a single table in a postgresql database when entering it.

Development server locally: Page loaded in 300ms
Production server on Heroku: Page loaded in 1.34secs (about 4.13 times slower) (Integrated gunicorn and loading my static files from aws S3 on a non-idling dyno)

wth?

Note that there is no traffic yet on my production server and I am using 1 dyno.

When I used the exact same setup as my development server for my production server on Heroku it was even slower. Is such a difference in loading time normal?

Specs of my computer:

Memory: 3.7 GiB  
Processor: Intel® Core™ i5 CPU M 520 @ 2.40GHz × 4   
OS type: 64-bit 
Bentley4
  • 10,678
  • 25
  • 83
  • 134
  • Do you find this happening on "first" hit? – Henrik Andersson Feb 04 '13 at 11:41
  • On the first loading of the page of a new browser session yes. What about subsequent 'hits', would that be expected? (I have not integrated any caching yet) – Bentley4 Feb 04 '13 at 11:43
  • 1
    I don't use Heroku, but from looking at the page on dynos it seems like the dynos are EC2 micro instances? I'm guessing this based on the fact that 512 MB is reserved for each dyno. If this is the case, that would explain your dramatic difference in speed as the micro instance is very heavily throttled. You can see this in action by running `top` and looking at the `st` value on the 3rd line. If they're not mapped to micro instances, then ignore what I've said. – CadentOrange Feb 04 '13 at 11:48
  • 1
    We're suffering from the same thing when we deploy our django or rails applications, the first hit will be drastically slow but after that it works fine. These are all answers that will explain whats happening. http://serverfault.com/questions/275035/why-is-my-site-intermittently-slow-to-load-seemingly-due-to-dns-issues and http://stackoverflow.com/questions/2606190/why-are-my-basic-heroku-apps-taking-two-seconds-to-load – Henrik Andersson Feb 04 '13 at 11:56
  • @Cadent orange: I don't know how to see from the `st` value if 'they' are mapped to micro instances. Could you take a look at the following? This is from top immediately after loading the page: `top - 11:56:41 up 18 days, 17:39, 0 users, load average: 45.05, 26.24, 23.36` `Tasks: 2 total, 1 running, 1 sleeping, 0 stopped, 0 zombie` `Cpu(s): 56.0%us, 42.6%sy, 0.0%ni, 0.2%id, 0.0%wa, 0.0%hi, 1.1%si, 0.1%st` – Bentley4 Feb 04 '13 at 12:04
  • @Limelight: After one hour of inactivity a dyno idles. It takes about 2-3 secs to get it active. But I am now talking about an active dyno. Also, the load time is quite constant, pretty stable for subsequent loads. Srry for underspecifying this. – Bentley4 Feb 04 '13 at 12:08
  • 1
    From your top output, the `st` value is 0.1% (see the last entry on the last line). It looks like you're not running on a micro instance after all, where `st` values can be as high as 90%. I'm afraid as I don't use Heroku, I have nothing useful to add. – CadentOrange Feb 04 '13 at 13:54
  • No body ask about database Plan? – dani herrera Feb 04 '13 at 19:38
  • I have the free plan. Which part of the database plans would cause a slower query from the first load? – Bentley4 Feb 04 '13 at 21:26

1 Answers1

0

If my computer has about 3.9 Gb ram and one dyno indeed has 512Mb ram according to this source, that means my computer has about 7.8 times more ram. According to this source ram is very significant for increasing performance of db queries. Since I'm doing quite a few queries the time difference makes sense to me.

Running top in my heroku app directory surprisingly returns 35 Gb ram though. But according to this source running top in Heroku is performed from a different dyno(one-off dyno) your app is running on.

The only thing I don't understand now is why a one-off dyno has so much ram.

As long as nobody gives a better answer I'll keep this answer checked.

Community
  • 1
  • 1
Bentley4
  • 10,678
  • 25
  • 83
  • 134