Forums

Why so slow?

Loading a hosted website for the first time after a number of idle hours is painfully slow.

Even a basic test page takes maybe 12 to 16 or more seconds to load. On subsequent loads, they are fine, they load fast. It's as if hosted sites drop out of cache after say eight hours or so.

Can the cache be made bigger or do we have to run a script or something to 'keep awake' the site?

I don't have anything production level hosted but would like to host a site for a small business that would be accessed infrequently.

Thanks.

12 to 16 seconds definitely feels like it's too long. What web framework are you using?

In general, we have a 26-hour timeout on web apps, so if it's inactive for over a day, we shut it down. It's not quite that simple though, because we sometimes rotate out servers, reboot them, etc.

I think we should be able to do something to "pre-warm" web apps for paying users though. I'll add a ticket to the tracker and discuss with colleagues... In the meantime, you could write a little scheduled tasks that pings each of your apps using a requests.get, every hour?

Cheers, tested with simple web2py and very basic Flask.

Just playing about and testing at the moment but intend to host one or two small sites.

Same here. I'm pretty frustrated as I was planning to move my online shop here from hostgator.

The staging site is here now, though, and after 1/2 a day of not touching it, it takes >10 seconds to load a page. Subsequently it's ok, but this doesn't make me confident about moving the online shop here :(

I'm on the $12/month plan, and using Django + Mezzanine + Cartridge.

Just to clarify, is the loading time acceptable while the site is active? It's only the latency after a prolonged idle period which is an issue?

For reference, I just loaded my test app, which is a trivial little "hello world" written in Flask, after at least days of inactivity and it loaded in around 3 seconds. So, I'm guessing that the delay may be Python initialisation time, which would be very low for my trivial app with no dependencies.

As a result, it might be useful to indicate how many Python files your code is split over, and how many external libraries you import (just very roughly). I'm guessing importing your own files may be slightly slower than standard libraries because of the way the filesystem works on PA, but that's just a guess. It might be interesting to try sticking them in a zip file or similar to see if that helps/hinders loading time.

The loading time is fine while the site is active. As far as I can tell, the slowness comes after hours of it being inactive.

Is there a way to extend this inactivity period before the webapp shuts down, if this is the cause?

I'm not certain how many files are being imported though. It's not a complex site at all, so it's pretty much out of the box Python + Mezzanine + Cartridge.

Hm, interesting - so it may be that the import time isn't relevant then. It was just an idea.

I wonder if perhaps it's some sort of initialisation which those libraries do on load, then - that's something that would be very specific to a framework. If there was some delay due to the PA architecture, I would have expected my simple app would show it as well.

You make an interesting point, and I had previously tested it out locally as well as on my linode server but didn't experience any of it.

Maybe someone from PA can chime in?

Whenever we bounce one of our servers, the first hit to a user's web app does some PA-specific initialisation which can take about 10 seconds. That's probably the bulk of the delay you're seeing. As it happens we've got some optimisations going through testing that should speed that up a bit, but there will still be a noticeable lag for that first hit after a reboot.

We reboot the servers every couple of days. Busy websites tend not to notice, because they get thousands of hits every hour, so a handful are slow and then it's back up to normal speed. But if you have a site that you only visit once a day, then for sure, every other time you visit it's going to feel slow on the first hit.

Like I say, we'll discuss ways that we could maybe "pre-warm" the web apps of paying customers at some point in the future. You can also write yourself a scheduled task to ping your web app every hour, to make sure it's warm.

Yeah, that's true, a scheduled task might be a good way to go. Presumably just a GET of any page on the site would do?

If you've got a production site which isn't visited frequently then I'd say that monitoring it is a very good idea anyway (i.e. periodically do a request, send an email or something if it fails). Busy sites can potentially rely on getting complaints very quickly so arguably monitoring is less important - in my opinion, however, it's always nice to see that a problem you're having has already been detected and a fix is in progress, and automated monitoring is the best way to achieve that.

We use pingdom, I'm sure there are others, but that would achieve the objective you're after...

I do use Pingdom as well, and if this can keep the web app warm, then it's not an issue.

Although, it would be good if paying customers need not do this. Looking forward to the solution.

I'm still having this issue - running flask w/ python 2.7

I do use a few extra libraries, but the slowdown doesn't seem to be dependent on those (based on removing/adding functionality/libraries)

Can anyone confirm if static pages also suffer from this delay? I'm thinking to minimize my use of templates to avoid this issue, at least on the front page.

Also, what would be a safe interval for a prewarmer? Is there any way to schedule a task on server reboot / swapping? Is the bytecode being recompiled on server swap/reboot?

Slowdowns can be caused by many things. There is not enough information in your post to work out what may be causing it. Send us feedback and we'll try to work out what you can do.

I'm having this exact issue as well - I tried to resolve it over email but unfortunately haven't gotten anywhere so I found this old thread.

My Flask app occasionally takes an extra 3-5 seconds to load after a number of idle hours, after which point it's fine. This happens once every 1-2 days, and always coincides with the following printout in the server log:

2022-04-21 16:04:58 *** Starting uWSGI 2.0.19.1 (64bit) on [Thu Apr 21 16:04:57 2022] ***

The response I got from support was the following: "When we move web apps between machines (we do it once in a day or two) first hit triggers spinup."

I understand, but from the user's perspective waiting 3-5 seconds for the website to "spin up" creates a bad experience for them and therefore reflects poorly on me as the creator. I purposely uploaded a toy Flask app and stripped away anything that could possibily cause slow loading times on my end, and unfortunately this problem still persists.

Some additional info: I'm currently on a paid account with 2 workers per app and I'm the only one accessing this toy app, so this shouldn't be an issue. Also, the app's JS files are tiny (~8KB total) and the CSS file is ~50KB, so this shouldn't be an issue either (the files are kept in the 'static' directory anyways).

Please let me know if there's a solution for this - maybe scheduling a task to ping the app every hour to make sure it stays "warm", as Harry suggested above? (Though this still wouldn't solve the problem fully since there's a chance a user could access the app at an inopportune moment such that their "first hit triggers spinup" of the app and they experience the lag.)

Thanks!

Since it's a shared infrastructure, the web servers need to be rebooted from time to time, for maintenance reasons. The only solution to prevent the side effects of the reboot (when the web app needs to spin up) is to use a private server, where only your web app would run. That would probably drastically decrease the frequency of the maintenance reboots. If you're interested in switching over to a private server, let us know via the emial, and we'll provide you with the offer.