From: adash Date: Wed, 25 Feb 2009 02:37:58 +0000 (+0000) Subject: bug fix and boost socket performance for writes X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=205c00959b2d5e5c8bdeafaef3bb228ab77452b6;p=IRC.git bug fix and boost socket performance for writes --- diff --git a/Robust/src/Benchmarks/Distributed/LookUpService/java/LookUpClient.java b/Robust/src/Benchmarks/Distributed/LookUpService/java/LookUpClient.java index b2a33034..df331840 100644 --- a/Robust/src/Benchmarks/Distributed/LookUpService/java/LookUpClient.java +++ b/Robust/src/Benchmarks/Distributed/LookUpService/java/LookUpClient.java @@ -48,7 +48,7 @@ public class LookUpClient { } else { operation = 2;//update hashmap } - lc.doLookUp(operation, sock, key); + lc.doLookUp(operation, sock, rwkey); } } /** Special character to terminate computation **/ @@ -59,21 +59,34 @@ public class LookUpClient { /** * Call to do a read/ write on socket **/ - public void doLookUp(int operation, Socket sock, Integer key){ + public void doLookUp(int operation, Socket sock, int key){ String op; if (operation == 1) { - op = new String("r"); - sock.write(op.getBytes()); - sock.write(key.intToByteArray()); + sock.write(fillBytes(operation, key)); byte b[] = new byte[4]; int numbytes = sock.read(b); } else { - op = new String("w"); - sock.write(op.getBytes()); - sock.write(key.intToByteArray()); + sock.write(fillBytes(operation, key)); } } + /* + * Convert int to a byte array + **/ + byte[] fillBytes(int operation, int key) { + byte[] b = new byte[5]; + if(operation == 1) { + b[0] = (byte)'r'; + } else { + b[0] = (byte)'w'; + } + for(int i = 1; i < 5; i++){ + int offset = (3-(i-1)) * 8; + b[i] = (byte) ((key >> offset) & 0xFF); + } + return b; + } + /** * Parse the command line options. **/ diff --git a/Robust/src/Benchmarks/Distributed/LookUpService/java/LookUpServerExample.java b/Robust/src/Benchmarks/Distributed/LookUpService/java/LookUpServerExample.java index 8fb9f549..6152f45c 100644 --- a/Robust/src/Benchmarks/Distributed/LookUpService/java/LookUpServerExample.java +++ b/Robust/src/Benchmarks/Distributed/LookUpService/java/LookUpServerExample.java @@ -15,7 +15,6 @@ public class LookUpServerExample { public LookUpServerExample(int nobjs, int nthreads) { this.nobjs = nobjs; this.nthreads = nthreads; - System.println("nobjs = "+nobjs+" nthreads= "+nthreads); } public static int main(String args[]) { @@ -39,7 +38,6 @@ public class LookUpServerExample { public static void acceptConnection(ServerSocket ss, HashMap hmap, int nthreads) { LookUpServerThread[] lus = new LookUpServerThread[nthreads]; - System.println("Here"); for(int i=0; i