You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by ak...@apache.org on 2010/06/14 18:07:16 UTC

svn commit: r954533 - in /trafficserver/traffic/branches/UserFiber/samples: Makefile UFHTTPLoader.C UFSleepTest.C UFTestConnPool.C echoServer.C httpProxy.C testConf.C testProducer.C testSignal.C ufTestHTTPServer.C ufTestHTTPServerPC.C

Author: akundu
Date: Mon Jun 14 16:07:15 2010
New Revision: 954533

URL: http://svn.apache.org/viewvc?rev=954533&view=rev
Log:
- Raghav's test of conf (testConf.C)
- Anirban's test http proxy ufTestHTTPServer.C (using conn. pool)
- Anirban's test http proxy using producer/consumer (using conn. pool)

Added:
    trafficserver/traffic/branches/UserFiber/samples/UFSleepTest.C
    trafficserver/traffic/branches/UserFiber/samples/UFTestConnPool.C
    trafficserver/traffic/branches/UserFiber/samples/httpProxy.C
    trafficserver/traffic/branches/UserFiber/samples/testConf.C
    trafficserver/traffic/branches/UserFiber/samples/ufTestHTTPServer.C
    trafficserver/traffic/branches/UserFiber/samples/ufTestHTTPServerPC.C
Modified:
    trafficserver/traffic/branches/UserFiber/samples/Makefile
    trafficserver/traffic/branches/UserFiber/samples/UFHTTPLoader.C
    trafficserver/traffic/branches/UserFiber/samples/echoServer.C
    trafficserver/traffic/branches/UserFiber/samples/testProducer.C
    trafficserver/traffic/branches/UserFiber/samples/testSignal.C

Modified: trafficserver/traffic/branches/UserFiber/samples/Makefile
URL: http://svn.apache.org/viewvc/trafficserver/traffic/branches/UserFiber/samples/Makefile?rev=954533&r1=954532&r2=954533&view=diff
==============================================================================
--- trafficserver/traffic/branches/UserFiber/samples/Makefile (original)
+++ trafficserver/traffic/branches/UserFiber/samples/Makefile Mon Jun 14 16:07:15 2010
@@ -1,12 +1,18 @@
 CPP=c++
-#BUILD_FLAGS=-g -O3 -Wall -Werror -DPIPE_NOT_EFD -Wno-deprecated
+BUILD_FLAGS=-g -O3 -Wall -Werror -DPIPE_NOT_EFD -Wno-deprecated
 #BUILD_FLAGS=-g -Wall -Werror -Wno-deprecated -fno-inline
-BUILD_FLAGS=-g -Wall -Werror -Wno-deprecated
+#BUILD_FLAGS=-g -Wall -Werror -Wno-deprecated 
 ARCH=x86-64
 INCLUDE=-I../core/include
+ARESDIR=../core/ext
+ARES_VERSION = 1.7.1
+ARES = c-ares-$(ARES_VERSION)
+ARES_INCLUDE = -I$(ARESDIR)/$(ARES)
+#ARES_LIB = $(ARESDIR)/$(ARES)/.libs/libcares.a 
+#ARES_LIB = -L/usr/lib/ -lcares
 
-#all:	UFHTTPLoader echoServer UFSleepTest UFCondTimedWaitTest httpProxy testSignal testSleep bayeuxCP
-all:	UFHTTPLoader echoServer UFCondTimedWaitTest httpProxy testSignal testSleep
+all:	UFHTTPLoader echoServer UFSleepTest UFCondTimedWaitTest httpProxy testSignal testSleep UFTestConnPool ufTestHTTPServer testProducer ufTestHTTPServerPC testConf
+#all:	testSignal
 #all:	httpProxy UFHTTPLoader
 #all:	testProducer testSignal
 #all:	testSignal
@@ -18,11 +24,29 @@ UFHTTPLoader.o:	UFHTTPLoader.C
 UFHTTPLoader:	UFHTTPLoader.o
 	$(CPP) $(BUILD_FLAGS) -o UFHTTPLoader UFHTTPLoader.o -L../core/lib/ -lUF -lpthread -march=$(ARCH)
 
+ufTestHTTPServerPC.o:	ufTestHTTPServerPC.C
+	$(CPP) $(BUILD_FLAGS) -c -o ufTestHTTPServerPC.o ufTestHTTPServerPC.C $(INCLUDE) -march=$(ARCH)
+
+ufTestHTTPServerPC:	ufTestHTTPServerPC.o
+	$(CPP) $(BUILD_FLAGS) -o ufTestHTTPServerPC ufTestHTTPServerPC.o -L../core/lib/ -lUF -lpthread -march=$(ARCH)
+
+ufTestHTTPServer.o:	ufTestHTTPServer.C
+	$(CPP) $(BUILD_FLAGS) -c -o ufTestHTTPServer.o ufTestHTTPServer.C $(INCLUDE) -march=$(ARCH)
+
+ufTestHTTPServer:	ufTestHTTPServer.o
+	$(CPP) $(BUILD_FLAGS) -o ufTestHTTPServer ufTestHTTPServer.o -L../core/lib/ -lUF -lpthread -march=$(ARCH)
+
+UFTestConnPool.o:	UFTestConnPool.C
+	$(CPP) $(BUILD_FLAGS) -c -o UFTestConnPool.o UFTestConnPool.C $(INCLUDE) -march=$(ARCH) 
+
+UFTestConnPool:	UFTestConnPool.o
+	$(CPP) $(BUILD_FLAGS) -o UFTestConnPool UFTestConnPool.o -L../core/lib/ -lUF -lpthread -march=$(ARCH)
+
 echoServer.o:	echoServer.C
 	$(CPP) $(BUILD_FLAGS) -c -o echoServer.o echoServer.C $(INCLUDE) -march=$(ARCH)
 
 echoServer:	echoServer.o
