1 <!DOCTYPE HTML
PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
4 <title
>Stress Test
</title
>
13 This script will create:
15 $scale * 10 ARO groups
17 $scale * 10 AXO groups
27 set_time_limit (6000);
30 get time accurate to the nearest microsecond, used for script timing
32 function getmicrotime ()
34 list ($usec, $sec) = explode (' ', microtime ());
35 return (float)$usec +
(float)$sec;
39 a better array_rand, this one actually works on windows
41 function array_mt_rand ($array, $items)
43 $keys = array_keys ($array);
44 $max = count ($keys) - 1;
48 return $keys[mt_rand (0, $max)];
53 for ( $i = 1; $i <= $items; $i++
)
55 $return[] = $keys[mt_rand (0, $max)];
62 require_once (dirname (__FILE__
) . '/../admin/gacl_admin.inc.php');
65 * Let's get ready to RUMBLE!!!
68 echo '<b>Stress Test</b>' . "\n";
69 echo ' Scale: ' . $scale . "\n\n";
71 $overall_start = getmicrotime ();
73 mt_srand ((double)microtime () *10000);
75 $gacl_api->add_object_section ('System', 'system', 0, 0, 'ACO');
77 echo "<b>Create ACOs</b>\n";
81 $start_time = getmicrotime ();
85 for ( $i = $start; $i <= $max; $i++
)
87 if ( $gacl_api->add_object ('system', 'ACO: ' . $i, $i, 10, 0, 'ACO') == FALSE )
89 echo " Error creating ACO: $i.\n";
90 echo ' ' . $gacl_api->_debug_msg
. "\n";
94 $elapsed = getmicrotime () - $start_time;
97 echo ' Count: ' . $max . "\n";
98 echo ' Time: ' . $elapsed . " s\n";
99 echo ' Average: ' . $elapsed/$max . " s\n\n";
103 $gacl_api->add_object_section ('Users', 'users', 0, 0, 'ARO');
105 echo "<b>Create many ARO Groups.</b>\n";
108 $start_time = getmicrotime ();
110 $query = 'SELECT id FROM '.$gacl_api->_db_table_prefix
.'aro_groups';
111 $ids = $gacl_api->db
->GetCol($query);
118 // function add_group ($name, $parent_id=0, $group_type='ARO') {
119 for ( $i = $start; $i <= $max; $i++
)
121 // Find a random parent
122 if ( !empty ($ids) ) {
123 $parent_id = $ids[array_mt_rand ($ids, 1)];
128 $result = $gacl_api->add_group ('aro_group'.$i,'ARO Group: '. $i, $parent_id, 'ARO');
130 if ( $result == FALSE )
132 echo " Error creating ARO Group: $i.\n";
133 echo ' ' . $gacl_api->_debug_msg
. "\n";
141 $elapsed = getmicrotime () - $start_time;
144 echo ' Count: ' . $max . "\n";
145 echo ' Time: ' . $elapsed . " s\n";
146 echo ' Average: ' . $elapsed/$max . " s\n\n";
150 echo "<b>Create AROs & assign to ARO Groups</b>\n";
153 $start_time = getmicrotime ();
156 $max = 1000 * $scale;
158 $groups = array_keys ($gacl_api->format_groups ($gacl_api->sort_groups ('ARO'), 'ARRAY'));
159 $randmax = count ($groups) - 1;
161 for ( $i = $start; $i <= $max; $i++
)
163 if ( $gacl_api->add_object ('users', 'ARO: '. $i, $i, 10, 0, 'ARO') == FALSE )
165 echo " Error creating ARO: $i.<br />\n";
166 echo ' ' . $gacl_api->_debug_msg
. "\n";
170 // Assign to random groups.
171 $rand_key = $groups[mt_rand (0, $randmax)];
172 $gacl_api->add_group_object ($rand_key, 'users', $i, 'ARO');
176 $elapsed = getmicrotime () - $start_time;
179 echo ' Count: ' . $max . "\n";
180 echo ' Time: ' . $elapsed . " s\n";
181 echo ' Average: ' . $elapsed/$max . " s\n\n";
186 $gacl_api->add_object_section ('Users', 'users', 0, 0, 'AXO');
188 echo "<b>Create many AXO Groups.</b>\n";
191 $start_time = getmicrotime ();
193 $query = 'SELECT id FROM '.$gacl_api->_db_table_prefix
.'axo_groups';
194 $ids = $gacl_api->db
->GetCol($query);
199 // function add_group ($name, $parent_id=0, $group_type='ARO') {
200 for ( $i = $start; $i <= $max; $i++
)
202 // Find a random parent
203 if ( !empty ($ids) ) {
204 $parent_id = $ids[array_mt_rand ($ids, 1)];
209 $result = $gacl_api->add_group ('axo_group'.$i,'AXO Group: '. $i, $parent_id, 'AXO');
210 if ( $result == FALSE )
212 echo " Error creating AXO Group: $i.\n";
213 echo ' ' . $gacl_api->_debug_msg
. "\n";
221 $elapsed = getmicrotime () - $start_time;
224 echo ' Count: ' . $max . "\n";
225 echo ' Time: ' . $elapsed . " s\n";
226 echo ' Average: ' . $elapsed/$max . " s\n\n";
230 echo "<b>Create AXOs & assign to AXO Groups</b>\n";
233 $start_time = getmicrotime ();
236 $max = 1000 * $scale;
238 // $groups = array_keys ($gacl_api->format_groups ($gacl_api->sort_groups ('AXO'), 'ARRAY'));
239 $rand_max = count ($groups) - 1;
241 for ( $i = $start; $i <= $max; $i++
)
243 if ( $gacl_api->add_object ('users', 'AXO: ' . $i, $i, 10, 0, 'AXO') == FALSE )
245 echo " Error creating ARO: $i.<br />\n";
246 echo ' ' . $gacl_api->_debug_msg
. "\n";
250 // Assign to random groups.
251 $rand_key = $groups[mt_rand (0, $rand_max)];
252 $gacl_api->add_group_object ($rand_key, 'users', $i, 'AXO');
256 $elapsed = getmicrotime () - $start_time;
259 echo ' Count: ' . $max . "\n";
260 echo ' Time: ' . $elapsed . " s\n";
261 echo ' Average: ' . $elapsed/$max . " s\n\n";
265 echo "<b>Generate random ACLs now.</b>\n";
268 $start_time = getmicrotime ();
273 $aco_list = $gacl_api->get_object ('system', 1, 'ACO');
275 $query = 'SELECT id, name FROM '.$gacl_api->_db_table_prefix
.''. $gacl_.'aro_groups ORDER BY parent_id DESC LIMIT 100';
276 $rs = $gacl_api->db
->Execute($query);
277 $aro_groups = $rs->GetAssoc();
279 $query = 'SELECT id, name FROM '.$gacl_api->_db_table_prefix
.'axo_groups ORDER BY parent_id DESC LIMIT 100';
280 $rs = $gacl_api->db
->Execute($query);
281 $axo_groups = $rs->GetAssoc();
283 // $aro_groups = $gacl_api->format_groups ($gacl_api->sort_groups ('ARO'), 'ARRAY');
285 print_r ($aro_groups);
287 // $axo_groups = $gacl_api->format_groups ($gacl_api->sort_groups ('AXO'), 'ARRAY');
289 print_r ($axo_groups);
291 for ( $i = $start; $i <= $max; $i++
)
293 $rand_aco_key = array_mt_rand ($aco_list, mt_rand (2, 10));
294 $rand_aro_key = array_mt_rand ($aro_groups, mt_rand(2,10));
295 $rand_axo_key = array_mt_rand ($axo_groups, mt_rand(2,10));
297 $aco_array = array ();
299 foreach ( $rand_aco_key as $aco_key )
301 $aco_data = $gacl_api->get_object_data ($aco_list[$aco_key], 'ACO');
302 $aco_array[$aco_data[0][0]][] = $aco_data[0][1];
305 // Randomly create ACLs with AXOs assigned to them.
306 // if ($i % 2 == 0) {
307 $axo_array = $rand_axo_key;
310 if ( $gacl_api->add_acl ($aco_array, NULL, $rand_aro_key, NULL, $axo_array) == FALSE )
312 echo " Error creating ACL: $i.\n";
313 echo ' ' . $gacl_api->_debug_msg
. "\n";
314 // print_r (array_slice ($gacl_api->_debug_msg, -2));
320 $elapsed = getmicrotime () - $start_time;
323 echo ' Count: ' . $max . "\n";
324 echo ' Time: ' . $elapsed . " s\n";
325 echo ' Average: ' . $elapsed/$max . " s\n\n";
328 echo "<b>Generating Test Data Set</b>\n";
331 $start_time = getmicrotime ();
339 for ( $i = $start; $i <= $max; $i++
)
341 $rand_aco_key = mt_rand (10,10 * $scale);
342 $rand_aro_key = mt_rand (10,1000 * $scale);
343 $rand_axo_key = mt_rand (10,1000 * $scale);
345 // echo ' Rand ACO: '. $rand_aco_key .' ARO: '. $rand_aro_key . ' AXO: ' . $rand_axo_key . "\n";
347 $aco_data = &$gacl_api->get_object_data ($rand_aco_key, 'ACO');
348 $aro_data = &$gacl_api->get_object_data ($rand_aro_key, 'ARO');
349 $axo_data = &$gacl_api->get_object_data ($rand_axo_key, 'AXO');
352 'aco' => $aco_data[0],
353 'aro' => $aro_data[0],
354 'axo' => $axo_data[0]
358 $elapsed = getmicrotime () - $start_time;
361 echo ' Count: ' . $max . "\n";
362 echo ' Time: ' . $elapsed . " s\n";
363 echo ' Average: ' . $elapsed/$max . " s\n\n";
365 echo "<b>Testing...</b>\n";
372 foreach ( $check as $i => $data )
374 echo ' Trying: ACO Section: '. $data['aco'][0] .' Value: '. $data['aco'][1] .' ARO Section: '. $data['aro'][0] .' Value: '. $data['aro'][1] . ' ARO Section: '. $data['axo'][0] .' Value: '. $data['axo'][1] . "\n";
376 $check_start = getmicrotime ();
378 $allow = $gacl_api->acl_check ($data['aco'][0],$data['aco'][1],$data['aro'][0],$data['aro'][1],$data['axo'][0],$data['axo'][1]);
380 $check_time = getmicrotime () - $check_start;
383 echo '<font color="#00ff00"> ' . $i . ". Access Granted!</font>";
385 echo '<font color="#ff0000"> ' . $i . ". Access Denied!</font>";
388 echo ' - ' . $check_time . " s\n";
390 $best = min ($best, $check_time);
391 $worst = max ($worst, $check_time);
392 $total = $total +
$check_time;
396 echo ' Count: ' . $max . "\n\n";
398 echo ' Total: ' . $total . " s\n";
399 echo ' Average: ' . $total/$max . " s\n\n";
401 echo ' Best: ' . $best . " s\n";
402 echo ' Worst: ' . $worst . " s\n\n";
404 // print_r ($gacl_api->db);
407 $elapsed = getmicrotime () - $overall_start;
409 echo '<b>All Finished</b>' . "\n";
410 echo ' Total Time: ' . $elapsed . " s\n";