modxSmarty - отключение modx-парсера и существенное ускорение
возникла идея — отключить modx-парсер вообще на тех страницах где он не нужен. и использовать исключительно возможности smarty. попутно появилась возможность работать с дебаггером smarty. я недавно вникаю в разработку на modx, поэтому мое решение наверняка крайне кривое — просьба просто его рассмотреть, и наставить на путь истиный. может кто-то сможет сделать более правильно и добавить в следующую версию пакета. по результатам экспериментов рендеринг страниц без modx-парсера ускоряется очень существенно. вот некоторые результаты: обычный вывод через modx-парсер: mbpv:~ info$ ab -n 100 -c 4 www.na.ru/tyres/manufacturers/Nokian/Hakka_Z/ This is ApacheBench, Version 2.3 <$Revision: 655654 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, www.zeustech.net/ Licensed to The Apache Software Foundation, www.apache.org/ Benchmarking www.na.ru (be patient).....done Server Software: Apache/2.2.23 Server Hostname: www.na.ru Server Port: 80 Document Path: /tyres/manufacturers/Nokian/Hakka_Z/ Document Length: 17622 bytes Concurrency Level: 4 Time taken for tests: 33.511 seconds Complete requests: 100 Failed requests: 0 Write errors: 0 Total transferred: 1809300 bytes HTML transferred: 1762200 bytes Requests per second: 2.98 [#/sec] (mean) Time per request: 1340.421 [ms] (mean) Time per request: 335.105 [ms] (mean, across all concurrent requests) Transfer rate: 52.73 [Kbytes/sec] received Connection Times (ms) min mean[±sd] median max Connect: 0 0 1.0 0 10 Processing: 293 1338 354.8 1430 1902 Waiting: 284 1303 348.9 1390 1870 Total: 293 1338 355.0 1431 1902 Percentage of the requests served within a certain time (ms) 50% 1431 66% 1493 75% 1529 80% 1549 90% 1680 95% 1762 98% 1900 99% 1902 100% 1902 (longest request) вывод с отключенным modx-парсером (при это НЕ кешируются ресурсы и шаблоны!): mbpv:~ info$ ab -n 100 -c 4 www.na.ru/tyres/manufacturers/Nokian/Hakka_Z/ This is ApacheBench, Version 2.3 <$Revision: 655654 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, www.zeustech.net/ Licensed to The Apache Software Foundation, www.apache.org/ Benchmarking www.na.ru (be patient).....done Server Software: Apache/2.2.23 Server Hostname: www.na.ru Server Port: 80 Document Path: /tyres/manufacturers/Nokian/Hakka_Z/ Document Length: 14050 bytes Concurrency Level: 4 Time taken for tests: 5.860 seconds Complete requests: 100 Failed requests: 0 Write errors: 0 Total transferred: 1452100 bytes HTML transferred: 1405000 bytes Requests per second: 17.07 [#/sec] (mean) Time per request: 234.394 [ms] (mean) Time per request: 58.599 [ms] (mean, across all concurrent requests) Transfer rate: 242.00 [Kbytes/sec] received Connection Times (ms) min mean[±sd] median max Connect: 0 0 0.1 0 1 Processing: 81 232 80.1 238 376 Waiting: 73 214 74.7 220 349 Total: 81 233 80.2 239 377 Percentage of the requests served within a certain time (ms) 50% 239 66% 279 75% 307 80% 313 90% 336 95% 353 98% 361 99% 377 100% 377 (longest request) mbpv:~ info$ если включить кеширование шаблона — еще ускорится. в общем — очень быстро работает :) как это сделано Шаблон base.php: <?php
$properties = $modx->resource->getOne('Template')->getProperties();
if(!empty($properties['tpl'])){ $tpl = $properties['tpl']; } else{ $tpl = 'index.tpl'; }
/* // управление кешем через галочку "кешируемый" у каждого ресурса // при этом будет работать modx=парсер каждый раз if ($modx->resource->cacheable != '1') { $modx->smarty->caching = false; } return $modx->smarty->fetch("tpl/{$tpl}"); */
// управление кешем через установку переменной caching = true; прямо тут в шаблоне. // при этом галочка "кешируемый" у ресурса игнорируется // и modx-парсер не работает! скорость генерации страницы растет ОЧЕНЬ существенно! // + можно использовать дебаггер //$modx->smarty->debugging=TRUE; $modx->smarty->caching = false; $modx->smarty->display("tpl/{$tpl}"); return ""; // отпрвить $ничего на вывод через modx-парсер. :) modsmarty.class.php: public function display($template, $cache_id = null, $compile_id = null, $parent = null) { echo $this->fetch($template, $cache_id, $compile_id, $parent); } меняем на public function display($template, $cache_id = null, $compile_id = null, $parent = null) { echo $this->fetch($template, $cache_id, $compile_id, $parent, true); } честно говоря не понимаю кто оттуда убрал последний параметр — ибо в оригинальном класе он там был. хотя кажется я догадываюсь кто это сделал. но вот зачем — не понятно ибо эта функция как бы и не использовалась в шаблоне :) собственно последний параметр true как раз и заставляет делать именно echo $_output;;, а не return $_output; ну и чтобы заработал дебаггер делаем изменение в файле debug.tpl:
{foreach $assigned_vars as $vars}{/foreach}
| ${$vars@key|escape:'html'} | {$vars|debug_print_var} |
|---|
| ${$vars@key|escape:'html'} | {$vars|debug_print_var} |
|---|