I am wondering why my node.js code on heroku is executing slower than my exact copy of that code on c9? I am running the code with the same database and choosing a more expensive dyno in heroku doesn't make a difference of course....
the following example displays my console.logs with timestamp for each line of code...heroku constantly takes 2-3 times longer than c9 and I don't understand why.
is this cpu concerned? But even if it is in theory, running heroku with the most expensive dyno doesn't help neither... Thank you so much in advance!
heroku:
mm:ss:SSS
line 1: 53:35:456
line 122: 53:35:460 - takes 4 ms
line 145: 53:35:600 - takes 140 ms
line 147: 53:35:671 - takes 71 ms
line 149: 53:35:818 - takes 147 ms
c9:
line 1: 59:20:141
line 122: 59:20:143 - takes 2 ms
line 145: 59:20:189 - takes 46 ms
line 147: 59:20:214 - takes 25 ms
line 149: 59:20:257 - takes 43 ms
There are several possible causes for a slow application but to address the question "why is Heroku slower than c9" you first need to compare the specifications on the machines.
Heroku dyno specs are published here: https://devcenter.heroku.com/articles/dyno-types At the time of writing these are:
Dyno Type Sleeps Professional Features Memory (RAM) CPU Share Dedicated Compute free yes no 512 MB 1x no 1x-4x hobby no no 512 MB 1x no 1x-4x standard-1x no yes 512 MB 1x no 1x-4x standard-2x no yes 1024 MB 2x no 4x-8x performance-m no yes 2.5 GB 100% yes 11x performance-l no yes 14 GB 100% yes 46x
The "micro" plan on c9.io (again, at the time of writing) appears to be 512Mb of RAM and 1xCPU which is probably comparable with a free dyno on Heroku (source: Cloud9 Hosting specs)
If you are not seeing a performance increase when using a larger dyno type (
standard-2x
or above) this suggest that the bottleneck for the application is elsewhere. If you install an application monitoring add-on e.g. New Relic from https://elements.heroku.com/addons/categories/monitoring This will give you a breakdown of where the application is spending time during the request cycle.The remaining factor would be latency between your environment and any external resources. For example if you are running an RDS data in the same region as your Cloud9 instance, but your Heroku dyno is running in a different AWS region (see https://help.heroku.com/X1JPM2Z6/where-is-each-region-geographically-located to determine this) then the latency between Heroku and your RDS instance will be a major factor in the response times.