newttster Posted August 19, 2011 Share Posted August 19, 2011 I have been reading up on how some people have been using timestamps to replace cron jobs ... http://makewebgames.io/showthread.php/33392-Another-5-minute-cron-removal?highlight=minute http://makewebgames.io/showthread.php/32642-any-version-Removal-of-1-minute-crons/page9?highlight=minute http://makewebgames.io/showthread.php/32949-Crons-Timestamp-or-none?highlight=crons%2C+timestamp http://makewebgames.io/showthread.php/31481-Crons-VS.-Time-Stamp/page2?highlight=crons%2C+timestamp Those are just a few examples ... but I have not been able to find anything where it is stated emphatically which works best with which cron more importantly ... which offers the least amount of lag for your players. Any input on this would be appreciated. Thanks. Quote Link to comment Share on other sites More sharing options...
Spudinski Posted August 19, 2011 Share Posted August 19, 2011 I'd suggest you use something with more documentation. Try "PHP Cron", found at: http://www.phpclasses.org/package/2392-PHP-Parse-cron-schedules-to-find-when-cron-job-ran.html Quote Link to comment Share on other sites More sharing options...
Lithium Posted August 19, 2011 Share Posted August 19, 2011 Trial and error mostly. You need to test every single option or even a mix on those to see which one has the best performance, as load is influenced by server environment itself... one practical good solution on a scenario is not necessary the best to all. Quote Link to comment Share on other sites More sharing options...
SacreBleu Posted August 19, 2011 Share Posted August 19, 2011 Depending on what operating system you work with, it is in my experience that the built-in cron in Linux works best, as it has the least overhead and is easiest to configurate. For Windows the best way to offer cronjobs is by utilising the task scheduler, it has done wonders for me and offers very little cpu utilisation and was always spot on. Luckily the engine I am currently using, albeit not a mafia game, has all these features built-in from the get go. Quote Link to comment Share on other sites More sharing options...
Anonymous Posted August 19, 2011 Share Posted August 19, 2011 Assuming a dedicated low-traffic box, then perhaps the prior poster is correct; however even with 500 odd actives it can be shown that these crons will exhibit visible lag from the users point of view. There is of course some question as to whether this is in part due to poorly optimized SQL however that's best left for a different topic. On shared boxes, where you have no control over what jobs other users may be running, adding to the load is not going to help in you or anybody else; it can only make it worse. I've noticed quite a few shared hosting companies using hard limits on the minimum period between crons to reduce peak loads; I can only assume they offset each user by a small amount to counteract the obvious problems with this. Using MySQL events is an interesting solution, but non-portable, difficult to maintain, and as far as I am aware, useless on replicated/clustered back-ends not to mention cloud based storage solutions. As a number of hosting organizations now use transparent data backup mechanisms; this could easily cause a range of problems that are not even visible until you come to perform a restore. This also suffers from the same problem as basic crons - in that many users sharing a box will put excessive load on the system each "tick". There are better solutions; one being using timestamps rather than countdown fields and only "regenerating" records only when they actually need it. This particular method is popular across larger products and is really not that difficult to implement on the MCCodes codebase. At the bare minimum, adding a "last_regenerated" field (for example) to your users table, you can dispose of the minute and five minute crons almost instantly. With a little extra work, most of the day-cron vanishes as well, followed with a little more work by the hour cron. Quote Link to comment Share on other sites More sharing options...
SacreBleu Posted August 19, 2011 Share Posted August 19, 2011 Eventually, every system will start to show lag, no matter how the application is being done. From what I've seen in most situations, many people use many different files for one command, merging documents and applying appropiate formatting would lessen the overall stress of the server, because only one file needs to be 'cronned' instead of twenty. As the above poster mentions, optimising the code to only run when it needs to be updated is best practise, the question here is, is there already apparent lag on your server, have users complained about visual lag and is this caused by the amount of cronjobs or inaccurate/incorrect cron settings and timetables? Quote Link to comment Share on other sites More sharing options...
newttster Posted August 20, 2011 Author Share Posted August 20, 2011 Thanks everyone. Really appreciate your input on this. @SacreBleu ... I am not having any issues as of yet because I don't have a site running yet ... I just want to configure my game well in advance to try and avoid lag issues that occur from "crons". Basically I want to cure it before it starts. Too often you see numerous complaints in game forums about lag issues. Seems to me that this could obviously be a game killer. @Anonymous ... would it be possible for you to discuss the "last_generated" field option with me via messages? This sounds very interesting. Would this be something like adding a where clause stating only to do said action if user has only been active? Quote Link to comment Share on other sites More sharing options...
Anonymous Posted August 20, 2011 Share Posted August 20, 2011 @newttster - Optimizing away cron jobs should be sufficient to explain the use of this type of technique. Quote Link to comment Share on other sites More sharing options...
newttster Posted August 20, 2011 Author Share Posted August 20, 2011 Thank you so much for your input and the link, Anonymous. This will be a huge help to me. Obviously I will have to play with it ... alot ... until I understand it fully. I am sure that there are others looking for this kind of "upgrade" to crons. Again, thanks ever so much. Quote Link to comment Share on other sites More sharing options...
runthis Posted August 20, 2011 Share Posted August 20, 2011 (edited) Something like this would not use crons, just php and would account for when the user is offline, although to other users viewing their stats, it wouldn't change until they came online. 5 minute cron $time=time(); $next_update=($_SESSION['lastran'] + 300); if($next_update <= $time){ $math=($time - $next_update); $amountToUpdate=($math / 300); $amountToUpdate=number_format($amountToUpdate,0); if($amountToUpdate < 1){ $amountToUpdate=1; } if($amountToUpdate > 10){ $amountToUpdate=10; } while($amountToUpdate > 0){ mysql_query("UPDATE THIS USERS STATS"); } $_SESSION['lastran']=time(); $amountToUpdate=($amountToUpdate-1); }else{ ## nada } Or you can use the cron files you already have without running crons by adding something like this to your one minute cron file, that way not every user it checking to see if they have to update like above, instead the cronbot that runs every minute for your hospital and jail will also be your five minute one too, which lets you eliminate the need for the 5min cron 5 minute cron $time=time(); $next_update=($_SESSION['lastran'] + 300); if($next_update <= $time){ $math=($time - $next_update); $amountToUpdate=($math / 300); $amountToUpdate=($amountToUpdate,0); if($amountToUpdate < 1){ $amountToUpdate=1; } if($amountToUpdate > 10){ $amountToUpdate=10; } while($amountToUpdate > 0){ $ch = curl_init("path/to/your/fiveminutecron.php"); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $output = curl_exec($ch); curl_close($ch); } $_SESSION['lastran']=time(); $amountToUpdate=($amountToUpdate-1); }else{ ## nada } Another way to do that one above would be $_SESSION['updated']+=1; if($_SESSION['updated'] > 4) { $_SESSION['updated']=0; $ch = curl_init("path/to/your/fiveminutecron.php"); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $output = curl_exec($ch); curl_close($ch); } Of course that's all untested, just typed into the forum but you get the idea. Edited August 20, 2011 by runthis Quote Link to comment Share on other sites More sharing options...
chavdave Posted May 20, 2012 Share Posted May 20, 2012 how do i set crons on windows my host sent me this command do i need to add anything to make it work php -f /home/crimmewa/public_html/Crons/cron_fivemins.php php -f /home/crimmewa/public_html/Crons/cron_minute.php php -f /home/crimmewa/public_html/Crons/cron_hour.php php -f /home/crimmewa/public_html/Crons/cron_day.php Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.