How to reduce TTFB for webpage using heroku free service - node.js

I recently uploaded a website to heroku (using their free service). The website is built using node.js and express. According to google I had a page speed score of 99 and 100 for mobile and desktop respectively. The following day I made some basic changes to the html and css, and after pushing to heroku again the TTFB is now extremely slow. The app was out of hibernation mode when I did the speed tests. Is this issue with Heroku's servers or should I look for another way to solve it? I don't know how changing the html and css would cause TTFB issues. Is this a common issue with Heroku?
Update: After pushing changes to heroku a second time I had no problems. Seems to have been a glitch with heroku's server.

TTFB is the time that the server takes to show the first byte of content. This audit fails when the browser waits more than 600ms for the server to respond to the main document request.
So, I don't know much about Heroku but if it is a free service, the response time must be much slower than the payment plans.

Related

express nodejs webserver extremely slow, loading times of 4-6 seconds per script/stylesheet

I am developing a cloud server that serves static files for personal use with express and nodejs. While developing I added some script files until I noticed that the webserver suddenly started to load extremely slow on reloads. I used the chrome dev tools and noticed extreme loading times like 6 seconds for a 265 byte script! (See picture)
What I tried:
moving the app.use(express.static(...)) to the very top
clearing cache and application storage as well as restarting the computer several times
serving just a very simple HTML-File with no external scripts or stylesheets which of course reduced the loading time severely but localhost (265 B) still took 2.03 seconds
I am really confused about this, because it happend out of nowhere from one moment to the next and Ive never experienced this issue while developing.
Well, a very stupid mistake: as you can see in the screenshot the throttling is set to Slow 3G. Seems that I changed it from No throttling by mistake. So check the dev tools settings!

Node app running on cPanel hosting shuts down after 30 minutes idle

I have a REST api node app.
Once its running on localhost, it runs until I stop the dev debugging, no errors.
I moved it over to my cPanel hosting, installed a node app.
It starts up the same as localhost.
But after 30 minutes being idle, it shuts down.
The next request after this, restarts the app.
There are no crash or errors in the log, just the restarting messages.
I know this is default behaviour for free hosting, like Heroku but I'm paying for this hosting package.
Does anyone know...
Is this default behaviour for cPanel hosted node apps, or is my app causing this (using too much memory or cpu for example?
Is there any settings that can be edited to change this?
According to the docs, cPanel uses something called Phusion Passenger to run Node.js. In turn, Passenger docs show a default "idle time" of 5 minutes and a default of passenger_min_instances = 1. No idea if cPanel changes the defaults, or if the hosting provider did. I would recommend contacting the hosting provider about the issue in any case, and asking about these options specifically - they may be able to help or tune the service for you.
The startup time for a node app depends on what it's doing. A rest-api could be in the milliseconds, whereas a small Ai app loading a corpus or training a dataset (which mine was) could end up being 30 seconds plus. However the quantity of users did not warrant a dedicated server, so the work-around was to call the endpoint using a CRON, keeping the app alive.
Not perfect, but this type of thing may be useful if you are using aws lambda, which calls a 3rd party service, and which charges based on time taken. Every millisecond counts.

Can I host a website on Heroku? if not, what would be a PaaS like solution?

I am new to web site development, and I have been facing some troubles to find an answer to this question. I use Heroku, nonetheless, the domain is not completely personalized, and it sends the dynos to sleep if no one accesses the page, therefore, the first user will always face delays o page reload. Further, it does seem to appear on Google. Can I use Heroku to create a functional web page? if not, which option would you suggest? I want something simple and efficient: i.e., I want to concentrate on coding my site, not coding details to make it run. Detail: I am using Node Js (MEAN stack).
A verified Heroku account gets 1000 dyno hours every month. A month has 720 hours. If you are deploying only one web app you can permanently host a website there.
There are free solutions that ping your web page in regular intervals to prevent it from sleeping. E.g. you could use the New Relic add on.

Weird behavior when deploying a Node.js app on Heroku

I have a Node.js app on Heroku which uses their standard dynos. When I deploy new code my site remains up, but for a short period of time some code runs twice. I'm assuming it's because what is happening with the dynos to keep the site from having any interruptions. I'm not sure how to prevent this from happening.

How to fine-tune NodeJS server deployed to Azure WebApp for massive load

I deployed node js server to Azure WebApp, and it worked fine. But, I see that sometime the response time is very slow. Also, I see that somewhere above 500 request/second the server start to fail handling request, and I see it use only 15% CPU. Now, I checked and the server return 500 error because the pipe is busy (by the win32 error code). That's why I was wondering if there is something I can change in the IISNode config to improve the server request capacity.
I already enabled the AlwaysOn feature, and also I add a check in Pingdom to keep the site alive. Also, I already changed nodeProcessCountPerApplication to 0 so it use all the available process.
Thank you,
Omer
One thing you can do is enable Always On. Without it, when your site hasn't been visited for 20 minutes the site gets taken down. Then the next time someone makes a request to your site Azure Web Apps warms up (re-sets up) your site but this process takes a few seconds.
Note that Always On is only available for sites in Basic, Standard, or Premium SKUs
Also, check out this page for tips on debugging Node.js apps in Azure Web Apps: https://azure.microsoft.com/en-us/documentation/articles/web-sites-nodejs-debug/

Resources