From 9a3aa066c37f542356c62f8df9631cff9f163194 Mon Sep 17 00:00:00 2001 From: Darrell Bishop <darrell@swiftstack.com> Date: Thu, 16 Aug 2012 21:30:54 -0700 Subject: [PATCH] Add timing stats to verbose download output. When using the swift command-line tool to evaluate a Swift cluster, it can be very handy to get some insight into the download timing. This patch adds timing data to verbose output for the download command. For each downloaded file, the printed line will also contain: - The time it took to send the request and receive the header - The total time the request took (including writing the file out locally) - The average throughput of the download Change-Id: Ib4a995623af973bb1eed4fb52c8c0e5da935964d --- bin/swift | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/bin/swift b/bin/swift index 11f9553a..16f72e3d 100755 --- a/bin/swift +++ b/bin/swift @@ -24,7 +24,7 @@ from os.path import basename, dirname, getmtime, getsize, isdir, join from Queue import Empty, Queue from sys import argv, exc_info, exit, stderr, stdout from threading import current_thread, enumerate as threading_enumerate, Thread -from time import sleep +from time import sleep, time from traceback import format_exception from urllib import quote, unquote @@ -350,8 +350,10 @@ def st_download(parser, args, print_queue, error_queue): else: raise Exception("Invalid queue_arg length of %s" % len(queue_arg)) try: + start_time = time() headers, body = \ conn.get_object(container, obj, resp_chunk_size=65536) + header_receipt = time() content_type = headers.get('content-type') if 'content-length' in headers: content_length = int(headers.get('content-length')) @@ -402,11 +404,15 @@ def st_download(parser, args, print_queue, error_queue): mtime = float(headers['x-object-meta-mtime']) utime(path, (mtime, mtime)) if options.verbose: + finish_time = time() + time_str = 'headers %.3fs, total %.3fs, %.3fs MB/s' % ( + header_receipt - start_time, finish_time - start_time, + float(read_length) / (finish_time - start_time) / 1000000) if conn.attempts > 1: - print_queue.put('%s [after %d attempts' % - (path, conn.attempts)) + print_queue.put('%s [%s after %d attempts]' % + (path, time_str, conn.attempts)) else: - print_queue.put(path) + print_queue.put('%s [%s]' % (path, time_str)) except ClientException, err: if err.http_status != 404: raise