/tools/cachebench.php

https://github.com/glpi-project/glpi · PHP · 173 lines · 75 code · 11 blank · 87 comment · 15 complexity · 240f95ec0277ec12586f7622a2fc736e MD5 · raw file

  1. <?php
  2. /**
  3. * ---------------------------------------------------------------------
  4. * GLPI - Gestionnaire Libre de Parc Informatique
  5. * Copyright (C) 2015-2020 Teclib' and contributors.
  6. *
  7. * http://glpi-project.org
  8. *
  9. * based on GLPI - Gestionnaire Libre de Parc Informatique
  10. * Copyright (C) 2003-2014 by the INDEPNET Development Team.
  11. *
  12. * ---------------------------------------------------------------------
  13. *
  14. * LICENSE
  15. *
  16. * This file is part of GLPI.
  17. *
  18. * GLPI is free software; you can redistribute it and/or modify
  19. * it under the terms of the GNU General Public License as published by
  20. * the Free Software Foundation; either version 2 of the License, or
  21. * (at your option) any later version.
  22. *
  23. * GLPI is distributed in the hope that it will be useful,
  24. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  26. * GNU General Public License for more details.
  27. *
  28. * You should have received a copy of the GNU General Public License
  29. * along with GLPI. If not, see <http://www.gnu.org/licenses/>.
  30. * ---------------------------------------------------------------------
  31. */
  32. if (PHP_SAPI != 'cli') {
  33. echo "This script must be run from command line";
  34. exit();
  35. }
  36. define('PER_LEVEL', 8);
  37. define('COUNT', 1024);
  38. require __DIR__ . '/../inc/includes.php';
  39. // To bypass various right checks
  40. $_SESSION['glpishowallentities'] = 1;
  41. $_SESSION['glpicronuserrunning'] = "cron_phpunit";
  42. $_SESSION['glpi_use_mode'] = Session::NORMAL_MODE;
  43. $_SESSION['glpiactiveentities'] = [0];
  44. $_SESSION['glpiactiveentities_string'] = "'0'";
  45. $CFG_GLPI['root_doc'] = '/glpi';
  46. $ent = new Entity();
  47. $nb = countElementsInTable('glpi_entities');
  48. if ($nb < 100000) {
  49. echo "+ Generate some entities\n";
  50. for ($a = 0; $a < PER_LEVEL; $a++) {
  51. $ida = $ent->add(['entities_id' => 0, 'name' => "ent $a"]);
  52. echo "$ida\r";
  53. for ($b = 0; $b < PER_LEVEL; $b++) {
  54. $idb = $ent->add(['entities_id' => $ida, 'name' => "s-ent $b"]);
  55. echo "$idb\r";
  56. for ($c = 0; $c < PER_LEVEL; $c++) {
  57. $idc = $ent->add(['entities_id' => $idb, 'name' => "ss-ent $c"]);
  58. //echo "$idc\r";
  59. for ($d = 0; $d < PER_LEVEL; $d++) {
  60. $idd = $ent->add(['entities_id' => $idc, 'name' => "sss-ent $d"]);
  61. //echo "$idd\r";
  62. for ($e = 0; $e < PER_LEVEL; $e++) {
  63. $ide = $ent->add(['entities_id' => $idd, 'name' => "sss-ent $e"]);
  64. //echo "$ide\r";
  65. for ($f = 0; $f < PER_LEVEL; $f++) {
  66. $idf = $ent->add(['entities_id' => $ide, 'name' => "sss-ent $f"]);
  67. //echo "$idf\r";
  68. }
  69. }
  70. }
  71. }
  72. }
  73. }
  74. //echo "Regenerate tree\n";
  75. //regenerateTreeCompleteName('glpi_entities');
  76. $nb = countElementsInTable('glpi_entities');
  77. }
  78. echo "+ Entities: $nb\n";
  79. if ($GLPI_CACHE) {
  80. echo "+ Cache: " . get_class($GLPI_CACHE) . "\n";
  81. } else {
  82. echo "+ Cache: disabled\n";
  83. }
  84. echo "+ Clear sons cache\n";
  85. $DB->update(
  86. 'glpi_entities',
  87. ['sons_cache' => null],
  88. [true]
  89. );
  90. $tps = microtime(true);
  91. echo "+ Run with empty cache\n";
  92. for ($i=0; $i<COUNT; $i++) {
  93. if (($i & 0x7f)==0) {
  94. echo "$i\r";
  95. }
  96. $t[$i] = $id = mt_rand(0, $nb);
  97. //$x = getSonsOf('glpi_entities', $id);
  98. $x = getAncestorsOf('glpi_entities', $id);
  99. }
  100. $tps = microtime(true) - $tps;
  101. printf("> time: %.4f\n", $tps);
  102. $tps = microtime(true);
  103. echo "+ Run with populated cache\n";
  104. for ($i=0; $i<COUNT; $i++) {
  105. if (($i & 0x7f)==0) {
  106. echo "$i\r";
  107. }
  108. $id = $t[$i];
  109. //$x = getSonsOf('glpi_entities', $id);
  110. $x = getAncestorsOf('glpi_entities', $id);
  111. }
  112. $tps = microtime(true) - $tps;
  113. printf("> time: %.4f\n", $tps);
  114. echo "+ Done\n";
  115. /*
  116. + Entities: 299598
  117. + Cache: disabled
  118. + Clear sons cache
  119. + Run with empty cache
  120. > time: 2.7468
  121. + Run with populated cache
  122. > time: 2.4121
  123. + Done
  124. + Entities: 299598
  125. + Cache: Laminas\Cache\Storage\Adapter\Apcu
  126. + Clear sons cache
  127. + Run with empty cache
  128. > time: 2.8290
  129. + Run with populated cache
  130. > time: 0.0335
  131. + Done
  132. + Entities: 299598
  133. + Cache: Laminas\Cache\Storage\Adapter\Memcache
  134. + Clear sons cache
  135. + Run with empty cache
  136. > time: 3.0366
  137. + Run with populated cache
  138. > time: 0.1195
  139. + Done
  140. + Entities: 299598
  141. + Cache: Laminas\Cache\Storage\Adapter\Redis
  142. + Clear sons cache
  143. + Run with empty cache
  144. > time: 2.9524
  145. + Run with populated cache
  146. > time: 0.1247
  147. + Done
  148. + Entities: 299593
  149. + Cache: Laminas\Cache\Storage\Adapter\WinCache
  150. + Clear sons cache
  151. + Run with empty cache
  152. > time: 5.1352
  153. + Run with populated cache
  154. > time: 0.1560
  155. + Done
  156. */