Proyectos de Subversion Moodle

Rev

Rev 1 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
// This file is part of Moodle - http://moodle.org/
3
//
4
// Moodle is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8
//
9
// Moodle is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
16
 
17
/**
18
 * Store performance test run + output script.
19
 *
1441 ariadna 20
 * @package    core_cache
1 efrain 21
 * @category   cache
22
 * @copyright  2012 Sam Hemelryk
23
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24
 */
25
 
26
require_once('../config.php');
1441 ariadna 27
require_once($CFG->dirroot . '/lib/adminlib.php');
1 efrain 28
 
29
$count = optional_param('count', 100, PARAM_INT);
30
$count = min($count, 100000);
31
$count = max($count, 0);
32
 
33
admin_externalpage_setup('cachetestperformance');
34
 
35
$applicationtable = new html_table();
1441 ariadna 36
$applicationtable->head = [
1 efrain 37
    get_string('plugin', 'cache'),
38
    get_string('result', 'cache'),
39
    get_string('set', 'cache'),
40
    get_string('gethit', 'cache'),
41
    get_string('getmiss', 'cache'),
42
    get_string('delete', 'cache'),
1441 ariadna 43
];
44
$applicationtable->data = [];
1 efrain 45
$sessiontable = clone($applicationtable);
46
$requesttable = clone($applicationtable);
47
 
48
 
49
$application = cache_definition::load_adhoc(cache_store::MODE_APPLICATION, 'cache', 'applicationtest');
50
$session = cache_definition::load_adhoc(cache_store::MODE_SESSION, 'cache', 'sessiontest');
51
$request = cache_definition::load_adhoc(cache_store::MODE_REQUEST, 'cache', 'requesttest');
52
 
53
$strinvalidplugin = new lang_string('invalidplugin', 'cache');
54
$strunsupportedmode = new lang_string('unsupportedmode', 'cache');
55
$struntestable = new lang_string('untestable', 'cache');
56
$strtested = new lang_string('tested', 'cache');
57
$strnotready = new lang_string('storenotready', 'cache');
58
 