-	$(CPP) $(BUILD_FLAGS) -o echoServer echoServer.o -L../core/lib/ -lUF -lpthread -march=$(ARCH)
+	$(CPP) $(BUILD_FLAGS) -o echoServer echoServer.o -L../core/lib/ -lUF -lpthread -march=$(ARCH) 
 
 httpProxy.o:	httpProxy.C
 	$(CPP) $(BUILD_FLAGS) -c -o httpProxy.o httpProxy.C $(INCLUDE) -march=$(ARCH)
@@ -30,17 +54,11 @@ httpProxy.o:	httpProxy.C
 httpProxy:	httpProxy.o
 	$(CPP) $(BUILD_FLAGS) -o httpProxy httpProxy.o -L../core/lib/ -lUF -lpthread -march=$(ARCH)
 
-#bayeuxCP.o:	bayeuxCP.C
-#	$(CPP) $(BUILD_FLAGS) -c -o bayeuxCP.o bayeuxCP.C $(INCLUDE) -march=$(ARCH)
-
-#bayeuxCP:	bayeuxCP.o
-#	$(CPP) $(BUILD_FLAGS) -o bayeuxCP bayeuxCP.o -L../core/lib/ -lUF -lpthread -march=$(ARCH)
+UFSleepTest.o:	UFSleepTest.C
+	$(CPP) $(BUILD_FLAGS) -c -o UFSleepTest.o UFSleepTest.C $(INCLUDE) -march=$(ARCH)
 
-#UFSleepTest.o:	UFSleepTest.C
-#	$(CPP) $(BUILD_FLAGS) -c -o UFSleepTest.o UFSleepTest.C $(INCLUDE) -march=$(ARCH)
-#
-#UFSleepTest:	UFSleepTest.o
-#	$(CPP) $(BUILD_FLAGS) -o UFSleepTest UFSleepTest.o -L../core/lib/ -lUF -lpthread -march=$(ARCH)
+UFSleepTest:	UFSleepTest.o
+	$(CPP) $(BUILD_FLAGS) -o UFSleepTest UFSleepTest.o -L../core/lib/ -lUF -lpthread -march=$(ARCH)
 
 testProducer.o:	testProducer.C
 	$(CPP) $(BUILD_FLAGS) -c -o testProducer.o testProducer.C $(INCLUDE) -march=$(ARCH)
@@ -66,5 +84,11 @@ UFCondTimedWaitTest.o:	UFCondTimedWaitTe
 UFCondTimedWaitTest:	UFCondTimedWaitTest.o
 	$(CPP) $(BUILD_FLAGS) -o UFCondTimedWaitTest UFCondTimedWaitTest.o -L../core/lib/ -lUF -lpthread -march=$(ARCH)
 
+testConf.o:	testConf.C
+	$(CPP) $(BUILD_FLAGS) -c -o testConf.o testConf.C $(INCLUDE) -march=$(ARCH)
+
+testConf:	testConf.o
+	$(CPP) $(BUILD_FLAGS) -o testConf testConf.o -L../core/lib/ -lUF -lpthread -march=$(ARCH)
+
 clean: 
-	rm *.o UFHTTPLoader
+	rm -f *.o UFHTTPLoader echoServer UFSleepTest UFCondTimedWaitTest httpProxy testSignal testSleep testConf

Modified: trafficserver/traffic/branches/UserFiber/samples/UFHTTPLoader.C
URL: http://svn.apache.org/viewvc/trafficserver/traffic/branches/UserFiber/samples/UFHTTPLoader.C?rev=954533&r1=954532&r2=954533&view=diff
==============================================================================
--- trafficserver/traffic/branches/UserFiber/samples/UFHTTPLoader.C (original)
+++ trafficserver/traffic/branches/UserFiber/samples/UFHTTPLoader.C Mon Jun 14 16:07:15 2010
@@ -1,7 +1,7 @@
 #include <stdio.h>
 #include <algorithm>
 #include <errno.h>
-#include <vector>
+#include <set>
 #include <time.h>
 #include <sstream>
 #include <iostream>
@@ -24,6 +24,8 @@
 #include "UF.H"
 #include "UFIO.H"
 #include "UFServer.H"
+#include "UFConnectionPool.H"
+#include <vector>
 
 using namespace std;
 
@@ -76,7 +78,6 @@ struct ResponseInfoObject
 ResponseInfoObject overallInfo;
 pthread_mutex_t overallInfoTrackMutex = PTHREAD_MUTEX_INITIALIZER;
 pthread_key_t threadUpdateOverallInfo;
-struct sockaddr_in rmt_addr;
 
 int GET_RESPONSE_TIMEOUT = 1*1000*1000;
 string DOUBLE_NEWLINE = "\r\n\r\n";
