Jump to content
MakeWebGames

"Cronless crons"


gamble

"Cronless crons"  

1 member has voted

  1. 1. "Cronless crons"

    • Yes
      7
    • No
      6
    • Maybe
      6


Recommended Posts

Just a quick questions for you guys:

Would you use cronless crons in your game if they were available?

Meaning the crons dont use the usual cpanel cron job functions but a file that is called when users are active to credit them that way. I believe a user on the forums released a MCC version.

Sorry about the god awful explanation haha.

Cronless cron by MTG:

http://magictallguy.tk/mods.php?mod=20

Edited by gamble
Link to comment
Share on other sites

You mean;

"Would you remove crons and work from timestamps?"

Quite easy to just work from timestamps, as long as you write it correctly and think thoroughly about where to activate updates.

Can be a long task to completely remove them though.

Replacing a cron with a cron, however, doesn't make much sense, since you would have to run more resources to check if it's due to run on all active players.

That's an extra query, per player, every page load, to check the files.

May as well just let the system run it once on command.

Link to comment
Share on other sites

I vote Yes.

When I develop a module I try and steer away from using crone and use timestamps. I feel it's just better to perform transactions incrementally and doing only what needs to be done instead of for example when 00:00:00 hits I run 1 min cron, 5 min cron, 1 hour cron, and 1 day cron.

I think crons from the cron tab should be used mainly for large transaction like generating reports, backups, etc

Link to comment
Share on other sites

No, sure timestamps for some things, however I have around 40 crons running various automated tasks to manage the game so :).

With MCCodes I would still use crons :)

Link to comment
Share on other sites

Dependent on the tasks the cron is required to do.

Things like stat updating and such, sure.

[get last run info] -> [calculate how many times it should have run between now and then] -> [alter values dependent on the value of the calculation] -> updates -> set new last run info.

Things that explicitly need to run a set time, no.

*Haven't tested "cron-less crons" *facepalm* in a live environment, so unable to comment in that respect.

Edited by Djkanna
Link to comment
Share on other sites

Certainly not.

The author of said cronless crons really missed the point, and failed to address several issues relating to how periodic events are triggered. Consider writing more sane code, that does not rely on periodics, it's not difficult.

Link to comment
Share on other sites

Certainly not.

The author of said cronless crons really missed the point, and failed to address several issues relating to how periodic events are triggered. Consider writing more sane code, that does not rely on periodics, it's not difficult.

I am by no means talking MTG's cronless crons...i talking the general idea of them.

Link to comment
Share on other sites

Should be rephrased, timestamps vs cronjobs....

timestamps are good for things like education mods, or mods that have a waiting period;jail,hospital,ban, but for bars and things that update more frequently for ALL players at once should use cronjobs for them... This is only my opinion though.

Link to comment
Share on other sites

Should be rephrased, timestamps vs cronjobs....

timestamps are good for things like education mods, or mods that have a waiting period;jail,hospital,ban, but for bars and things that update more frequently for ALL players at once should use cronjobs for them... This is only my opinion though.

I kind of like the term. It's growing on me.

It's like;

A chicken free, chicken and mushroom pie.

A non-chocolate, chocolate teapot.

Or even a sugar free, sugar cube.

Oxymorons, indeed.

Link to comment
Share on other sites

I use timestamps to run 1 and 5 minute stuff. I use Crons to run hour and day stuff. I could switch solely over to timestamps but really I don't want to.

Why do you use them for the smaller intervals and not for the bigger ones?

Why dont you want to switch completely?

Link to comment
Share on other sites

I started using time stamps because the server I was on didn't accept cron jobs for 1 and 5 minute. I never switched after because it wasn't an issue. Still isn't. I like the cron for the hour and day because unless the server goes down or something like that I know they'll run. And if they don't then I'll get an email telling me and I can manually run it.

Link to comment
Share on other sites

@Guest

... or well-written, high-quality, fast, stable PHP code? :D

@gamble,