59
foreach (core_component::get_plugin_list_with_file('cachestore', 'lib.php', true) as $plugin => $path) {
1441 ariadna 60
    $class = 'cachestore_' . $plugin;
61
    $plugin = get_string('pluginname', 'cachestore_' . $plugin);
1 efrain 62
 
63
    if (!class_exists($class) || !method_exists($class, 'initialise_test_instance') || !$class::are_requirements_met()) {
1441 ariadna 64
        $applicationtable->data[] = [$plugin, $strinvalidplugin, '-', '-', '-', '-'];
65
        $sessiontable->data[] = [$plugin, $strinvalidplugin, '-', '-', '-', '-'];
66
        $requesttable->data[] = [$plugin, $strinvalidplugin, '-', '-', '-', '-'];
1 efrain 67
        continue;
68
    }
69
 
70
    if (!$class::is_supported_mode(cache_store::MODE_APPLICATION)) {
1441 ariadna 71
        $applicationtable->data[] = [$plugin, $strunsupportedmode, '-', '-', '-', '-'];
1 efrain 72
    } else {
73
        $store = $class::initialise_test_instance($application);
74
        if ($store === false) {
1441 ariadna 75
            $applicationtable->data[] = [$plugin, $struntestable, '-', '-', '-', '-'];
1 efrain 76
        } else if (!$store->is_ready()) {
1441 ariadna 77
            $applicationtable->data[] = [$plugin, $strnotready, '-', '-', '-', '-'];
1 efrain 78
        } else {
1441 ariadna 79
            $result = [$plugin, $strtested, 0, 0, 0];
1 efrain 80
            $start = microtime(true);
81
            for ($i = 0; $i < $count; $i++) {
1441 ariadna 82
                $store->set('key' . $i, 'test data ' . $i);
1 efrain 83
            }
84
            $result[2] = sprintf('%01.4f', microtime(true) - $start);
85
 
86
            $start = microtime(true);
87
            for ($i = 0; $i < $count; $i++) {
1441 ariadna 88
                $store->get('key' . $i);
1 efrain 89
            }
90
            $result[3] = sprintf('%01.4f', microtime(true) - $start);
91
 
92
            $start = microtime(true);
93
            for ($i = 0; $i < $count; $i++) {
1441 ariadna 94
                $store->get('fake' . $i);
1 efrain 95
            }
96
            $result[4] = sprintf('%01.4f', microtime(true) - $start);
97
 
98
            $start = microtime(true);
99
            for ($i = 0; $i < $count; $i++) {
1441 ariadna 100
                $store->delete('key' . $i);
1 efrain 101
            }
102
            $result[5] = sprintf('%01.4f', microtime(true) - $start);
103
            $applicationtable->data[] = $result;
104
            $store->instance_deleted();
105
        }
106
    }
107
 
108
    if (!$class::is_supported_mode(cache_store::MODE_SESSION)) {
1441 ariadna 109
        $sessiontable->data[] = [$plugin, $strunsupportedmode, '-', '-', '-', '-'];
1 efrain 110
    } else {
111
        $store = $class::initialise_test_instance($session);
112
        if ($store === false) {
1441 ariadna 113
            $sessiontable->data[] = [$plugin, $struntestable, '-', '-', '-', '-'];
1 efrain 114
        } else if (!$store->is_ready()) {
1441 ariadna 115
            $sessiontable->data[] = [$plugin, $strnotready, '-', '-', '-', '-'];
1 efrain 116
        } else {
1441 ariadna 117
            $result = [$plugin, $strtested, 0, 0, 0];
1 efrain 118
            $start = microtime(true);
119
            for ($i = 0; $i < $count; $i++) {
1441 ariadna 120
                $store->set('key' . $i, 'test data ' . $i);
1 efrain 121
            }
122
            $result[2] = sprintf('%01.4f', microtime(true) - $start);
123
 
124
            $start = microtime(true);
125
            for ($i = 0; $i < $count; $i++) {
1441 ariadna 126
                $store->get('key' . $i);
1 efrain 127
            }
128
            $result[3] = sprintf('%01.4f', microtime(true) - $start);
129
 
130
            $start = microtime(true);
131
            for ($i = 0; $i < $count; $i++) {
1441 ariadna 132
                $store->get('fake' . $i);
1 efrain 133
            }
134
            $result[4] = sprintf('%01.4f', microtime(true) - $start);
135
 
136
            $start = microtime(true);
137
            for ($i = 0; $i < $count; $i++) {
1441 ariadna 138
                $store->delete('key' . $i);
1 efrain 139
            }
140
            $result[5] = sprintf('%01.4f', microtime(true) - $start);
141
            $sessiontable->data[] = $result;
142
            $store->instance_deleted();
143
        }
144
    }
145
 
146
    if (!$class::is_supported_mode(cache_store::MODE_REQUEST)) {
1441 ariadna 147
        $requesttable->data[] = [$plugin, $strunsupportedmode, '-', '-', '-', '-'];
1 efrain 148
    } else {
149
        $store = $class::initialise_test_instance($request);
150
        if ($store === false) {
1441 ariadna 151
            $requesttable->data[] = [$plugin, $struntestable, '-', '-', '-', '-'];
1 efrain 152
        } else if (!$store->is_ready()) {
1441 ariadna 153
            $requesttable->data[] = [$plugin, $strnotready, '-', '-', '-', '-'];
1 efrain 154
        } else {
1441 ariadna 155
            $result = [$plugin, $strtested, 0, 0, 0];
1 efrain 156
            $start = microtime(true);
157
            for ($i = 0; $i < $count; $i++) {
1441 ariadna 158
                $store->set('key' . $i, 'test data ' . $i);
1 efrain 159
            }
160
            $result[2] = sprintf('%01.4f', microtime(true) - $start);
161
 
162
            $start = microtime(true);
163
            for ($i = 0; $i < $count; $i++) {
1441 ariadna 164
                $store->get('key' . $i);
1 efrain 165
            }
166
            $result[3] = sprintf('%01.4f', microtime(true) - $start);
167
 
168
            $start = microtime(true);
169
            for ($i = 0; $i < $count; $i++) {
1441 ariadna 170
                $store->get('fake' . $i);
1 efrain 171
            }
172
            $result[4] = sprintf('%01.4f', microtime(true) - $start);
173
 
174
            $start = microtime(true);
175
            for ($i = 0; $i < $count; $i++) {
1441 ariadna 176
                $store->delete('key' . $i);
1 efrain 177
            }
178
            $result[5] = sprintf('%01.4f', microtime(true) - $start);
179
            $requesttable->data[] = $result;
180
            $store->instance_deleted();
181
        }
182
    }
183
}
184
 
185
echo $OUTPUT->header();
186
echo $OUTPUT->heading(get_string('storeperformance', 'cache', $count));
187
 
1441 ariadna 188
$possiblecounts = [1, 10, 100, 500, 1000, 5000, 10000, 50000, 100000];
189
$links = [];
1 efrain 190
foreach ($possiblecounts as $pcount) {
1441 ariadna 191
    $links[] = html_writer::link(new moodle_url($PAGE->url, ['count' => $pcount]), $pcount);
1 efrain 192
}
193
echo $OUTPUT->box_start('generalbox performance-test-counts');
194
echo get_string('requestcount', 'cache', join(', ', $links));
195
echo $OUTPUT->box_end();
196
 
197
echo $OUTPUT->heading(get_string('storeresults_application', 'cache'));
198
echo html_writer::table($applicationtable);
199
 
200
echo $OUTPUT->heading(get_string('storeresults_session', 'cache'));
201
echo html_writer::table($sessiontable);
202
 
203
echo $OUTPUT->heading(get_string('storeresults_request', 'cache'));
204
echo html_writer::table($requesttable);
205
 
206
echo $OUTPUT->footer();