@@ -96,6 +97,7 @@ bool readData(UFIO* ufio, unsigned int t
         {
             if(okToExitToEnd && (num_bytes_read == 0))
             {
+                cerr<<"okToExitToEnd = "<<okToExitToEnd<<endl;
                 connClosed = true;
                 return true;
             }
@@ -163,18 +165,18 @@ bool writeData(UFIO* ufio, const string&
     return ((amt_written == (int)data.length()) ? true : false);
 }
 
+string remote_addr = "";
 int sockBuf = 0;
 UFIO* getConn(ResponseInfoObject* rIO)
 {
-    //create the socket to build the connection on
-    //UFIO* ufio = new UFIO(UFScheduler::getUFScheduler()->getRunningFiberOnThisThread());
-    UFIO* ufio = new UFIO(UFScheduler::getUFScheduler()->getUF());//getRunningFiberOnThisThread());
-    if(!ufio)
+    UFConnectionPool* cpool = UFIOScheduler::getUFIOS()->getConnPool();
+    if(!cpool)
         return 0;
 
     struct timeval start,finish;
     gettimeofday(&start, 0);
-    if(ufio->connect((struct sockaddr*)&rmt_addr, sizeof(rmt_addr), CONNECT_AND_REQUEST_TIMEOUT) != 0)
+    UFIO* ufio = cpool->getConnection(remote_addr);
+    if(!ufio)
     {
         if(random()%100 < 10)
             cerr<<"connect error: "<<strerror(errno)<<endl;
@@ -275,7 +277,7 @@ void run_handler()
 
         if(connClosed)
         {
-            delete ufio;
+            UFIOScheduler::getUFIOS()->getConnPool()->releaseConnection(ufio, false);
             ufio = getConn(rIO);
             if(!ufio)
                 return;
@@ -283,53 +285,10 @@ void run_handler()
     }
 
 run_handler_done:
-    delete ufio;
+    UFIOScheduler::getUFIOS()->getConnPool()->releaseConnection(ufio, false);
 }
 
 
-
-void read_address(const char *str, struct sockaddr_in *sin)
-{
-    char host[128], *p;
-    struct hostent *hp;
-    short port;
-
-    strcpy(host, str);
-    if ((p = strchr(host, ':')) == NULL)
-    {
-        cerr<<"invalid host: "<<host<<endl;
-        exit(1);
-    }
-    *p++ = '\0';
-    port = (short) atoi(p);
-    if (port < 1)
-    {
-
-        cerr<<"invalid port: "<<port<<endl;
-        exit(1);
-    }
-
-    memset(sin, 0, sizeof(struct sockaddr_in));
-    sin->sin_family = AF_INET;
-    sin->sin_port = htons(port);
-    if (host[0] == '\0')
-    {
-        sin->sin_addr.s_addr = INADDR_ANY;
-        return;
-    }
-    sin->sin_addr.s_addr = inet_addr(host);
-    if (sin->sin_addr.s_addr == INADDR_NONE)
-    {
-        /* not dotted-decimal */
-        if ((hp = gethostbyname(host)) == NULL)
-        {
-            cerr<<"cant resolve address "<<host<<endl;
-            exit(1);
-        }
-        memcpy(&sin->sin_addr, hp->h_addr, hp->h_length);
-    }
-}
-
 struct ClientUF : public UF
 {
     void run();
@@ -481,8 +440,8 @@ void SetupClientUF::run()
     overallInfo.write_error += rIO.write_error;
     overallInfo.read_error += rIO.read_error;
     overallInfo.num_user_fibers_running += rIO.num_user_fibers_running;
-    for(unsigned int i =0; i < rIO.results.size(); ++i)
-        overallInfo.results.push_back(rIO.results[i]);
+    for(vector<unsigned long long int>::iterator beg = rIO.results.begin(); beg != rIO.results.end(); ++beg)
+        overallInfo.results.push_back(*beg);
     pthread_mutex_unlock(&overallInfoTrackMutex);
 
 
@@ -548,7 +507,6 @@ void printResults()
     cout<<"max = "<<lastValue<<"us"<<endl;
 }
 
-string remote_addr = "";
 void print_info()
 {
     cerr<<"connecting to               = "<<remote_addr<<endl;
@@ -684,14 +642,6 @@ int main(int argc, char** argv)
     remote_addr = rem_addr + ":" + rem_port;
     print_info();
 
-    read_address(remote_addr.c_str(), &rmt_addr);
-    if (rmt_addr.sin_addr.s_addr == INADDR_ANY)
-    {
-        cerr<<"invalid remote address: "<<remote_addr<<endl;
-        exit(1);
-    }
-
-
 
     //create the threads
     pthread_t* thread = new pthread_t[NUM_THREADS];
@@ -710,5 +660,6 @@ int main(int argc, char** argv)
         pthread_join(thread[i], &status);
     delete [] thread;
 
+
     printResults();
 }

Added: trafficserver/traffic/branches/UserFiber/samples/UFSleepTest.C
URL: http://svn.apache.org/viewvc/trafficserver/traffic/branches/UserFiber/samples/UFSleepTest.C?rev=954533&view=auto
==============================================================================
--- trafficserver/traffic/branches/UserFiber/samples/UFSleepTest.C (added)
+++ trafficserver/traffic/branches/UserFiber/samples/UFSleepTest.C Mon Jun 14 16:07:15 2010
@@ -0,0 +1,49 @@
+#include "UF.H"
+#include <sys/time.h>
+#include <stdlib.h>
+#include <iostream>
+
+using namespace std;
+
+unsigned int amtToSleep = 1000000;
+unsigned int numTimes = 10;
+struct UFSleepTest : public UF
+{
+    UF* createUF() { return new UFSleepTest(); }
+
+    void run()
+    {
+        timeval now;
+        gettimeofday(&now,NULL);
+
+        unsigned long long int timeNow = now.tv_sec*1000000+now.tv_usec;
+        unsigned int counter = 0;
+
+        while(counter++ < numTimes)
+        {
+            usleep(amtToSleep);
+            timeNow += amtToSleep;
+            cerr<<"current time = "<<timeNow<<endl;
+        }
+
+        _parentScheduler->setExitJustMe(true);
+    }
+};
+
+int main(int argc, char** argv)
+{
+    if(argc > 1)
+        numTimes = atoi(argv[1]);
+    if(argc > 2)
+        amtToSleep = atoi(argv[2]);
+
+    pthread_t thread;
+    list<UF*>* ufList = new list<UF*>();
+    ufList->push_back(new UFSleepTest());
+    UFScheduler::ufCreateThread(&thread, ufList);
+
+    void* status;
+    pthread_join(thread, &status);
+
+    return 0;
+}

Added: trafficserver/traffic/branches/UserFiber/samples/UFTestConnPool.C
URL: http://svn.apache.org/viewvc/trafficserver/traffic/branches/UserFiber/samples/UFTestConnPool.C?rev=954533&view=auto
==============================================================================
--- trafficserver/traffic/branches/UserFiber/samples/UFTestConnPool.C (added)
+++ trafficserver/traffic/branches/UserFiber/samples/UFTestConnPool.C Mon Jun 14 16:07:15 2010
@@ -0,0 +1,66 @@
+#include <errno.h>
+#include <iostream>
+#include <string.h>
+#include "UF.H"
+#include "UFIO.H"
+#include "UFConnectionPool.H"
+
+using namespace std;
+struct TestConnPoolFetchUF : public UF
+{
+    void run();
+    UF* createUF() { return new TestConnPoolFetchUF(); }
+};
+
+string hostToGet = "127.0.0.1:80";
+unsigned int NUM_TO_GET = 10;
+void TestConnPoolFetchUF::run()
+{
+    UFConnectionPool* cpool = UFIOScheduler::getUFIOS()->getConnPool();
+    unsigned int counter = 0;
+    while(counter++ < NUM_TO_GET)
+    {
+        cerr<<"getting connection"<<endl;
+        UFIO* ufio = cpool->getConnection(hostToGet);
+        if(!ufio)
+        {
+            cerr<<"couldnt get connection "<<strerror(errno)<<endl;
+            break;
+        }
+        cerr<<"releasing connection to pool"<<endl;
+        cpool->releaseConnection(ufio, true);
+    }
+
+    UFScheduler::getUFScheduler()->setExitJustMe(true);
+}
+
+int main(int argc, char** argv)
+{
+    unsigned int numThreadsToCreate = 1;
+    unsigned int numUFsToCreate = 1;
+    if(argc > 1)
+        hostToGet = argv[1];
+    if(argc > 2)
+        numThreadsToCreate = atoi(argv[2]);
+    else if(argc > 3)
+        numUFsToCreate = atoi(argv[3]);
+
+    //create the threads
+    pthread_t* thread = new pthread_t[numThreadsToCreate];
+    unsigned int i = 0;
+    for(; i<numThreadsToCreate; i++)
+    {
+        list<UF*>* ufList = new list<UF*>();
+        for(unsigned int j = 0; j < numUFsToCreate; ++j)
+            ufList->push_back(new TestConnPoolFetchUF());
+        UFIO::ufCreateThreadWithIO(&thread[i], ufList);
+    }
+
+    //wait for kids
+    void* status;
+    for(i=0; i<numThreadsToCreate; i++)
+        pthread_join(thread[i], &status);
+    delete [] thread;
+
+    return 0;
+}

Modified: trafficserver/traffic/branches/UserFiber/samples/echoServer.C
URL: http://svn.apache.org/viewvc/trafficserver/traffic/branches/UserFiber/samples/echoServer.C?rev=954533&r1=954532&r2=954533&view=diff
==============================================================================
--- trafficserver/traffic/branches/UserFiber/samples/echoServer.C (original)
+++ trafficserver/traffic/branches/UserFiber/samples/echoServer.C Mon Jun 14 16:07:15 2010
@@ -1,11 +1,8 @@
-#include <iostream>
 #include <stdlib.h>
-
 #include "UFIO.H"
 #include "UFServer.H"
 
-using namespace std;
-
+unsigned long long int readTimeout = 0;
 struct EchoServer : public UFServer
 {
     EchoServer(char* interfaceIP, unsigned int port)
@@ -13,30 +10,21 @@ struct EchoServer : public UFServer
         _addressToBindTo = interfaceIP ? interfaceIP : "";
         _port = port;
     }
-    void handleNewConnection(UFIO* ufio);
-};
-
-unsigned long long int readTimeout = 0;
-void EchoServer::handleNewConnection(UFIO* ufio)
-{
-    if(!ufio)
+    void handleNewConnection(UFIO* ufio)
     {
-        cerr<<"couldnt create UFIO object"<<endl;
-        return;
-    }
-
-    char buf[256];
-    int amtRead = 0;
-    while ( ((amtRead = ufio->read(buf, 255, readTimeout)) > 0) && 
-            (ufio->write(buf, amtRead) == amtRead) ) {}
-}
+        if(!ufio) return;
 
+        char buf[256];
+        int amtRead = 0;
+        while ( ((amtRead = ufio->read(buf, 255, readTimeout)) > 0) && (ufio->write(buf, amtRead) == amtRead) ) {}
+    }
+};
 
 int main(int argc, char** argv)
 {
     unsigned int numThreads = 8;
-    unsigned int numProcesses = 1;
     unsigned short int port = 8080;
+    unsigned int numProcesses = 1;
     if(argc > 1)
         numThreads = atoi(argv[1]);
     if(argc > 2)
@@ -53,6 +41,5 @@ int main(int argc, char** argv)
     ufecho.UF_STACK_SIZE                = 8192;
 
     ufecho.run();
-
     return 0;
 }

