Ejemplo n.º 1
0
 /**
  * returns run options represents as a hash
  * @return array
  */
 public static function getRunOptions()
 {
     // default run argument values
     $sysInfo = get_sys_info();
     $ini = get_benchmark_ini();
     $defaults = array('active_range' => 100, 'collectd_rrd_dir' => '/var/lib/collectd/rrd', 'fio' => 'fio', 'fio_options' => array('direct' => TRUE, 'ioengine' => 'libaio', 'refill_buffers' => FALSE, 'scramble_buffers' => TRUE), 'font_size' => 9, 'highcharts_js_url' => 'http://code.highcharts.com/highcharts.js', 'highcharts3d_js_url' => 'http://code.highcharts.com/highcharts-3d.js', 'jquery_url' => 'http://code.jquery.com/jquery-2.1.0.min.js', 'meta_compute_service' => 'Not Specified', 'meta_cpu' => $sysInfo['cpu'], 'meta_instance_id' => 'Not Specified', 'meta_memory' => $sysInfo['memory_gb'] > 0 ? $sysInfo['memory_gb'] . ' GB' : $sysInfo['memory_mb'] . ' MB', 'meta_os' => $sysInfo['os_info'], 'meta_provider' => 'Not Specified', 'meta_storage_config' => 'Not Specified', 'meta_test_sw' => isset($ini['meta-id']) ? 'ch-' . $ini['meta-id'] . (isset($ini['meta-version']) ? ' ' . $ini['meta-version'] : '') : '', 'oio_per_thread' => 64, 'output' => trim(shell_exec('pwd')), 'precondition_passes' => 2, 'ss_max_rounds' => 25, 'ss_verification' => 10, 'test' => array('iops'), 'threads' => '{cpus}', 'threads_per_core_max' => 2, 'threads_per_target_max' => 8, 'timeout' => 86400, 'wd_test_duration' => 60);
     $opts = array('active_range:', 'collectd_rrd', 'collectd_rrd_dir:', 'fio:', 'font_size:', 'highcharts_js_url:', 'highcharts3d_js_url:', 'jquery_url:', 'meta_compute_service:', 'meta_compute_service_id:', 'meta_cpu:', 'meta_drive_interface:', 'meta_drive_model:', 'meta_drive_type:', 'meta_instance_id:', 'meta_memory:', 'meta_os:', 'meta_notes_storage:', 'meta_notes_test:', 'meta_provider:', 'meta_provider_id:', 'meta_region:', 'meta_resource_id:', 'meta_run_id:', 'meta_storage_config:', 'meta_storage_vol_info:', 'meta_test_id:', 'meta_test_sw:', 'no3dcharts', 'nojson', 'nopdfreport', 'noprecondition', 'nopurge', 'norandom', 'noreport', 'nosecureerase', 'notrim', 'nozerofill', 'oio_per_thread:', 'output:', 'precondition_passes:', 'randommap', 'savefio', 'secureerase_pswd:', 'sequential_only', 'skip_blocksize:', 'skip_workload:', 'ss_max_rounds:', 'ss_verification:', 'target:', 'target_skip_not_present', 'test:', 'threads:', 'threads_per_core_max:', 'threads_per_target_max:', 'timeout:', 'trim_offset_end:', 'v' => 'verbose', 'wd_test_duration:', 'wd_sleep_between:');
     $options = parse_args($opts, array('skip_blocksize', 'skip_workload', 'target', 'test'));
     $verbose = isset($options['verbose']) && $options['verbose'];
     // explicit fio command
     foreach ($defaults as $key => $val) {
         if (!isset($options[$key])) {
             $options[$key] = $val;
         }
     }
     // target/test argument (expand comma separated values)
     foreach (array('target', 'test') as $key) {
         if (isset($options[$key])) {
             $targets = array();
             foreach ($options[$key] as $temp) {
                 foreach (explode(',', $temp) as $target) {
                     $targets[] = trim($target);
                 }
             }
             $options[$key] = $targets;
         }
     }
     foreach (get_prefixed_params('fio_') as $key => $val) {
         $options['fio_options'][$key] = $val;
     }
     // don't use random IO
     if (isset($options['norandom']) && $options['norandom']) {
         if (isset($options['fio']['refill_buffers'])) {
             unset($options['fio']['refill_buffers']);
         }
         if (isset($options['fio']['scramble_buffers'])) {
             unset($options['fio']['scramble_buffers']);
         }
     }
     // implicit nosecureerase
     if (!isset($options['secureerase_pswd'])) {
         $options['nosecureerase'] = TRUE;
     }
     // implicit nopurge
     if (isset($options['nosecureerase']) && $options['nosecureerase'] && isset($options['notrim']) && $options['notrim'] && isset($options['nozerofill']) && $options['nozerofill']) {
         $options['nopurge'] = TRUE;
     }
     // threads is based on number of CPUs
     if (isset($options['threads']) && preg_match('/{cpus}/', $options['threads'])) {
         $options['threads'] = str_replace(' ', '', str_replace('{cpus}', BlockStorageTest::getCpuCount(), $options['threads']));
         // expression
         if (preg_match('/[\\*\\+\\-\\/]/', $options['threads'])) {
             eval(sprintf('$options["threads"]=%s;', $options['threads']));
         }
         $options['threads'] *= 1;
         if ($options['threads'] <= 0) {
             $options['threads'] = 1;
         }
     }
     // remove targets that are not present
     if (isset($options['target_skip_not_present']) && isset($options['target']) && count($options['target']) > 1) {
         print_msg(sprintf('Checking targets %s because --target_skip_not_present argument was set', implode(', ', $options['target'])), $verbose, __FILE__, __LINE__);
         $targets = array();
         foreach ($options['target'] as $i => $target) {
             if (!is_dir($target) && !file_exists($target)) {
                 print_msg(sprintf('Skipped test target %s because it does not exist and the --target_skip_not_present argument was set', $target), $verbose, __FILE__, __LINE__);
             } else {
                 $targets[] = $target;
             }
         }
         $options['target'] = $targets;
         print_msg(sprintf('Adjusted test targets is %s', implode(', ', $options['target'])), $verbose, __FILE__, __LINE__);
     }
     // adjust threads for number of targets
     if (isset($options['target']) && count($options['target']) > 1) {
         $options['threads'] = round($options['threads'] / count($options['target']));
         if ($options['threads'] == 0) {
             $options['threads'] = 1;
         }
     }
     // adjust for threads_per_target_max
     if (isset($options['threads_per_target_max']) && $options['threads'] > $options['threads_per_target_max']) {
         $threads = $options['threads'];
         $options['threads'] = $options['threads_per_target_max'];
         print_msg(sprintf('Reduced threads from %d to %d for threads_per_target_max constraint %d', $threads, $options['threads'], $options['threads_per_target_max']), $verbose, __FILE__, __LINE__);
     }
     $options['threads_total'] = $options['threads'] * count($options['target']);
     // adjust for threads_per_core_max
     if (isset($options['threads_per_core_max']) && $options['threads_total'] > $options['threads_per_core_max'] * BlockStorageTest::getCpuCount()) {
         $threads_total = $options['threads_total'];
         $threads = $options['threads'];
         $options['threads'] = round($options['threads_per_core_max'] * BlockStorageTest::getCpuCount() / count($options['target']));
         if (!$options['threads']) {
             $options['threads'] = 1;
         }
         $options['threads_total'] = round($options['threads'] * count($options['target']));
         if ($threads != $options['threads']) {
             print_msg(sprintf('Reduced total threads from %d to %d [threads per target from %d to %s] for threads_per_core_max constraint %d, %d CPU cores, and %d targets', $threads_total, $options['threads_total'], $threads, $options['threads'], $options['threads_per_core_max'], BlockStorageTest::getCpuCount(), count($options['target'])), $verbose, __FILE__, __LINE__);
         } else {
             print_msg(sprintf('Ignoring threads_per_core_max constraint %d because at least 1 thread per target is required', $options['threads_per_core_max']), $verbose, __FILE__, __LINE__);
         }
     }
     return $options;
 }
