Example #1
0
 def download(self):
     total_downloaded = 0
     connections = [
         self.connect(self.host) for i in range(self.runs)
     ]
     total_start_time = time()
     for current_file in SpeedTest.DOWNLOAD_FILES:
         threads = []
         for run in range(self.runs):
             thread = Thread(
                 target=self.downloadthread,
                 args=(connections[run],
                       '%s?x=%d' % (current_file, int(time() * 1000))))
             thread.run_number = run + 1
             thread.start()
             threads.append(thread)
         for thread in threads:
             thread.join()
             total_downloaded += thread.downloaded
             LOG.debug('Run %d for %s finished',
                       thread.run_number, current_file)
     total_ms = (time() - total_start_time) * 1000
     for connection in connections:
         connection.close()
     LOG.info('Took %d ms to download %d bytes',
              total_ms, total_downloaded)
     return total_downloaded * 8000 / total_ms
    def upload(self):
        connections = [self.connect(self.host) for i in range(self.runs)]

        post_data = [
            urlencode({'content0': content(s)}) for s in SpeedTest.UPLOAD_FILES
        ]

        total_uploaded = 0
        total_start_time = time()
        for data in post_data:
            threads = []
            for run in range(self.runs):
                thread = Thread(target=self.uploadthread,
                                args=(connections[run], data))
                thread.run_number = run + 1
                thread.start()
                threads.append(thread)
            for thread in threads:
                thread.join()
                LOG.debug('Run %d for %d bytes finished', thread.run_number,
                          thread.uploaded)
                total_uploaded += thread.uploaded
        total_ms = (time() - total_start_time) * 1000
        for connection in connections:
            connection.close()
        LOG.info('Took %d ms to upload %d bytes', total_ms, total_uploaded)
        return total_uploaded * 8000 / total_ms
Example #3
0
    def upload(self):
        connections = [
            self.connect(self.host) for i in range(self.runs)
        ]

        post_data = [
            urlencode({'content0': content(s)}) for s in SpeedTest.UPLOAD_FILES
        ]

        total_uploaded = 0
        total_start_time = time()
        for data in post_data:
            threads = []
            for run in range(self.runs):
                thread = Thread(target=self.uploadthread,
                                args=(connections[run], data))
                thread.run_number = run + 1
                thread.start()
                threads.append(thread)
            for thread in threads:
                thread.join()
                LOG.debug('Run %d for %d bytes finished',
                          thread.run_number, thread.uploaded)
                total_uploaded += thread.uploaded
        total_ms = (time() - total_start_time) * 1000
        for connection in connections:
            connection.close()
        LOG.info('Took %d ms to upload %d bytes',
                 total_ms, total_uploaded)
        return total_uploaded * 8000 / total_ms
Example #4
0
 def download(self):
     total_downloaded = 0
     connections = [
         self.connect(self.host) for i in range(self.runs)
     ]
     total_start_time = time()
     for current_file in SpeedTest.DOWNLOAD_FILES:
         threads = []
         for run in range(self.runs):
             thread = Thread(
                 target=self.downloadthread,
                 args=(connections[run],
                       '%s?x=%d' % (current_file, int(time() * 1000))))
             thread.run_number = run + 1
             thread.start()
             threads.append(thread)
         for thread in threads:
             thread.join()
             total_downloaded += thread.downloaded
             LOG.debug('Run %d for %s finished',
                       thread.run_number, current_file)
     total_ms = (time() - total_start_time) * 1000
     for connection in connections:
         connection.close()
     LOG.info('Took %d ms to download %d bytes',
              total_ms, total_downloaded)
     return total_downloaded * 8000 / total_ms