Added: trafficserver/traffic/branches/UserFiber/samples/httpProxy.C
URL: http://svn.apache.org/viewvc/trafficserver/traffic/branches/UserFiber/samples/httpProxy.C?rev=954533&view=auto
==============================================================================
--- trafficserver/traffic/branches/UserFiber/samples/httpProxy.C (added)
+++ trafficserver/traffic/branches/UserFiber/samples/httpProxy.C Mon Jun 14 16:07:15 2010
@@ -0,0 +1,100 @@
+#include <iostream>
+#include <stdlib.h>
+
+#include "UFIO.H"
+#include "UFServer.H"
+#include "UFConnectionPool.H"
+using namespace std;
+
+struct HTTPProxy : public UFServer
+{
+    HTTPProxy(char* interfaceIP, unsigned int port)
+    {
+        _addressToBindTo = interfaceIP ? interfaceIP : "";
+        _port = port;
+    }
+    void handleNewConnection(UFIO* ufio);
+};
+
+bool handleIO(UFIO* input, UFIO* output, char* buf, unsigned int maxLen)
+{
+    int amtRead = 0;
+    if((amtRead = input->read(buf, maxLen)) > 0)
+    {
+        if(output->write(buf, amtRead) == amtRead)
+            return true;
+    }
+    return false;
+}
+
+string hostToConnectTo = "localhost:8888";
+unsigned long long int readTimeout = 0;
+void HTTPProxy::handleNewConnection(UFIO* ufio)
+{
+    if(!ufio)
+    {
+        cerr<<"couldnt create UFIO object"<<endl;
+        return;
+    }
+
+    UFConnectionPool* cpool = UFIOScheduler::getUFIOS()->getConnPool();
+    UFIO *sufio = cpool->getConnection(hostToConnectTo.c_str(), true);
+    if(!sufio)
+    {
+        cerr<<"didnt get connection"<<endl;
+        return;
+    }
+
+    char buf[2048];
+    list<UFIO*> ufioList;
+    ufioList.push_back(ufio);
+    ufioList.push_back(sufio);
+    list<UFIO*>::iterator beg;
+    while(1)
+    {
+        //poll to see which connection has some activity on it
+        if(!UFIOScheduler::getUFIOS()->rpoll(ufioList, readTimeout))
+        {
+            cerr<<"error in getting poll"<<endl;
+            break;
+        }
+        if(ufio->_markedActive) //client had some activity
+        {
+            if(!handleIO(ufio, sufio, buf, 2047))
+                break;
+        }
+        if(sufio->_markedActive) //client had some activity
+        {
+            if(!handleIO(sufio, ufio, buf, 2047))
+                break;
+        }
+    }
+
+    cpool->releaseConnection(sufio, false);
+}
+
+int main(int argc, char** argv)
+{
+    unsigned int numThreads = 1;
+    unsigned int numProcesses = 0;
+    unsigned short int port = 8080;
+    if(argc > 1)
+        numThreads = atoi(argv[1]);
+    if(argc > 2)
+        port = atoi(argv[2]);
+    if(argc > 3)
+        hostToConnectTo = argv[3];
+    if(argc > 4)
+        readTimeout = atoi(argv[4]);
+    if(argc > 5)
+        numProcesses = atoi(argv[5]);
+
+    HTTPProxy ufecho(0, port);
+    ufecho.MAX_ACCEPT_THREADS_ALLOWED   = 1;
+    ufecho.MAX_THREADS_ALLOWED          = numThreads;
+    ufecho.MAX_PROCESSES_ALLOWED        = numProcesses;
+
+    ufecho.run();
+
+    return 0;
+}

