backdrop / backdrop-issues

Issue tracker for Backdrop core.
145 stars 40 forks source link

Adding more jobs in the cron run while its running (cron task queue with priority/weight)? #1636

Closed klonos closed 6 years ago

klonos commented 8 years ago

The idea of shortening the default cron run time to something like 10mins was mentioned in https://github.com/backdrop/backdrop-issues/issues/857#issuecomment-186698291. We do have cron running in the background now (#1214), but what happens when for example there are lots of cron jobs to be run that will take long time? Say these jobs are of minor significance (maintenance tasks like cache clearing or removing stale things etc.) compared to time-critical things like say having a node published in a specific point in time? How do we handle this? Could we give precedence to specific types of cron jobs/tasks?

klonos commented 8 years ago

So, I was thinking that perhaps we should introduce some sort of cron task "weight":

Doable? Thoughts?

klonos commented 8 years ago

...

  • If there are many tasks with weight 0, then these are sorted say by date/time added.

Well, in the case of cron tasks for publishing nodes, perhaps instead of executing by order of time the task was added, perhaps we should be smarter and execute by time node is set to be published.

I think if all these features are implemented in cron, we should rename it to something "catchy" and market it as something special (it is!):

In Backdrop, the default cron shipped with Drupal was replaced by the next-gen Smart Cron that features background tasks so that webpages are served to visitors without interruption as well as tasks prioritization so that critical tasks are run on schedule.

quicksketch commented 8 years ago

Answering a couple of questions here:

Right now the way most modules implement cron they work on an assumption that they will not take longer than a few seconds to execute their particular task, and if other modules run their periodic tasks at the same time, they also won't take more than a few seconds. If a module does have a very long running task, then they use the Queue API to queue the tasks so that they can be run a the "next available cron cycle", because other tasks already might be queued before them that would need to be run first.

Overall, I think we already have most of the bases covered for what's requested here. Though a bad-behaving module might still use hook_cron() when a queue is more appropriate.

klonos commented 8 years ago

Thanx for taking the time to explain @quicksketch

I know, you'll hate me for the noise, but here's another though: if the default cron time is indeed shortened to 10mins or less, why not actually have it be running constantly (triggered at every page load/refresh) instead?

The reason why we had configurable time for cron AFAIK was in order to mitigate things like slow page loads. Well, we have no such issues in Backdrop anymore, since cron now runs in the background. So, why not run it all the time and see if there are pending tasks to be executed (useful for accuracy in #857)?

If we implement this, we can also lose the entire Cron config page (and the menu item from the admin bar) because:

We can also remove the entry from the site status report for UI simplification:

Again thoughts?

ghost commented 8 years ago

Again, I strongly disagree : all this annoying "automatic cron" stuff is here for sites which cannot (or do not want) use the host cron feature - this is badly named "from outside the site", but this is the only clean way to go. I'd like to remove all this stuff from core, and provide a contrib module ("Elysia Cron", do you remember...) for old low cost shared sites

klonos commented 8 years ago

... all this annoying "automatic cron" stuff is here for sites which cannot (or do not want) use the host cron feature... I'd like to remove all this stuff from core, and provide a contrib module ("Elysia Cron", do you remember...) for old low cost shared sites

Yes, but you are missing the point here (Backdrop CMS Philosophy):

Audience

Backdrop CMS is for the small to medium sized business, non-profits, educational institutions, and companies or organizations who are delivering comprehensive websites on a budget. ...

  1. Meet Low System Requirements. Backdrop must be able to run on affordable hosting with very basic requirements....

(emphasis mine)

ghost commented 8 years ago

@klonos : no, I'm not missing the point : In my expression "old low cost shared sites", the key word is old : here in France, as of today, I can get a high quality "affordable hosting with very basic requirements" for less than 2€ / month (US$ 2¼), which includes CRON tasks, and free phone support if you have trouble setting it up…

quicksketch commented 8 years ago

Well, we have no such issues in Backdrop anymore, since cron now runs in the background. So, why not run it all the time and see if there are pending tasks to be executed (useful for accuracy in #857)?

I don't think there would be too much harm in this. As I noted above, your site is limited to a single cron execution running at any given time anyway. However, this may cause poorly written hook_cron() implementations to have exaggerated side-effects. Some cron jobs may delete all their caches, or rebuild an expensive operation, expecting that cron may be run no more often than every 5-10 minutes. Those are poor assumptions to be sure, but a bad hook_cron() implementation could start severely affecting the site by constantly flushing/rebuilding something that is supposed to be a long-term cache.

Overall, I think this may be a bit risky, but possibly not out of the question. For starters simply lowering the default interval to a shorter time (1-5 minutes) may be a good experiment.

Again, I strongly disagree : all this annoying "automatic cron" stuff is here for sites which cannot (or do not want) use the host cron feature - this is badly named "from outside the site", but this is the only clean way to go.

The ability to use a standard cron setup or to use a task-runner like Jenkins is completely valid. I think you're right that we definitely shouldn't remove the ability to disable the built-in cron. With our target audience however, I think that we should expect the built-in cron to be most-common, with explicitly set cron jobs or task runners as a common but not required configuration.

quicksketch commented 6 years ago

I'm not sure if any items are needed to be completed here. Even with things like file deletions, node scheduling, log cleanup, etc, we don't have any reports of cron failing at its jobs. For complicated task running, we should port Elysia/Ultimate Cron for Backdrop and leave it to contrib.

If there is an actionable item here, please reopen. Or let's use a new issue with a targeted objective.