small changes to chase down why it was slow
authorbdemsky <bdemsky>
Thu, 8 Nov 2007 23:32:44 +0000 (23:32 +0000)
committerbdemsky <bdemsky>
Thu, 8 Nov 2007 23:32:44 +0000 (23:32 +0000)
Robust/src/Benchmarks/Jhttpp2/BR/Jhttpp2Task.java
Robust/src/Benchmarks/Jhttpp2/BR/MySocket.java [new file with mode: 0644]

index bd20efd40c5dbeef1dfc7ed369c1c5912422f37b..37b2f7bbb98fc6cb9b3d4b17b33eddf73efb9754 100644 (file)
@@ -5,16 +5,16 @@ task start(StartupObject s{initialstate}) {
 
 task acceptconnection(ServerSocket ss{SocketPending}) {
     tag t=new tag(connection);
-    Socket s=ss.accept(t);
+    MySocket ms=new MySocket(){}{t};
+    ss.accept(ms);
     Jhttpp2HTTPSession js=new Jhttpp2HTTPSession() {first}{t};
     Jhttpp2ClientInputStream jcis=new Jhttpp2ClientInputStream() {}{t};
 }
 
-task requestfirst(Jhttpp2HTTPSession session {first}{connection tc}, Jhttpp2ClientInputStream jcis {}{connection tc}, Socket socket {IOPending}{connection tc}) {
+task requestfirst(Jhttpp2HTTPSession session {first}{connection tc}, Jhttpp2ClientInputStream jcis {}{connection tc}, MySocket socket {IOPending}{connection tc}) {
     byte[] buf=new byte[10000];
     int length=socket.read(buf);
     String str=new String(buf, 0, length);
-    System.printString("["+str+"]\n");
     if (session.request!=null) {
        str=session.request.concat(str);
     }
@@ -32,20 +32,19 @@ task requestfirst(Jhttpp2HTTPSession session {first}{connection tc}, Jhttpp2Clie
     }
 }
 
-task request(Jhttpp2HTTPSession session {}{connection tc}, Jhttpp2ClientInputStream jcis {}{connection tc}, Socket socket {IOPending}{connection tc}, optional Request rold{!chained}{connection tc}) {
+task request(Jhttpp2HTTPSession session {!first}{connection tc}, Jhttpp2ClientInputStream jcis {}{connection tc}, MySocket socket {IOPending}{connection tc}, optional Request rold{!chained}{connection tc}) {
     byte[] buf=new byte[10000];
     int length=socket.read(buf);
-    System.printString("length="+length+"\n");
     if (session.request!=null)
        System.printString(session.request+"\n");
     if (length==0) {
+       socket.close();
        taskexit;
     } else if (length < 0 ) {
        System.printString("ERROR\n");
        taskexit;
     }
     String str=new String(buf, 0, length);
-    System.printString("["+str+"]\n");
 
     if (session.request!=null) {
        str=session.request.concat(str);
@@ -57,7 +56,6 @@ task request(Jhttpp2HTTPSession session {}{connection tc}, Jhttpp2ClientInputStr
        session.request=str;
        taskexit;
     } else {
-       System.printString("new Request\n");
        session.request=str.substring(r.length(), str.length());
        if (session.request.length()>0)
            taskexit(session{more}, rold{chained}{ct});
@@ -90,9 +88,14 @@ task sendfirst(Request r{first&&!processed}{connection tc}) {
     taskexit(r{processed});
 }
 
-task sendnext(optional Request rprev{received&&!done}{chained ct}, Request r{!processed}{chained ct}) {
+task sendnext(optional Request rprev{received&&!done}{chained ct}, Request r{!processed&&!first}{chained ct}) {
     r.parseRequest();
-    r.connect();
+    if (isavailable(rprev)&&rprev.remote_host_name!=null&&
+       rprev.remote_host_name.equals(r.remote_host_name)&&rprev.port==r.port) {
+       r.fd=rprev.fd;
+       r.nativeBindFD(r.fd);
+    } else
+       r.connect();
     r.sendRequest();
     taskexit(r{processed}, rprev{done});
 }
@@ -103,6 +106,9 @@ task recvreq(Request r{processed&&!received&&IOPending}) {
     if (length==0) {
        //Done
        taskexit(r{received});
+    } else if (length<0) {
+       r.close();
+       taskexit(r{received});
     }
     String str=new String(buf, 0, length);
     if (r.response!=null) {
@@ -131,7 +137,7 @@ task recvreq(Request r{processed&&!received&&IOPending}) {
        lastindex=nextindex;
     }
     if (bytes>0) {
-       if ((lastindex+bytes)<str.length()) {
+       if ((lastindex+bytes)<=str.length()) {
            r.response=str;
            taskexit(r{received});
        } else {
@@ -145,9 +151,8 @@ task recvreq(Request r{processed&&!received&&IOPending}) {
     }
 }
 
-task sendfirstresp(optional Request r{first && !sent && received}{connection tc}, Socket sock{}{connection tc}) {
-    if (isavailable(r)) {
-       System.printString(r.response);
+task sendfirstresp(optional Request r{first && !sent && received}{connection tc}, MySocket sock{}{connection tc}) {
+    if (isavailable(r)&&r.response!=null) {
        sock.write(r.response.getBytes());
        taskexit(r{sent});
     } else {
@@ -162,9 +167,8 @@ task sendfirstresp(optional Request r{first && !sent && received}{connection tc}
     }
 }
 
-task sendresp(optional Request rprev {sent}{chained ct}, optional Request r{!sent && received}{chained ct, connection tc}, Socket sock{}{connection tc}) {
-    if (isavailable(r)) {
-       System.printString(r.response);
+task sendresp(optional Request rprev {sent}{chained ct}, optional Request r{!sent && received && !first}{chained ct, connection tc}, MySocket sock{}{connection tc}) {
+    if (isavailable(r)&&r.response!=null) {
        sock.write(r.response.getBytes());
        taskexit(r{sent});
     } else {
diff --git a/Robust/src/Benchmarks/Jhttpp2/BR/MySocket.java b/Robust/src/Benchmarks/Jhttpp2/BR/MySocket.java
new file mode 100644 (file)
index 0000000..fad3418
--- /dev/null
@@ -0,0 +1,7 @@
+public class MySocket extends Socket {
+    flag foo;
+    public MySocket() {
+       super();
+    }
+
+}