Added: trafficserver/traffic/branches/UserFiber/samples/testConf.C
URL: http://svn.apache.org/viewvc/trafficserver/traffic/branches/UserFiber/samples/testConf.C?rev=954533&view=auto
==============================================================================
--- trafficserver/traffic/branches/UserFiber/samples/testConf.C (added)
+++ trafficserver/traffic/branches/UserFiber/samples/testConf.C Mon Jun 14 16:07:15 2010
@@ -0,0 +1,43 @@
+#include "UFConf.H"
+#include <iostream>
+
+using std::cerr;
+using std::endl;
+
+int main(int argc, char **argv)
+{
+    if(argc < 3) 
+    {
+        cerr << "Usage : " << argv[0] << " <base-conf-file> <child-conf-file> [<conf-key>]*" << endl;
+        return 0;
+    }
+    string base_conf_file = argv[1];
+    string child_conf_file = argv[2];
+
+    // Add base conf
+    UFConfManager::addConf(base_conf_file);
+
+    // Add child conf with base_conf as parent
+    UFConfManager::addChildConf(child_conf_file, base_conf_file);
+
+    // Get base conf and child conf
+    UFConf* base_conf = UFConfManager::getConf(base_conf_file);
+    UFConf* child_conf = UFConfManager::getConf(child_conf_file);
+  
+    // Go through rest of command line and print out config value as seen through the base and child configs
+    for(int i = 3; i <argc; i++)
+    {
+        string key = argv[i];
+        ConfValueBase *base_conf_val = base_conf->get(key);
+        ConfValueBase *child_conf_val = child_conf->get(key);
+        cerr << "Key=" << key << " Base=";
+        if(base_conf_val)
+            base_conf_val->dump(cerr);
+        cerr << " Child=";
+        if(child_conf_val)
+            child_conf_val->dump(cerr);
+        cerr << endl;
+    }
+
+    return 0;
+}

