Skip to content
Extraits de code Groupes Projets
Valider 4cedb1e8 rédigé par Fil's avatar Fil
Parcourir les fichiers

revision de cron() de maniere a indexer plus vite sans jamais se marcher sur...

revision de cron() de maniere a indexer plus vite sans jamais se marcher sur les pieds quand il ya beaucoup de hits (et code un peu plus simple)
parent 0ce109aa
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -61,12 +61,6 @@ function spip_cron($taches = array()) { ...@@ -61,12 +61,6 @@ function spip_cron($taches = array()) {
AND ($t - @filemtime(_FILE_MYSQL_OUT) < 300)) AND ($t - @filemtime(_FILE_MYSQL_OUT) < 300))
return; return;
include(_FILE_CONNECT);
if (!$GLOBALS['db_ok']) {
spip_log('pas de connexion DB pour taches de fond (cron)');
return;
}
if (!$taches) if (!$taches)
$taches = taches_generales(); $taches = taches_generales();
...@@ -86,14 +80,24 @@ function spip_cron($taches = array()) { ...@@ -86,14 +80,24 @@ function spip_cron($taches = array()) {
} }
if (!$tache) return; if (!$tache) return;
// Connexion DB
include(_FILE_CONNECT);
if (!$GLOBALS['db_ok']) {
spip_log('pas de connexion DB pour taches de fond (cron)');
return;
}
// Interdire des taches paralleles, de maniere a eviter toute concurrence
// entre deux SPIP partageant la meme base, ainsi que toute interaction
// bizarre entre des taches differentes
if (!spip_get_lock('cron')) {
spip_lock("tache $tache: pas de lock cron");
return;
}
// On opere un double lock : un dans _DIR_SESSIONS, pour les hits // Un autre lock dans _DIR_SESSIONS, pour plus de securite
// (en parallele sur le meme site) ; et un autre dans la base de
// donnees, de maniere a eviter toute concurrence entre deux SPIP
// differents partageant la meme base (replication de serveurs Web)
$lock = _DIR_SESSIONS . $tache . '.lock'; $lock = _DIR_SESSIONS . $tache . '.lock';
if (spip_touch($lock, $taches[$tache]) if (spip_touch($lock, $taches[$tache])) {
AND spip_get_lock('cron'.$tache)) {
// preparer la tache // preparer la tache
spip_timer('tache'); spip_timer('tache');
...@@ -109,10 +113,10 @@ function spip_cron($taches = array()) { ...@@ -109,10 +113,10 @@ function spip_cron($taches = array()) {
// eventuellement modifier la date du fichier // eventuellement modifier la date du fichier
if ($code_de_retour < 0) @touch($lock, (0 - $code_de_retour)); if ($code_de_retour < 0) @touch($lock, (0 - $code_de_retour));
} }
// relacher le lock mysql
spip_release_lock('cron'.$tache);
} }
// relacher le lock mysql
spip_release_lock('cron');
} }
// //
...@@ -152,7 +156,7 @@ function taches_generales() { ...@@ -152,7 +156,7 @@ function taches_generales() {
// indexation // indexation
if (lire_meta("activer_moteur") == "oui") if (lire_meta("activer_moteur") == "oui")
$taches_generales['index'] = 60; $taches_generales['index'] = 90;
// ajax // ajax
$taches_generales['ajax'] = 3600 * 2; $taches_generales['ajax'] = 3600 * 2;
...@@ -174,7 +178,14 @@ function cron_optimiser($t) { ...@@ -174,7 +178,14 @@ function cron_optimiser($t) {
} }
function cron_index($t) { function cron_index($t) {
return count(effectuer_une_indexation()); $c = count(effectuer_une_indexation());
// si des indexations ont ete effectuees, on passe la periode a 0 s
## note : (time() - 90) correspond en fait a :
## time() - $taches_generales['index']
if ($c)
return (0 - (time() - 90));
else
return 0;
} }
function cron_sites($t) { function cron_sites($t) {
......
...@@ -983,18 +983,15 @@ function spip_touch($fichier, $duree=0, $touch=true) { ...@@ -983,18 +983,15 @@ function spip_touch($fichier, $duree=0, $touch=true) {
// quand il est appele par inc-public il n'est pas gourmand // quand il est appele par inc-public il n'est pas gourmand
// //
function cron($gourmand = false) { function cron($gourmand = false) {
$touch = _DIR_SESSIONS.'background';
$touch_gourmand = $touch.'-gourmand';
// Si on est gourmand, ou si le fichier gourmand n'existe pas // Si on est gourmand, ou si le fichier gourmand n'existe pas
// (ou est trop vieux), on va voir si un cron est necessaire. // (ou est trop vieux -> 60 sec), on va voir si un cron est necessaire.
// Au passage si on est gourmand on le dit aux autres // Au passage si on est gourmand on le dit aux autres
if (spip_touch($touch_gourmand, 60, $gourmand) if (spip_touch(_FILE_CRON_LOCK.'-gourmand', 60, $gourmand)
OR $gourmand) { OR $gourmand) {
// Faut-il travailler ? Pas tous en meme temps svp // Faut-il travailler ? Pas tous en meme temps svp
// Au passage si on travaille on bloque les autres // Au passage si on travaille on bloque les autres
if (spip_touch($touch, 1)) { if (spip_touch(_FILE_CRON_LOCK, 1)) {
include_ecrire('inc_cron.php3'); include_ecrire('inc_cron.php3');
spip_cron(); spip_cron();
} }
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter