Ejemplo n.º 1
0
    def bench_net_throughput(self, config, redis: RedisCluster, java, nodes_trace):
        """
        This benchmark proceeds similarly to _bench_checksum, but captures the network traffic coming and going to Redis
        servers.
        """
        dumpcap = ['/usr/bin/dumpcap', '-q', '-i', 'any', '-f', 'tcp port 6379', '-s', '64', '-w']

        print("Starting dumpcap")
        isoformat = datetime.today().isoformat()
        capture_dir = '/opt/erasuretester/results/'
        write_capture_file = 'capture_%s_%s_write.pcapng' % (isoformat, config[0])
        sleep(5)
        dumpcap_proc = subprocess.Popen(dumpcap + [capture_dir + write_capture_file])
        sleep(10)
        print("Uncompressing archive")
        tar_proc = subprocess.Popen(['tar', '-xvf', '/opt/erasuretester/httpd.tar.bz2', '-C', self.mount],
                                    stdout=subprocess.PIPE, bufsize=1)
        self._show_subprocess_percent(tar_proc, 2614)
        sleep(10)
        kill_pid(dumpcap_proc)
        subprocess.check_call(['chmod', '666', capture_dir + write_capture_file])

        measures = []
        for redis_size in (x[0] for x in nodes_trace):
            redis.scale(redis_size, brutal=True)
            capture_file = 'capture_%s_%s_read_%d.pcapng' % (isoformat, config[0], redis_size)

            dumpcap_proc = subprocess.Popen(dumpcap + [capture_dir + capture_file])
            sleep(10)
            print('Checking files...')
            sha_proc = subprocess.Popen(
                ['sha256sum', '-c', '/opt/erasuretester/httpd.sha256'],
                stdout=subprocess.PIPE, bufsize=1)
            sha_output = self._show_subprocess_percent(sha_proc, 2517)
            ok_files = len([x for x in sha_output if b' OK' in x])
            failed_files = len([x for x in sha_output if b' FAILED' in x])

            sleep(10)
            kill_pid(dumpcap_proc)
            subprocess.check_call(['chmod', '666', capture_dir + capture_file])

            measures.append({
                'ok': ok_files,
                'failed': failed_files,
                'capture': capture_file,
                'redis_initial': config[1],
                'redis_current': redis_size
            })

        return {
            'write_capture': write_capture_file,
            'measures': measures
        }
Ejemplo n.º 2
0
def _stop_wpa_supplicant(interface):
    """Stops wpa_supplicant from running on the given interface.

  Also removes the pid file and sets the interface down.

  Args:
    interface: The interface on which to stop wpa_supplicant.

  Returns:
    Whether wpa_supplicant was successfully stopped.
  """
    if not _is_wpa_supplicant_running(interface):
        utils.log('wpa_supplicant already not running.')
        return True

    pid_filename = utils.get_filename('wpa_supplicant',
                                      utils.FILENAME_KIND.pid,
                                      interface,
                                      tmp=True)
    config_filename = utils.get_filename('wpa_supplicant',
                                         utils.FILENAME_KIND.config,
                                         interface,
                                         tmp=True)
    if not utils.kill_pid('wpa_supplicant .* %s$' % config_filename,
                          pid_filename):
        return False

    try:
        subprocess.check_call(('ip', 'link', 'set', interface, 'down'))
    except subprocess.CalledProcessError:
        return False

    return True
Ejemplo n.º 3
0
 def close_audio(device_obj, pid=None):
     """结束录音"""
     succeed = False
     data = {}
     # TODO 目前手动杀进程
     cache_audio_info = cache.RECORDING_DEVICES[device_obj.id]
     if not pid:
         pid = cache.RECORDING_DEVICES.get(device_obj.id)['pid']
     if pid:
         succeed = kill_pid(pid)
     if not succeed:
         return False, data
     device_obj.status = DeviceStatusEnum.RUNNING.value
     # TODO
     data = {
         'device_id':
         device_obj.id,
         'file_path':
         cache_audio_info['filename'],
         'duration':
         (datetime.datetime.now() - cache_audio_info['start_time']).seconds,
         'file_size':
         SgDeviceHelper.get_file_size(cache_audio_info['filename'], 'M')
     }
     return succeed, data
Ejemplo n.º 4
0
 def _stop(self):
     self._log.debug("ProcessProxy._stop", self._pid_path)
     r = False
     if os.path.exists(self._pid_path):
         pid = self._get_pid()
         os.remove(self._pid_path)
         sleep(0.5)
         r = utils.kill_pid(pid)
     try:
         if self._process:
             self._process.terminate()
     except:
         print_exc()
     self._process = None
     print('ProcessProxy: DONE STOPPING', self._pid_path)
     return r
Ejemplo n.º 5
0
def _stop_hostapd(interface):
    """Stops hostapd from running on the given interface.

  Also removes the pid file, sets them interface down and deletes the monitor
  interface, if it exists.

  Args:
    interface: The interface on which to stop hostapd.

  Returns:
    Whether hostapd was successfully stopped and cleaned up.
  """
    if not _is_hostapd_running(interface):
        utils.log('hostapd already not running.')
        return True

    config_filename = utils.get_filename('hostapd',
                                         utils.FILENAME_KIND.config,
                                         interface,
                                         tmp=True)
    pid_filename = utils.get_filename('hostapd',
                                      utils.FILENAME_KIND.pid,
                                      interface,
                                      tmp=True)
    if not utils.kill_pid('hostapd .* %s$' % config_filename, pid_filename):
        return False

    # TODO(apenwarr): hostapd doesn't always delete interface mon.$ifc.  Then it
    # gets confused by the fact that it already exists.  Let's help out.  We
    # should really fix this by eliminating the need for hostapd to have a
    # monitor interface at all (which is deprecated anyway) Remove this line when
    # our hostapd no longer needs a monitor interface.
    utils.subprocess_quiet(('iw', 'dev', 'mon.%s' % interface, 'del'))

    subprocess.check_call(('ip', 'link', 'set', interface, 'down'))

    return True
Ejemplo n.º 6
0
 def __exit__(self, exc_type, exc_val, exc_tb):
     kill_pid(self.proc)
Ejemplo n.º 7
0
 def __exit__(self, exc_type, exc_val, exc_tb):
     kill_pid(self.proc)