Modified: trafficserver/traffic/branches/UserFiber/samples/testProducer.C
URL: http://svn.apache.org/viewvc/trafficserver/traffic/branches/UserFiber/samples/testProducer.C?rev=954533&r1=954532&r2=954533&view=diff
==============================================================================
--- trafficserver/traffic/branches/UserFiber/samples/testProducer.C (original)
+++ trafficserver/traffic/branches/UserFiber/samples/testProducer.C Mon Jun 14 16:07:15 2010
@@ -1,7 +1,7 @@
 #include <iostream>
 #include <stdlib.h>
 #include "UFPC.H"
-
+#include <stdio.h>
 
 UFProducer* p = 0;
 struct TestProducer : public UF
@@ -48,11 +48,10 @@ struct TestConsumer : public UF
                 uf->usleep(1000);
                 continue;
             }
-            UFProducerDataCode code = result->_ufpcCode;
+            int code = result->_ufpcCode;
             UFProducerData::releaseObj(result);
-            if(code == END)
+            if(code == 0 /* INDICATES AN END */)
                 break;
-            //printf("%lu cons %u\n", (unsigned long int) ((uintptr_t)(void*)uf), *((unsigned int*)result->_data));
             printf("%lu cons\n", (unsigned long int) ((uintptr_t)(void*)uf));
         }
         c->removeProducer(p);

Modified: trafficserver/traffic/branches/UserFiber/samples/testSignal.C
URL: http://svn.apache.org/viewvc/trafficserver/traffic/branches/UserFiber/samples/testSignal.C?rev=954533&r1=954532&r2=954533&view=diff
==============================================================================
--- trafficserver/traffic/branches/UserFiber/samples/testSignal.C (original)
+++ trafficserver/traffic/branches/UserFiber/samples/testSignal.C Mon Jun 14 16:07:15 2010
@@ -19,7 +19,7 @@ struct TestProducer : public UF
             mut->broadcast();
             mut->unlock(uf);
             printf("%lu add\n", (unsigned long int) ((uintptr_t)(void*)uf));
-            uf->usleep(1000);
+            uf->usleep(10);
         }
     }
     UF* createUF() { return new TestProducer(); }
@@ -65,7 +65,7 @@ struct ConsumerWithLockOnly : public UF
             while(lastValue == value)
             {
                 mut->unlock(uf);
-                uf->usleep(100);
+                uf->usleep(10);
                 mut->lock(uf);
             }
             tmpValue = value;

Added: trafficserver/traffic/branches/UserFiber/samples/ufTestHTTPServer.C
URL: http://svn.apache.org/viewvc/trafficserver/traffic/branches/UserFiber/samples/ufTestHTTPServer.C?rev=954533&view=auto
==============================================================================
--- trafficserver/traffic/branches/UserFiber/samples/ufTestHTTPServer.C (added)
+++ trafficserver/traffic/branches/UserFiber/samples/ufTestHTTPServer.C Mon Jun 14 16:07:15 2010
@@ -0,0 +1,127 @@
+#include <iostream>
+#include <errno.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <vector>
+#include <string.h>
+
+#include "UF.H"
+#include "UFIO.H"
+#include "UFIO.H"
+#include "UFServer.H"
+#include "UFStatSystem.H"
+#include "UFConnectionPool.H"
+
+using namespace std;
+
+static uint32_t http_request;
+struct ufTestHTTPServer : public UFServer
+{
+    ufTestHTTPServer(char* interfaceIP, unsigned int port)
+    {
+        _addressToBindTo = interfaceIP ? interfaceIP : "";
+        _port = port;
+    }
+    void handleNewConnection(UFIO* ufio);
+    void preAccept() { UFStatSystem::registerStat("http_request", &http_request, false); }
+};
+
+unsigned long long int readTimeout = 0;
+string hostToConnectTo = "localhost:8888";
+void ufTestHTTPServer::handleNewConnection(UFIO* ufio)
+{
+    UFStatSystem::increment(http_request);
+    if(!ufio)
+        return;
+
+    UFConnectionPool* cpool = UFIOScheduler::getUFIOS()->getConnPool();
+    UFIO *sufio = cpool->getConnection(hostToConnectTo.c_str(), true);
+    if(!sufio)
+    {
+        cerr<<"didnt get connection to "<<hostToConnectTo<<endl;
+        return;
+    }
+
+    char buf[1024];
+    int amtRead = 0;
+    bool bail = false;
+    string readData;
+    bool releaseConn = false;
+    while(!bail)
+    {
+        //1. read from the client
+        amtRead = ufio->read(buf, 1023, readTimeout);
+        if(amtRead > 0)
+        {
+            readData.append(buf, amtRead);
+            if(readData.find("\r\n\r\n") == string::npos)
+                continue;
+
+            //2. check whether we should be closing the connection after the request is done
+            if((readData.find("Connection: close") != string::npos) ||
+               ((readData.find("HTTP/1.1") == string::npos) && (readData.find("Connection: Keep-Alive") == string::npos)))
+                bail = true;
+
+            //3. write to the OS
+            if(sufio->write(readData.data(), readData.length()) != (int)readData.length())
+                break;
+            readData.clear();
+
+            //4. read from the OS
+            string dataReadFromOS;
+            while(1)
+            {
+                amtRead = sufio->read(buf, 1023, readTimeout);
+                if(amtRead <= 0)
+                {
+                    bail = true;
+                    break;
+                }
+
+                dataReadFromOS.append(buf, amtRead);
+                if(dataReadFromOS.find("END") == string::npos)
+                    continue;
+                break; //found the end string
+            }
+
+            //5. write to the client what we've read from the OS
+            if(ufio->write(dataReadFromOS.data(), dataReadFromOS.length()) != (int)dataReadFromOS.length())
+                break;
+        }
+        else if(amtRead <= 0)
+        {
+            releaseConn = true;
+            break;
+        }
+    }
+
+    cpool->releaseConnection(sufio, releaseConn);
+}
+
+
+int main(int argc, char** argv)
+{
+    unsigned int numThreads = 8;
+    unsigned int numProcesses = 1;
+    unsigned short int port = 8080;
+    if(argc > 1)
+        numThreads = atoi(argv[1]);
+    if(argc > 2)
+        port = atoi(argv[2]);
+    if(argc > 3)
+        hostToConnectTo = argv[3];
+    if(argc > 4)
+        readTimeout = atoi(argv[4]);
+    if(argc > 5)
+        numProcesses = atoi(argv[5]);
+
+    ufTestHTTPServer ufhttp(0, port);
+    ufhttp.MAX_ACCEPT_THREADS_ALLOWED   = 1;
+    ufhttp.MAX_THREADS_ALLOWED          = numThreads;
+    ufhttp.MAX_PROCESSES_ALLOWED        = numProcesses;
+    ufhttp.UF_STACK_SIZE                = 8192;
+
+    ufhttp.run();
+
+    return 0;
+}