Ejemplo n.º 2
0
 /**
  * Adds a $row to $table
  * @param string $table 
  * @param array $row 
  * @return boolean
  */
 public final function addRow($table, $row)
 {
     $added = FALSE;
     if ($table && is_array($row)) {
         $this->addBenchmarkMeta($row);
         // add system meta information
         foreach (get_sys_info() as $k => $v) {
             if (!isset($row[sprintf('meta_%s', $k)])) {
                 $row[sprintf('meta_%s', $k)] = $v;
             }
         }
         $added = TRUE;
         if (!isset($this->rows[$table])) {
             $this->rows[$table] = array();
         }
         $this->rows[$table][] = array_merge($row, $this->artifacts);
     }
     return $added;
 }
Ejemplo n.º 3
0
 /**
  * returns run options represents as a hash
  * @return array
  */
 public function getRunOptions()
 {
     if (!isset($this->options)) {
         if ($this->dir) {
             $this->options = self::getSerializedOptions($this->dir);
             $this->verbose = isset($this->options['verbose']);
         } else {
             // default run argument values
             $sysInfo = get_sys_info();
             $defaults = array('collectd_rrd_dir' => '/var/lib/collectd/rrd', 'dns_retry' => 2, 'dns_samples' => 10, 'dns_timeout' => 5, 'geo_regions' => 'us_west us_central us_east canada eu_west eu_central eu_east oceania asia america_south africa', 'latency_interval' => 0.2, 'latency_samples' => 100, 'latency_timeout' => 3, 'meta_cpu' => $sysInfo['cpu'], 'meta_memory' => $sysInfo['memory_gb'] > 0 ? $sysInfo['memory_gb'] . ' GB' : $sysInfo['memory_mb'] . ' MB', 'meta_os' => $sysInfo['os_info'], 'output' => trim(shell_exec('pwd')), 'spacing' => 200, 'test' => 'latency', 'throughput_size' => 5, 'throughput_threads' => 2, 'throughput_uri' => '/web-probe');
             $opts = array('abort_threshold:', 'collectd_rrd', 'collectd_rrd_dir:', 'discard_fastest:', 'discard_slowest:', 'dns_one_server', 'dns_retry:', 'dns_samples:', 'dns_tcp', 'dns_timeout:', 'geoiplookup', 'geo_regions:', 'latency_interval:', 'latency_samples:', 'latency_skip:', 'latency_timeout:', 'max_runtime:', 'max_tests:', 'meta_compute_service:', 'meta_compute_service_id:', 'meta_cpu:', 'meta_instance_id:', 'meta_location:', 'meta_memory:', 'meta_os:', 'meta_provider:', 'meta_provider_id:', 'meta_region:', 'meta_resource_id:', 'meta_run_id:', 'meta_test_id:', 'min_runtime:', 'min_runtime_in_save', 'output:', 'params_url:', 'params_url_service_type:', 'params_url_header:', 'randomize', 'same_continent_only', 'same_country_only', 'same_geo_region', 'same_provider_only', 'same_region_only', 'same_service_only', 'same_state_only', 'service_lookup', 'sleep_before_start:', 'spacing:', 'suppress_failed', 'test:', 'test_endpoint:', 'test_instance_id:', 'test_location:', 'test_private_network_type:', 'test_provider:', 'test_provider_id:', 'test_region:', 'test_service:', 'test_service_id:', 'test_service_type:', 'throughput_header:', 'throughput_https', 'throughput_inverse', 'throughput_keepalive', 'throughput_same_continent:', 'throughput_same_country:', 'throughput_same_geo_region:', 'throughput_same_provider:', 'throughput_same_region:', 'throughput_same_service:', 'throughput_same_state:', 'throughput_samples:', 'throughput_size:', 'throughput_slowest_thread', 'throughput_small_file', 'throughput_threads:', 'throughput_time', 'throughput_timeout:', 'throughput_uri:', 'throughput_use_mean', 'throughput_webpage:', 'throughput_webpage_check', 'traceroute', 'v' => 'verbose');
             $this->options = parse_args($opts, array('latency_skip', 'params_url_service_type', 'params_url_header', 'test', 'test_endpoint', 'test_instance_id', 'test_location', 'test_provider', 'test_provider_id', 'test_region', 'test_service', 'test_service_id', 'test_service_type', 'throughput_header', 'throughput_webpage'));
             $this->options['run_start'] = time();
             $this->verbose = isset($this->options['verbose']);
             // set default same size constraints if --throughput_size is not set
             if (!isset($this->options['throughput_size'])) {
                 foreach (array('throughput_same_continent' => 10, 'throughput_same_country' => 20, 'throughput_same_geo_region' => 30, 'throughput_same_provider' => 10, 'throughput_same_region' => 100, 'throughput_same_state' => 50) as $k => $v) {
                     $defaults[$k] = $v;
                 }
             }
             foreach ($defaults as $key => $val) {
                 if (!isset($this->options[$key])) {
                     $this->options[$key] = $val;
                     $this->defaultsSet[] = $key;
                 }
             }
             if (isset($this->options['throughput_size']) && $this->options['throughput_size'] == 0) {
                 $this->options['throughput_time'] = TRUE;
             }
             if (!isset($this->options['throughput_samples'])) {
                 $this->options['throughput_samples'] = isset($this->options['throughput_small_file']) || isset($this->options['throughput_time']) ? 10 : 5;
             }
             if (!isset($this->options['throughput_timeout'])) {
                 $this->options['throughput_timeout'] = isset($this->options['throughput_small_file']) || isset($this->options['throughput_time']) ? 5 : 180;
             }
             // expand geo_regions
             if (isset($this->options['geo_regions'])) {
                 $geoRegions = array();
                 foreach (explode(',', $this->options['geo_regions']) as $r1) {
                     foreach (explode(' ', $r1) as $r2) {
                         $r2 = strtolower(trim($r2));
                         if ($r2 && !in_array($r2, $geoRegions)) {
                             $geoRegions[] = $r2;
                         }
                     }
                 }
                 if ($geoRegions) {
                     $this->options['geo_regions'] = $geoRegions;
                 }
             }
             // expand tests
             if (!is_array($this->options['test'])) {
                 $this->options['test'] = array($this->options['test']);
             }
             foreach ($this->options['test'] as $i => $test) {
                 $tests = array();
                 foreach (explode(',', $test) as $t1) {
                     foreach (explode(' ', $t1) as $t2) {
                         $t2 = strtolower(trim($t2));
                         if ($t2 && !in_array($t2, $tests)) {
                             $tests[] = $t2;
                         }
                     }
                 }
                 if ($tests) {
                     $this->options['test'][$i] = $tests;
                 } else {
                     unset($this->options['test'][$i]);
                 }
             }
             // get parameters from a URL
             if (isset($this->options['params_url'])) {
                 $headers = array();
                 if (isset($this->options['params_url_header'])) {
                     foreach ($this->options['params_url_header'] as $header) {
                         if (preg_match('/^(.*):(.*)$/', $header, $m)) {
                             $headers[trim($m[1])] = trim($m[2]);
                         } else {
                             print_msg(sprintf('Skipping header %s because it is not properly formatted ([key]:[val])', $header), $this->verbose, __FILE__, __LINE__, TRUE);
                         }
                     }
                 }
                 if ($params = json_decode($json = ch_curl($this->options['params_url'], 'GET', $headers, NULL, NULL, '200-299', TRUE), TRUE)) {
                     print_msg(sprintf('Successfully retrieved %d runtime parameters from the URL %s', count($params), $this->options['params_url']), $this->verbose, __FILE__, __LINE__);
                     foreach ($params as $key => $val) {
                         if (!isset($this->options[$key]) || in_array($key, $this->defaultsSet)) {
                             print_msg(sprintf('Added runtime parameter %s=%s from --params_url', $key, is_array($val) ? implode(',', $val) : $val), $this->verbose, __FILE__, __LINE__);
                             $this->options[$key] = $val;
                         } else {
                             print_msg(sprintf('Skipping runtime parameter %s=%s from --params_url because it was set on the command line', $key, $val), $this->verbose, __FILE__, __LINE__);
                         }
                     }
                     // remove test endpoints that are not of the --params_url_service_type
                     // specified
                     if (isset($this->options['params_url_service_type'])) {
                         foreach ($this->options['test_endpoint'] as $i => $endpoint) {
                             if (!isset($this->options['test_service_type'][$i]) || !in_array($this->options['test_service_type'][$i], $this->options['params_url_service_type'])) {
                                 print_msg(sprintf('Removing test endpoint %s because it is not included in the allowed service types: %s', $endpoint, implode(', ', $this->options['params_url_service_type'])), $this->verbose, __FILE__, __LINE__);
                                 unset($this->options['test_endpoint'][$i]);
                             }
                         }
                     }
                 } else {
                     return array('params_url' => is_string($json) ? sprintf('Response from --params_url %s is not valid JSON: %s', $this->options['params_url'], $json) : sprintf('Unable to retrieve data from --params_url %s', $this->options['params_url']));
                 }
             }
             // expand test endpoints: first element is public hostname/IP; second is private
             if (isset($this->options['test_endpoint'])) {
                 foreach ($this->options['test_endpoint'] as $i => $endpoint) {
                     $endpoints = array();
                     foreach (explode(',', $endpoint) as $e1) {
                         foreach (explode(' ', $e1) as $e2) {
                             $e2 = trim($e2);
                             if ($e2 && !in_array($e2, $endpoints)) {
                                 $endpoints[] = $e2;
                             }
                             if (count($endpoints) == 2) {
                                 break;
                             }
                         }
                         if (count($endpoints) == 2) {
                             break;
                         }
                     }
                     if ($endpoints) {
                         $this->options['test_endpoint'][$i] = $endpoints;
                     } else {
                         unset($this->options['test_endpoint'][$i]);
                     }
                 }
             }
             // perform service lookups using CloudHarmony 'Identify Service' API
             if (isset($this->options['service_lookup'])) {
                 foreach ($this->options['test_endpoint'] as $i => $endpoints) {
                     $hostname = str_replace('*', rand(), get_hostname($endpoints[0]));
                     if (!isset($this->options['test_service_id'][$i]) && ($response = get_service_info($hostname, $this->verbose))) {
                         if (!isset($this->options['test_provider_id'][$i])) {
                             $this->options['test_provider_id'][$i] = $response['providerId'];
                         }
                         if (!isset($this->options['test_service_id'][$i])) {
                             $this->options['test_service_id'][$i] = $response['serviceId'];
                         }
                         if (!isset($this->options['test_service_type'][$i])) {
                             $this->options['test_service_type'][$i] = $response['serviceType'];
                         }
                         if (!isset($this->options['test_region'][$i]) && isset($response['region'])) {
                             $this->options['test_region'][$i] = $response['region'];
                         }
                         if (!isset($this->options['test_location'][$i]) && isset($response['country'])) {
                             $this->options['test_location'][$i] = sprintf('%s%s', isset($response['state']) ? $response['state'] . ',' : '', $response['country']);
                         }
                     }
                 }
                 if (!isset($this->options['meta_compute_service_id']) && ($hostname = trim(shell_exec('hostname'))) && ($response = get_service_info($hostname, $this->verbose))) {
                     if (!isset($this->options['meta_provider_id'])) {
                         $this->options['meta_provider_id'] = $response['providerId'];
                     }
                     if (!isset($this->options['meta_compute_service_id'])) {
                         $this->options['meta_compute_service_id'] = $response['serviceId'];
                     }
                     if (!isset($this->options['meta_region']) && isset($response['region'])) {
                         $this->options['meta_region'] = $response['region'];
                     }
                     if (!isset($this->options['meta_location']) && isset($response['country'])) {
                         $this->options['meta_location'] = sprintf('%s%s', isset($response['state']) ? $response['state'] . ',' : '', $response['country']);
                     }
                 }
             }
             // perform geo ip lookups to determine endpoint locations
             if (isset($this->options['geoiplookup'])) {
                 foreach ($this->options['test_endpoint'] as $i => $endpoints) {
                     $hostname = str_replace('*', rand(), get_hostname($endpoints[0]));
                     if (!isset($this->options['test_location'][$i]) && (!isset($this->options['test_service_type'][$i]) || $this->options['test_service_type'][$i] != 'cdn' && $this->options['test_service_type'][$i] != 'dns') && ($geoip = geoiplookup($hostname, $this->verbose))) {
                         $this->options['test_location'][$i] = sprintf('%s%s', isset($geoip['state']) ? $geoip['state'] . ', ' : '', $geoip['country']);
                     }
                 }
                 if (!isset($this->options['meta_location']) && ($hostname = trim(shell_exec('hostname'))) && ($geoip = geoiplookup($hostname, $this->verbose))) {
                     $this->options['meta_location'] = sprintf('%s%s', isset($geoip['state']) ? $geoip['state'] . ', ' : '', $geoip['country']);
                 }
             }
             // expand meta_location to meta_location_country and meta_location_state
             if (isset($this->options['meta_location'])) {
                 $pieces = explode(',', $this->options['meta_location']);
                 $this->options['meta_location_country'] = strtoupper(trim($pieces[count($pieces) - 1]));
                 if (count($pieces) > 1) {
                     $this->options['meta_location_state'] = trim($pieces[0]);
                 }
             }
             // expand test_location to test_location_country and test_location_state
             if (isset($this->options['test_location'])) {
                 $this->options['test_location_country'] = array();
                 $this->options['test_location_state'] = array();
                 foreach ($this->options['test_location'] as $i => $location) {
                     $pieces = explode(',', $location);
                     $this->options['test_location_country'][$i] = strtoupper(trim($pieces[count($pieces) - 1]));
                     $this->options['test_location_state'][$i] = count($pieces) > 1 ? trim($pieces[0]) : NULL;
                 }
             }
             // expand throughput_webpage
             if (isset($this->options['throughput_webpage'])) {
                 foreach ($this->options['throughput_webpage'] as $i => $resource) {
                     $resources = array();
                     foreach (explode(',', $resource) as $e1) {
                         foreach (explode(' ', $e1) as $e2) {
                             $e2 = trim($e2);
                             $resources[] = $e2;
                         }
                     }
                     if ($resources) {
                         $this->options['throughput_webpage'][$i] = $resources;
                     } else {
                         unset($this->options['throughput_webpage'][$i]);
                     }
                 }
             }
             // set meta_geo_region
             if (isset($this->options['meta_location'])) {
                 $pieces = explode(',', $this->options['meta_location']);
                 $this->options['meta_location_country'] = strtoupper(trim($pieces[count($pieces) - 1]));
                 $this->options['meta_location_state'] = count($pieces) > 1 ? trim($pieces[0]) : NULL;
                 if ($geoRegion = $this->getGeoRegion($this->options['meta_location_country'], isset($this->options['meta_location_state']) ? $this->options['meta_location_state'] : NULL)) {
                     $this->options['meta_geo_region'] = $geoRegion;
                 }
             }
         }
     }
     return $this->options;
 }