Skip to content

Commit

Permalink
Log exceptions and requests to per-thread logs instead of stderr
Browse files Browse the repository at this point in the history
  • Loading branch information
anirudhSK committed Sep 5, 2013
1 parent 09acd68 commit 9a5d359
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions workloads/on-off.py
Expand Up @@ -5,26 +5,33 @@
from time import sleep
import random
import thread
from httplib import BadStatusLine

# Fetch one flow's worth of bytes
def issue_next_get(flow_size, conn, is_persistent):
def issue_next_get(flow_size, conn, is_persistent, thread_fh):
time_before_get = time()
if (is_persistent):
conn.request("GET", "/randomhuge", '', {'Range' : 'bytes=0'+'-'+str(flow_size - 1)})
else :
conn.request("GET", "/randomhuge", '', {'Range' : 'bytes=0'+'-'+str(flow_size - 1), 'Connection' : 'Close'})

time_after_get = time()
print >> sys.stderr, "request string\nGET /randomhuge\nRange : bytes=0"+"-"+str(flow_size - 1);
resp = conn.getresponse()
resp.read()
print >> thread_fh, "request string\nGET /randomhuge\nRange : bytes=0" + "-" + str(flow_size - 1);
thread_fh.flush()
resp=''
try:
resp = conn.getresponse()
resp.read()
except BadStatusLine as e:
print >> thread_fh, e.line, e.args
thread_fh.flush()
time_to_response = time()
syn_fct = int(1000*(time_to_response-time_before_get))
get_fct = int(1000*(time_to_response-time_after_get))
return (syn_fct, get_fct)

# Simulate an ON/OFF source
def on_off_source(thread_name, url, duration, persistent_str, conns, time_start):
def on_off_source(thread_name, url, duration, persistent_str, conns, time_start, thread_fh):
print thread_name
# Initialization
current_time = time() - time_start;
Expand All @@ -49,7 +56,7 @@ def on_off_source(thread_name, url, duration, persistent_str, conns, time_start)
flow_size = int(1e9);

# Retrieve flow
(syn_fct, get_fct) = issue_next_get(flow_size, conns[thread_name], is_persistent)
(syn_fct, get_fct) = issue_next_get(flow_size, conns[thread_name], is_persistent, thread_fh)

# print stats
print thread_name," Flow #", counter," size: ", flow_size," bytes syn_fct: ", syn_fct," get_fct: ", get_fct
Expand Down Expand Up @@ -82,6 +89,7 @@ def on_off_source(thread_name, url, duration, persistent_str, conns, time_start)
conns = dict()
print "Initializing random seed", random_seed
random.seed(random_seed)
for i in range(0, nsrc):
thread.start_new_thread(on_off_source, ("Thread-"+str(i), url, duration, persistent_str, conns, time_start))
for i in range(0, nsrc):
thread_fh = open("/tmp/" + str(i) + ".threadlog", "w");
thread.start_new_thread(on_off_source, ("Thread-"+str(i), url, duration, persistent_str, conns, time_start, thread_fh))
sleep(duration + 1)

0 comments on commit 9a5d359

Please sign in to comment.