Example #5
0
def download(exclude=[]):
    total_downloaded = 0
    connections = []
    for run in range(RUNS):
        connection = httplib.HTTPConnection(HOST)
        connection.set_debuglevel(HTTPDEBUG)
        connection.connect()
        connections.append(connection)
    total_start_time = time()
    for current_file in [x for x in DOWNLOAD_FILES if x not in exclude]:
        threads = []
        for run in range(RUNS):
            thread = Thread(target=downloadthread,
                            args=(connections[run], current_file))
            thread.run_number = run
            thread.start()
            threads.append(thread)
        for thread in threads:
            thread.join()
            total_downloaded += thread.downloaded
            printv('Run %d for %s finished' %
                   (thread.run_number, current_file))
    total_ms = (time() - total_start_time) * 1000
    for connection in connections:
        connection.close()
    printv('Took %d ms to download %d bytes' % (total_ms, total_downloaded))
    return (total_downloaded * 8000 / total_ms)
 def download(self, urls=None):
     total_downloaded = 0
     if urls is None:
         connections = [self.connect(self.host) for i in range(self.runs)]
     else:
         connections = [self.connect(h['host']) for h in urls]
     total_start_time = time()
     for current_file in self.DOWNLOAD_FILES:
         threads = []
         for run in range(self.runs):
             thread = Thread(
                 target=self.downloadthread,
                 args=(connections[run],
                       '%s?x=%d' % (current_file, int(time() * 1000))
                       if urls is None else urls[run]['url']))
             thread.run_number = run + 1
             thread.start()
             threads.append(thread)
         for thread in threads:
             try:
                 thread.join()
                 total_downloaded += thread.downloaded
                 util.debug('[SC] Run %d for %s finished' %
                            (thread.run_number, current_file))
             except:
                 pass
     total_ms = (time() - total_start_time) * 1000
     for connection in connections:
         connection.close()
     util.info('[SC] Took %d ms to download %d bytes' % (total_ms,
                                                         total_downloaded))
     return total_downloaded * 8000 / total_ms
Example #7
0
	def download(self):
		try:
			if self._host is None:
				self._host = self.chooseserver()
		
			total_downloaded = 0
			connections = []
			for run in range(self._runs):
				connection = httplib.HTTPConnection(self._host)
				connection.set_debuglevel(self._httpdebug)
				connection.connect()
				connections.append(connection)
			total_start_time = time()
			for current_file in self._download_files:
				threads = []
				for run in range(self._runs):
					thread = Thread(target = self._downloadthread, args = (connections[run], current_file + '?x=' + str(int(time() * 1000))))
					thread.run_number = run
					thread.start()
					threads.append(thread)
				for thread in threads:
					thread.join()
					total_downloaded += thread.downloaded
					#self._printv('Run %d for %s finished' % (thread.run_number, current_file))
			total_ms = (time() - total_start_time) * 1000
			for connection in connections:
				connection.close()
			#self._printv('Took %d ms to download %d bytes' % (total_ms, total_downloaded))
			return (total_downloaded * 8000 / total_ms)
		except Exception as e:
			raise SpeedtestError(e)
Example #8
0
def upload():
    connections = []
    for run in range(RUNS):
        connection = httplib.HTTPConnection(HOST)
        connection.set_debuglevel(HTTPDEBUG)
        connection.connect()
        connections.append(connection)

    post_data = []
    ALPHABET = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
    for current_file_size in UPLOAD_FILES:
        values = {'content': ''.join(random.choice(ALPHABET)
                                     for i in range(current_file_size))}
        post_data.append(urllib.urlencode(values))

    total_uploaded = 0
    total_start_time = time()
    for data in post_data:
        threads = []
        for run in range(RUNS):
            thread = Thread(target=uploadthread, args=(connections[run], data))
            thread.run_number = run
            thread.start()
            threads.append(thread)
        for thread in threads:
            thread.join()
            printv('Run %d for %d bytes finished' %
                   (thread.run_number, thread.uploaded))
            total_uploaded += thread.uploaded
    total_ms = (time() - total_start_time) * 1000
    for connection in connections:
        connection.close()
    printv('Took %d ms to upload %d bytes' % (total_ms, total_uploaded))
    return (total_uploaded * 8000 / total_ms)
Example #9
0
    def upload(self):
        """ Perform multiple uploads in threads."""
        connections = []
        for run in range(self.runs):
            connections.append(self.connect(self.host))

        post_data = []
        for current_file_size in SpeedTest.UPLOAD_FILES:
            values = {
                'content0': ''.join(
                    random.choice(SpeedTest.ALPHABET) for i in range(current_file_size))
            }
            post_data.append(urlencode(values))

        total_uploaded = 0
        total_start_time = time()
        for data in post_data:
            threads = []
            for run in range(self.runs):
                thread = Thread(target=self.uploadthread,
                                args=(connections[run], data))
                thread.run_number = run + 1
                thread.start()
                threads.append(thread)
            for thread in threads:
                thread.join()
                logging.info('Run %d for %d bytes finished',
                             thread.run_number, thread.uploaded)
                total_uploaded += thread.uploaded
        total_ms = (time() - total_start_time) * 1000
        for connection in connections:
            connection.close()
        logging.info('Took %d ms to upload %d bytes',
                     total_ms, total_uploaded)
        return total_uploaded * 8000 / total_ms