My apologies, conceptually doing away with crons is a good thing as they put undue strain on the server often at highly inconvenient times (anybody remember Torn's daily downtime @ new day? - insane). There are a few commercial applications out there; WoltLab's Burning Board IIRC for one; that runs "crons" from PHP doing away with system-level crons, but I'm far more in favor of a solution based on timestamps triggered only when needed.

Crons for system level tasks are usually fine, though care must be taken not to run too much at one time (often midnight).

Link to comment
Share on other sites

@Guest

... or well-written, high-quality, fast, stable PHP code? :D

@gamble,

My apologies, conceptually doing away with crons is a good thing as they put undue strain on the server often at highly inconvenient times (anybody remember Torn's daily downtime @ new day? - insane). There are a few commercial applications out there; WoltLab's Burning Board IIRC for one; that runs "crons" from PHP doing away with system-level crons, but I'm far more in favor of a solution based on timestamps triggered only when needed.

Crons for system level tasks are usually fine, though care must be taken not to run too much at one time (often midnight).

Thanks for the post!

I would be interested in looking into a "complex" timestamp sort of cron system. I found MTG's quite interesting and am thinking about adding something similar into my current project. This may sound childish or "noobish" but i never really thought about a timestamp approach until i saw MTG's MCC mod.

Link to comment
Share on other sites

Naturally, I use MySQL Events. Unfortunately, not every host allows you to do this by default. Enabling the event scheduler can be quite the arse if your host doesn't like it. However, as I host my own sites, I don't need to worry about that and will continue to use MySQL Events until something better is written to replace them

Link to comment
Share on other sites

  • 2 weeks later...

Why does this need to be done using a cronjob anyway?

In your user model just create a method called update_data or something, add a datetime field for your last data update and do something like this (not actual code) for a 5 min update for example:

$date_difference = now - last_update;

$diff_in_mins = $date_difference.to_seconds;

$updates = floor($diff_in_mins/5);

 

if($updates > 1):
   $energy_increase = $user->is_donator ? 10 : 5;
   // update the stuff here
   $this->energy = ($updates * $energy_increase) + $this->energy > $this->energy_max ? $this->energy_max : ($updates * $energy_increase) + $this->energy > $this->energy_max;
   // update the last updated field
   $this->update = correct_last_update
endif;
Link to comment
Share on other sites

Why does this need to be done using a cronjob anyway?

In your user model just create a method called update_data or something, add a datetime field for your last data update and do something like this (not actual code) for a 5 min update for example:

$date_difference = now - last_update;

$diff_in_mins = $date_difference.to_seconds;

$updates = floor($diff_in_mins/5);

 

if($updates > 1):
   $energy_increase = $user->is_donator ? 10 : 5;
   // update the stuff here
   $this->energy = ($updates * $energy_increase) + $this->energy > $this->energy_max ? $this->energy_max : ($updates * $energy_increase) + $this->energy > $this->energy_max;
   // update the last updated field
   $this->update = correct_last_update
endif;

Because this will just update that 1 player, unless the SQL query (which you haven't provided) updates all players.

A cron would be a good way to go, because on every page click we're not adding another query to perform. (35 active players * 5 clicks every 20 seconds = 2,100 added queries a minute.)

Link to comment
Share on other sites

Because this will just update that 1 player, unless the SQL query (which you haven't provided) updates all players.

A cron would be a good way to go, because on every page click we're not adding another query to perform. (35 active players * 5 clicks every 20 seconds = 2,100 added queries a minute.)

If you had a very large number of players and incremented them every X minutes you'd experience some server problems.

What if you only updated that user only where it is required. Think about the instances where the info for that user needs to be changed, it certainly isn't every 5 or so minutes;

- When you are attacking the user update them (hp needs to update maybe)

- When you are active so every page load

- Any other user interaction, maybe something like for an organised crime?

Link to comment
Share on other sites

If you had a very large number of players and incremented them every X minutes you'd experience some server problems.

What if you only updated that user only where it is required. Think about the instances where the info for that user needs to be changed, it certainly isn't every 5 or so minutes;

- When you are attacking the user update them (hp needs to update maybe)

- When you are active so every page load

- Any other user interaction, maybe something like for an organised crime?

... and you'd store the last time the "cronless cron" ran in the database, right?

I think we may be talking about different things?

Edited by sniko
Link to comment
Share on other sites

... and you'd store the last time the "cronless cron" ran in the database, right?

I think we may be talking about different things?

Yea I think so, from what I saw the cronless cron idea just updates the entire db when someone loads up a page. I was saying you only need to update what is relevant which would cut the server load down massively

Link to comment
Share on other sites

Yea I think so, from what I saw the cronless cron idea just updates the entire db when someone loads up a page. I was saying you only need to update what is relevant which would cut the server load down massively

Ah, we are talking about different things - kind of.

The idea of cronless crons - in this instance - was to update all player and other related stuff typically every minute, five minutes, every hour, every day, IIRC.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...