diff --git a/src/benchmarks/edu/brown/benchmark/voterexperiments/demohstorecorrect/PhoneCallGenerator.java b/src/benchmarks/edu/brown/benchmark/voterexperiments/demohstorecorrect/PhoneCallGenerator.java index bf830c3fe3..d12de1be6e 100644 --- a/src/benchmarks/edu/brown/benchmark/voterexperiments/demohstorecorrect/PhoneCallGenerator.java +++ b/src/benchmarks/edu/brown/benchmark/voterexperiments/demohstorecorrect/PhoneCallGenerator.java @@ -49,9 +49,9 @@ public class PhoneCallGenerator { private LinkedList callList; private ListIterator callIterator; - Socket socket; - BufferedReader in; - PrintWriter out; + private Socket socket; + private BufferedReader in; + private PrintWriter out; // Initialize some common constants and variables private static final String[] AREA_CODE_STRS = ("907,205,256,334,251,870,501,479" + @@ -190,5 +190,19 @@ public PhoneCall receive() return null; } } + + public void closeConnections() + { + try { + out.print("closing"); + out.flush(); + in.close(); + out.close(); + socket.close(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } } diff --git a/src/benchmarks/edu/brown/benchmark/voterexperiments/demohstorecorrect/VoterDemoHStoreClient.java b/src/benchmarks/edu/brown/benchmark/voterexperiments/demohstorecorrect/VoterDemoHStoreClient.java index ed4e8dfb47..b4019d5df1 100644 --- a/src/benchmarks/edu/brown/benchmark/voterexperiments/demohstorecorrect/VoterDemoHStoreClient.java +++ b/src/benchmarks/edu/brown/benchmark/voterexperiments/demohstorecorrect/VoterDemoHStoreClient.java @@ -141,6 +141,11 @@ protected boolean runOnce() throws IOException { return false; } } + + @Override + public void stopCallback() { + switchboard.closeConnections(); + } @Override public String[] getTransactionDisplayNames() { diff --git a/src/benchmarks/edu/brown/benchmark/voterexperiments/demohstorecorrect/VoterDemoHStoreConstants.java b/src/benchmarks/edu/brown/benchmark/voterexperiments/demohstorecorrect/VoterDemoHStoreConstants.java index 537cf34291..abc2484b76 100644 --- a/src/benchmarks/edu/brown/benchmark/voterexperiments/demohstorecorrect/VoterDemoHStoreConstants.java +++ b/src/benchmarks/edu/brown/benchmark/voterexperiments/demohstorecorrect/VoterDemoHStoreConstants.java @@ -45,7 +45,7 @@ public abstract class VoterDemoHStoreConstants { public static final String CONTESTANTS_FILE = "logs/hstorecontestants.txt"; public static final String VOTE_FILE = "demo/demo-votes.txt"; public static final int DELETE_CODE = -1; - public static final boolean SOCKET_CONTROL = true; + public static final boolean SOCKET_CONTROL = false; public static final String HOST_PREFIX = "istc7"; public static final String HOST_PREFIX_2 = "istc9"; diff --git a/src/benchmarks/edu/brown/benchmark/voterexperiments/demohstorecorrect/procedures/Vote.java b/src/benchmarks/edu/brown/benchmark/voterexperiments/demohstorecorrect/procedures/Vote.java index d4aab5ebf5..df584d7772 100644 --- a/src/benchmarks/edu/brown/benchmark/voterexperiments/demohstorecorrect/procedures/Vote.java +++ b/src/benchmarks/edu/brown/benchmark/voterexperiments/demohstorecorrect/procedures/Vote.java @@ -183,6 +183,7 @@ private void printResults(int numVotes) throws IOException VoltTable[] v = voltExecuteSQL(); VoterDemoHStoreUtil.writeToFile(v, tableNames, numVotes); + tableNames = new ArrayList(); voltQueueSQL(getAllRemainingContestants); tableNames.add("RemainingContestants"); @@ -190,6 +191,7 @@ private void printResults(int numVotes) throws IOException tableNames.add("RemovedContestants"); v = voltExecuteSQL(); VoterDemoHStoreUtil.writeToContestantsFile(v, tableNames, numVotes); + } diff --git a/src/benchmarks/edu/brown/benchmark/voterexperiments/demosstorecorrect/PhoneCallGenerator.java b/src/benchmarks/edu/brown/benchmark/voterexperiments/demosstorecorrect/PhoneCallGenerator.java index 54fb322774..1cca650fcf 100644 --- a/src/benchmarks/edu/brown/benchmark/voterexperiments/demosstorecorrect/PhoneCallGenerator.java +++ b/src/benchmarks/edu/brown/benchmark/voterexperiments/demosstorecorrect/PhoneCallGenerator.java @@ -49,9 +49,9 @@ public class PhoneCallGenerator { private LinkedList callList; private ListIterator callIterator; - Socket socket; - BufferedReader in; - PrintWriter out; + private Socket socket; + private BufferedReader in; + private PrintWriter out; // Initialize some common constants and variables private static final String[] AREA_CODE_STRS = ("907,205,256,334,251,870,501,479" + @@ -191,5 +191,19 @@ public PhoneCall receive() return null; } } + + public void closeConnections() + { + try { + out.print("closing"); + out.flush(); + in.close(); + out.close(); + socket.close(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } } diff --git a/src/benchmarks/edu/brown/benchmark/voterexperiments/demosstorecorrect/VoterDemoSStoreClient.java b/src/benchmarks/edu/brown/benchmark/voterexperiments/demosstorecorrect/VoterDemoSStoreClient.java index 51b31a386f..21df45f3bb 100644 --- a/src/benchmarks/edu/brown/benchmark/voterexperiments/demosstorecorrect/VoterDemoSStoreClient.java +++ b/src/benchmarks/edu/brown/benchmark/voterexperiments/demosstorecorrect/VoterDemoSStoreClient.java @@ -127,6 +127,11 @@ protected boolean runOnce() throws IOException { return response; } + + @Override + public void stopCallback() { + switchboard.closeConnections(); + } @Override public String[] getTransactionDisplayNames() { diff --git a/src/benchmarks/edu/brown/benchmark/voterexperiments/demosstorecorrect/VoterDemoSStoreConstants.java b/src/benchmarks/edu/brown/benchmark/voterexperiments/demosstorecorrect/VoterDemoSStoreConstants.java index f0aaa8e9a7..cbbbc9f993 100644 --- a/src/benchmarks/edu/brown/benchmark/voterexperiments/demosstorecorrect/VoterDemoSStoreConstants.java +++ b/src/benchmarks/edu/brown/benchmark/voterexperiments/demosstorecorrect/VoterDemoSStoreConstants.java @@ -45,7 +45,7 @@ public abstract class VoterDemoSStoreConstants { public static final String CONTESTANTS_FILE = "logs/sstorecontestants.txt"; public static final String VOTE_FILE = "demo/demo-votes.txt"; public static final int DELETE_CODE = -1; - public static final boolean SOCKET_CONTROL = true; + public static final boolean SOCKET_CONTROL = false; public static final String HOST_PREFIX = "istc9"; public static final String HOST_PREFIX_2 = "istc7"; diff --git a/src/benchmarks/edu/brown/benchmark/voterexperiments/demosstorecorrect/procedures/Vote.java b/src/benchmarks/edu/brown/benchmark/voterexperiments/demosstorecorrect/procedures/Vote.java index ba359e8b9f..db04bf7153 100644 --- a/src/benchmarks/edu/brown/benchmark/voterexperiments/demosstorecorrect/procedures/Vote.java +++ b/src/benchmarks/edu/brown/benchmark/voterexperiments/demosstorecorrect/procedures/Vote.java @@ -183,6 +183,7 @@ private void printResults(int numVotes) throws IOException VoltTable[] v = voltExecuteSQL(); VoterDemoSStoreUtil.writeToFile(v, tableNames, numVotes); + tableNames = new ArrayList(); voltQueueSQL(getAllRemainingContestants); tableNames.add("RemainingContestants"); @@ -190,6 +191,7 @@ private void printResults(int numVotes) throws IOException tableNames.add("RemovedContestants"); v = voltExecuteSQL(); VoterDemoSStoreUtil.writeToContestantsFile(v, tableNames, numVotes); + } diff --git a/tools/voterdemoserver-simple.py b/tools/voterdemoserver-simple.py new file mode 100644 index 0000000000..f1baa93d1e --- /dev/null +++ b/tools/voterdemoserver-simple.py @@ -0,0 +1,114 @@ +import socket +import sys, argparse +import time +import Queue +from threading import Semaphore +from thread import * + +hready = False +sready = False + +HOST = '' +PORT = 9510 +HSTORE_PORT = 9511 +SSTORE_PORT = 9512 +FILE = "../demo/demo-votes.txt" + +h_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) +s_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) +h_lock = Semaphore(1) +s_lock = Semaphore(1) +votes = [] +s_index = 0 +h_index = 0 +waittime = 0.001 +#first_stop = True +print 'Socket created' + +try: + h_socket.bind((HOST,HSTORE_PORT)) + s_socket.bind((HOST,SSTORE_PORT)) +except: + print 'Bind failed.' + sys.exit() + +print 'Socket bind complete' + +h_socket.listen(10) +s_socket.listen(10) +print 'Socket now listening' + +def getvotes(filename): + f = open(filename, 'r') + global votes + for line in f: + votes.append(line) + f.close() + +def s_popvotes(conn, lock): + global waittime + global s_index + global votes + while True: + data = conn.recv(1024) + if data == 'closing': + print "CLOSING" + break + lock.acquire() + conn.sendall(votes[s_index]) + s_index+=1 + time.sleep(waittime) + lock.release() + s_index = 0 + conn.close() + +def h_popvotes(conn, lock): + global waittime + global h_index + global votes + while True: + data = conn.recv(1024) + if data == 'closing': + print "CLOSING" + break + lock.acquire() + conn.sendall(votes[h_index]) + h_index+=1 + time.sleep(waittime) + lock.release() + h_index = 0 + conn.close() + +def hthread(): + global h_socket + global h_lock + while True: + conn, addr = h_socket.accept() + print 'H-Store Votes connected with ' + addr[0] + ':' + str(addr[1]) + start_new_thread(h_popvotes, (conn,h_lock)) + h_socket.close() + +def sthread(): + global s_socket + global s_lock + while True: + conn, addr = s_socket.accept() + print 'S-Store Votes connected with ' + addr[0] + ':' + str(addr[1]) + start_new_thread(s_popvotes, (conn,s_lock)) + s_socket.close() + + +parser = argparse.ArgumentParser(description='Starts running the vote feeder for h-store and/or s-store.') +parser.add_argument('-w','--wait', help='wait in between sending next vote (in seconds)', type=float, default=0.001) +parser.add_argument('-f','--file', help='filename to read', default="demo-votes.txt") + +args = parser.parse_args() + +waittime = args.wait +FILE = args.file +print(FILE) +print(waittime) +getvotes(FILE) +start_new_thread(hthread, ()) +sthread() + diff --git a/tools/voterdemoserver.py b/tools/voterdemoserver.py index da829e31f7..c4277b6543 100755 --- a/tools/voterdemoserver.py +++ b/tools/voterdemoserver.py @@ -53,6 +53,9 @@ def popvotes(conn, votes, lock): global waittime while True: data = conn.recv(1024) + if data == 'closing': + print "CLOSING" + break lock.acquire() conn.sendall(votes.get()) time.sleep(waittime)