Example #10
0
def download(exclude=[]):
    total_downloaded = 0
    connections = []
    for run in range(RUNS):
        connection = httplib.HTTPConnection(HOST)
        connection.set_debuglevel(HTTPDEBUG)
        connection.connect()
        connections.append(connection)
    total_start_time = time()
    for current_file in [x for x in DOWNLOAD_FILES if x not in exclude]:
        threads = []
        for run in range(RUNS):
            thread = Thread(target=downloadthread,
                            args=(connections[run], current_file))
            thread.run_number = run
            thread.start()
            threads.append(thread)
        for thread in threads:
            thread.join()
            total_downloaded += thread.downloaded
            printv('Run %d for %s finished' %
                   (thread.run_number, current_file))
    total_ms = (time() - total_start_time) * 1000
    for connection in connections:
        connection.close()
    printv('Took %d ms to download %d bytes' % (total_ms, total_downloaded))
    return (total_downloaded * 8000 / total_ms)
 def download(self, urls=None):
     total_downloaded = 0
     if urls is None:
         connections = [self.connect(self.host) for i in range(self.runs)]
     else:
         connections = [self.connect(h['host']) for h in urls]
     total_start_time = time()
     for current_file in self.DOWNLOAD_FILES:
         threads = []
         for run in range(self.runs):
             thread = Thread(target=self.downloadthread,
                             args=(connections[run], '%s?x=%d' %
                                   (current_file, int(time() * 1000))
                                   if urls is None else urls[run]['url']))
             thread.run_number = run + 1
             thread.start()
             threads.append(thread)
         for thread in threads:
             try:
                 thread.join()
                 total_downloaded += thread.downloaded
                 util.debug('[SC] Run %d for %s finished' %
                            (thread.run_number, current_file))
             except:
                 pass
     total_ms = (time() - total_start_time) * 1000
     for connection in connections:
         connection.close()
     util.info('[SC] Took %d ms to download %d bytes' %
               (total_ms, total_downloaded))
     return total_downloaded * 8000 / total_ms
Example #12
0
	def upload(self):
		try:
			if self._host is None:
				raise SpeedtestError('Host not set.')
			
			connections = []
			for run in range(self._runs):
				connection = httplib.HTTPConnection(self._host)
				connection.set_debuglevel(self._httpdebug)
				connection.connect()
				connections.append(connection)
				
			post_data = []
			ALPHABET = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
			for current_file_size in self._upload_files:
				values = {'content0' : ''.join(random.choice(ALPHABET) for i in range(current_file_size)) }
				post_data.append(urllib.urlencode(values))
				
			total_uploaded = 0
			total_start_time = time()
			for data in post_data:
				threads = []
				for run in range(self._runs):
					thread = Thread(target = self._uploadthread, args = (connections[run], data))
					thread.run_number = run
					thread.start()
					threads.append(thread)
				for thread in threads:
					thread.join()
					#self._printv('Run %d for %d bytes finished' % (thread.run_number, thread.uploaded))
					total_uploaded += thread.uploaded
			total_ms = (time() - total_start_time) * 1000
			for connection in connections:
				connection.close()
			#self._printv('Took %d ms to upload %d bytes' % (total_ms, total_uploaded))
			return (total_uploaded * 8000 / total_ms)
		except Exception as e:
			raise SpeedtestError(e)
Example #13
0
def upload():
    connections = []
    for run in range(RUNS):
        connection = httplib.HTTPConnection(HOST)
        connection.set_debuglevel(HTTPDEBUG)
        connection.connect()
        connections.append(connection)

    post_data = []
    ALPHABET = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
    for current_file_size in UPLOAD_FILES:
        values = {
            'content':
            ''.join(random.choice(ALPHABET) for i in range(current_file_size))
        }
        post_data.append(urllib.urlencode(values))

    total_uploaded = 0
    total_start_time = time()
    for data in post_data:
        threads = []
        for run in range(RUNS):
            thread = Thread(target=uploadthread, args=(connections[run], data))
            thread.run_number = run
            thread.start()
            threads.append(thread)
        for thread in threads:
            thread.join()
            printv('Run %d for %d bytes finished' %
                   (thread.run_number, thread.uploaded))
            total_uploaded += thread.uploaded
    total_ms = (time() - total_start_time) * 1000
    for connection in connections:
        connection.close()
    printv('Took %d ms to upload %d bytes' % (total_ms, total_uploaded))
    return (total_uploaded * 8000 / total_ms)