Added: trafficserver/traffic/branches/UserFiber/samples/ufTestHTTPServerPC.C
URL: http://svn.apache.org/viewvc/trafficserver/traffic/branches/UserFiber/samples/ufTestHTTPServerPC.C?rev=954533&view=auto
==============================================================================
--- trafficserver/traffic/branches/UserFiber/samples/ufTestHTTPServerPC.C (added)
+++ trafficserver/traffic/branches/UserFiber/samples/ufTestHTTPServerPC.C Mon Jun 14 16:07:15 2010
@@ -0,0 +1,299 @@
+#include <iostream>
+#include <errno.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <vector>
+#include <string.h>
+
+#include "UF.H"
+#include "UFIO.H"
+#include "UFIO.H"
+#include "UFServer.H"
+#include "UFStatSystem.H"
+#include "UFConnectionPool.H"
+#include "UFPC.H"
+
+using namespace std;
+bool runOS = true;
+
+static uint32_t http_request;
+struct ufTestHTTPServer : public UFServer
+{
+    ufTestHTTPServer(char* interfaceIP, unsigned int port)
+    {
+        _addressToBindTo = interfaceIP ? interfaceIP : "";
+        _port = port;
+    }
+    void handleNewConnection(UFIO* ufio);
+    void preAccept() { UFStatSystem::registerStat("http_request", &http_request, false); }
+};
+
+
+struct OSProducer : public UF
+{
+    OSProducer(const std::string& hostToConnect, const std::string& request)
+    {
+        _p = new UFProducer();
+        _p->_requireLockToUpdateConsumers = false;
+        _hostToConnect = hostToConnect;
+        _request = request;
+        _bailProducer = 0;
+    }
+    ~OSProducer() { }
+
+    void runAsOS();
+    void runAsStaticCache();
+
+    static std::string data;
+
+    void run()
+    {
+        if(runOS)
+            runAsOS();
+        else
+            runAsStaticCache();
+    }
+
+    UF* createUF() { return new OSProducer(); }
+    UFProducer* getProducer() const { return _p; }
+    unsigned short int    _bailProducer;
+
+protected:
+    UFProducer* _p;
+    std::string _hostToConnect;
+    std::string _request;
+    OSProducer() { _p = new UFProducer(); }
+};
+//std::string OSProducer::data = "HTTP/1.1 200 OK\r\nContent-Length: 1503\r\nAccept-Ranges: bytes\r\nConnection: Keep-Alive\r\n\r\n" + string(1500u, 'a') + "END";
+std::string OSProducer::data = "HTTP/1.1 200 OK\r\nContent-Length: 5\r\nAccept-Ranges: bytes\r\nConnection: Keep-Alive\r\n\r\nhello";
+
+unsigned long long int readTimeout = 0;
+string hostToConnectTo = "localhost:8888";
+void ufTestHTTPServer::handleNewConnection(UFIO* ufio)
+{
+    UFStatSystem::increment(http_request);
+    if(!ufio)
+        return;
+
+    UFScheduler* ufs = UFScheduler::getUFScheduler();
+    UF* uf = ufs->getRunningFiberOnThisThread();
+    char buf[1024];
+    int amtRead = 0;
+    bool bail = false;
+    string readData;
+    unsigned static int counter = 0;
+
+
+    //3. create the producer to OS
+    OSProducer* pUF = new OSProducer(hostToConnectTo, readData);
+    if(!pUF)
+        return;
+    UFConsumer* c = new UFConsumer();
+    if(!c)
+    {
+        delete pUF;
+        return;
+    }
+    c->_requireLockToWaitForUpdate = false;
+    if(!c->joinProducer(pUF->getProducer()))
+    {
+        delete pUF;
+        delete c;
+        return;
+    }
+    ufs->addFiberToScheduler(pUF);
+
+
+    while(!bail)
+    {
+        //1. read from the client
+        amtRead = ufio->read(buf, 1023, readTimeout);
+        if(amtRead > 0)
+        {
+            readData.append(buf, amtRead);
+            if(readData.find("\r\n\r\n") == string::npos)
+                continue;
+
+            /*
+            //2. check whether we should be closing the connection after the request is done
+            if((readData.find("Connection: close") != string::npos) ||
+               ((readData.find("HTTP/1.1") == string::npos) && (readData.find("Connection: Keep-Alive") == string::npos)))
+                bail = true;
+                */
+
+
+            int amtWritten = 0;
+            while(1)
+            {
+                UFProducerData* result = c->waitForData(uf);
+                if(!result)
+                {
+                    bail = true;
+                    break;
+                }
+
+                if(result->_ufpcCode == 0 /* the producer is done */)
+                {
+                    UFProducerData::releaseObj(result);
+                    break;
+                }
+                else if(result->_ufpcCode == -1 /* the producer inserted an error */)
+                {
+                    UFProducerData::releaseObj(result);
+                    bail = true;
+                    break;
+                }
+
+                //write out to the client
+                amtWritten = ufio->write((char*)result->_data, result->_size);
+                if(amtWritten != (int) result->_size)
+                {
+                    cerr<<"couldnt write out data - wrote "<<amtWritten<<" instead of "<<result->_size<<" "<<strerror(ufio->getErrno())<<endl;
+                    UFProducerData::releaseObj(result);
+                    bail = true;
+                    break;
+                }
+                UFProducerData::releaseObj(result);
+            }
+
+            pUF->_bailProducer = 2;
+            ufs->addFiberToScheduler(pUF);
+
+            readData.clear();
+            counter++;
+        }
+        else if(amtRead <= 0)
+            break;
+    }
+    delete c;
+
+    pUF->_bailProducer = 1;
+    ufs->addFiberToScheduler(pUF);
+
+    /*
+    if(counter > 300000)
+        UFScheduler::getUFScheduler()->setExit(true);
+        */
+}
+
+
+int main(int argc, char** argv)
+{
+    unsigned int numThreads = 8;
+    unsigned int numProcesses = 1;
+    unsigned short int port = 8080;
+    if(argc > 1)
+        numThreads = atoi(argv[1]);
+    if(argc > 2)
+        port = atoi(argv[2]);
+    if(argc > 3)
+        hostToConnectTo = argv[3];
+    if(argc > 4)
+        readTimeout = atoi(argv[4]);
+    if(argc > 5)
+        numProcesses = atoi(argv[5]);
+    if(argc > 6)
+        runOS = atoi(argv[6]);
+
+    ufTestHTTPServer ufhttp(0, port);
+    ufhttp.MAX_ACCEPT_THREADS_ALLOWED   = 1;
+    ufhttp.MAX_THREADS_ALLOWED          = numThreads;
+    ufhttp.MAX_PROCESSES_ALLOWED        = numProcesses;
+    ufhttp.UF_STACK_SIZE                = 8192;
+
+    ufhttp.run();
+
+    return 0;
+}
+
+void OSProducer::runAsOS()
+{
+    bool releaseConn = false;
+    UFConnectionPool* cpool = UFIOScheduler::getUFIOS()->getConnPool();
+    UFIO* sufio = 0;
+
+    bool alreadyWritten = false;
+    unsigned int amtRead = 0;
+    string dataReadFromOS;
+    while(1)
+    {
+        if(!sufio)
+        {
+            sufio = cpool->getConnection(_hostToConnect, true);
+            if(!sufio)
+            {
+                cerr<<"couldnt get connection to "<<_hostToConnect<<endl;
+                delete _p;
+                _p = 0;
+                return;
+            }
+        }
+
+        if(!alreadyWritten && sufio->write(_request.data(), _request.length()) != (int)_request.length())
+        {
+            cpool->releaseConnection(sufio, releaseConn);
+            delete _p;
+            _p = 0;
+            return;
+        }
+        alreadyWritten = true;
+
+        char* buf = (char*) malloc (1024);
+        amtRead = sufio->read(buf, 1023, 0);
+        if(amtRead == 0)
+        {
+            cpool->releaseConnection(sufio, false);
+            sufio = 0;
+            alreadyWritten = false;
+            continue;
+        }
+        if(amtRead <= 0)
+        {
+            cerr<<"error on read "<<strerror(errno)<<" read "<<amtRead<<" prev read "<<dataReadFromOS.length()<<endl;
+            free(buf);
+            _p->produceData(0, 0, -1, false, this);
+            break;
+        }
+        _p->produceData(buf, amtRead, 1, true, this);
+
+        dataReadFromOS.append(buf, amtRead);
+        if(dataReadFromOS.find("END") == string::npos)
+            continue;
+        releaseConn = true;
+        break; //found the end string
+    }
+    cpool->releaseConnection(sufio, releaseConn);
+    delete _p;
+    _p = 0;
+}
+
+void OSProducer::runAsStaticCache()
+{
+    unsigned int amtToSendPerAttempt = 4096;
+    unsigned int amtToSendThisTime = 0;
+    unsigned int amtSent = 0;
+    while(1)
+    {
+        while(amtSent < data.length())
+        {
+            amtToSendThisTime = (((data.length() - amtSent) > amtToSendPerAttempt) ? amtToSendPerAttempt : (data.length() - amtSent));
+            /*
+            char* buf = (char*) malloc (amtToSendThisTime);
+            memcpy(buf, data.data() + amtSent, amtToSendThisTime);
+            _p->produceData(buf, amtToSendThisTime, 1, true, this);
+            */
+            _p->produceData((void*)(data.data()+amtSent), amtToSendThisTime, 1, false, this);
+            amtSent += amtToSendThisTime;
+        }
+        _p->produceData(0, 0, 0, false, this);
+        amtSent = 0;
+
+        this->block();
+        if(_bailProducer == 1)
+            break;
+        _bailProducer = 0;
+    }
+
+    delete _p;
+    _p = 0;
+}