Revision: 7406
          http://playerstage.svn.sourceforge.net/playerstage/?rev=7406&view=rev
Author:   gerkey
Date:     2009-03-09 20:09:15 +0000 (Mon, 09 Mar 2009)

Log Message:
-----------
Fixed up queue handling, got performance stuff in place, webgazebo runs
valgrind-clean.

Modified Paths:
--------------
    code/branches/federation/gazebo/webgazebo/WebGazebo.cc
    code/branches/federation/gazebo/webgazebo/WebGazebo.hh
    code/branches/federation/gazebo/webgazebo/client.cc

Modified: code/branches/federation/gazebo/webgazebo/WebGazebo.cc
===================================================================
--- code/branches/federation/gazebo/webgazebo/WebGazebo.cc      2009-03-09 
20:08:24 UTC (rev 7405)
+++ code/branches/federation/gazebo/webgazebo/WebGazebo.cc      2009-03-09 
20:09:15 UTC (rev 7406)
@@ -115,7 +115,7 @@
   double timeout = 3.0;
   struct timeval t0, t1;
   gettimeofday(&t0, NULL);
-  struct timespec sleeptime = {0, 10000000};
+  struct timespec sleeptime = {0, 1000000};
   while(this->simIface->data->responseCount == 0)
   {
     gettimeofday(&t1, NULL);
@@ -316,10 +316,12 @@
                               struct evkeyvalq* kv,
                               std::string& response)
 {
+  /*
   printf("[webgazebo] got request for %s:%s:%s\n",
          model.c_str(),
          prop.c_str(),
          action.c_str());
+         */
   if(HasModel(model))
   {
     if(action == "get")
@@ -452,7 +454,9 @@
 {
   WebGazebo* obj = (WebGazebo*)arg;
 
+  /*
   printf("[webgazebo] Got request:%s:\n", req->uri);
+  */
   
   // Pull out query args
   struct evkeyvalq query_args;
@@ -481,10 +485,14 @@
   }
 
   evbuffer_add_printf(eb, "%s\n", response.c_str());
+  /*
   printf("[webgazebo] Sending reply: %d %s\n",
          response_code, response_string.c_str());
+         */
   evhttp_send_reply(req, response_code, response_string.c_str(), eb);
   evbuffer_free(eb);
+
+  obj->DeleteKeyVal(&query_args);
 }
 
 void
@@ -508,20 +516,31 @@
   t.push_back(s.substr(start));
 }
 
+// Strange that libevent doesn't provide a way to free the evkeyvalq
+// structure.
+void
+WebGazebo::DeleteKeyVal(struct evkeyvalq* query_args)
+{
+  struct evkeyval* kv;
+  TAILQ_FOREACH(kv, query_args, next)
+  {
+    free(kv->key);
+    free(kv->value);
+    TAILQ_REMOVE(query_args, kv, next);
+  }
+}
+
 bool
 WebGazebo::GetValue(std::string& value,
                     struct evkeyvalq* query_args, 
                     const std::string& key)
 {
-  for(struct evkeyval* kv = ((struct evkeyval*)&query_args)->next.tqe_next;
-      kv;
-      kv = kv->next.tqe_next)
+  struct evkeyval* kv;
+  TAILQ_FOREACH(kv, query_args, next)
   {
     if(key == kv->key)
     {
-      value = kv->value;
-      printf("setting %s to %s (%s)\n", 
-             key.c_str(), kv->value, value.c_str());
+      value = std::string(kv->value);
       return true;
     }
   }

Modified: code/branches/federation/gazebo/webgazebo/WebGazebo.hh
===================================================================
--- code/branches/federation/gazebo/webgazebo/WebGazebo.hh      2009-03-09 
20:08:24 UTC (rev 7405)
+++ code/branches/federation/gazebo/webgazebo/WebGazebo.hh      2009-03-09 
20:09:15 UTC (rev 7406)
@@ -103,4 +103,5 @@
                   std::string& action,
                   std::string uri,
                   std::string& response);
+    void DeleteKeyVal(struct evkeyvalq* query_args);
 };

Modified: code/branches/federation/gazebo/webgazebo/client.cc
===================================================================
--- code/branches/federation/gazebo/webgazebo/client.cc 2009-03-09 20:08:24 UTC 
(rev 7405)
+++ code/branches/federation/gazebo/webgazebo/client.cc 2009-03-09 20:09:15 UTC 
(rev 7406)
@@ -39,22 +39,42 @@
 #include <evhttp.h>
 
 struct timeval g_t0, g_t1;
+const char* g_uri;
+size_t g_cnt;
+double g_dt;
+const size_t g_target_cnt = 1000;
 
 // Callback that's invoked when the request is done and we have the
 // response
 void
 cb(evhttp_request* req, void* arg)
 {
+  struct evhttp_connection* ec = (struct evhttp_connection*)arg;
   gettimeofday(&g_t1, NULL);
   if(req->response_code != 200)
+  {
     printf("Got non-OK response code: %d\n", req->response_code);
+    exit(1);
+  }
 
-  printf("Response:\n%s", req->input_buffer->buffer);
+  //printf("Response:\n%s", req->input_buffer->buffer);
   
   double dt = ((g_t1.tv_sec + g_t1.tv_usec/1e6) - 
                (g_t0.tv_sec + g_t0.tv_usec/1e6));
-  printf("Elapsed time: %.6f\n", dt);
-  exit(0);
+  g_dt += dt;
+  //printf("Elapsed time: %.6f\n", dt);
+
+  g_cnt++;
+  if(g_cnt >= g_target_cnt)
+  {
+    printf("Total: %d transactions / %.6fs = %.6f tran/s\n",
+           g_cnt, g_dt, g_cnt / g_dt);
+    exit(0);
+  }
+
+  gettimeofday(&g_t0, NULL);
+  struct evhttp_request* er = evhttp_request_new(cb, (void*)ec);
+  int ret = evhttp_make_request(ec, er, EVHTTP_REQ_GET, g_uri);
 }
 
 #define USAGE "USAGE: client <URI>"
@@ -62,15 +82,13 @@
 int
 main(int argc, char** argv)
 {
-  const char* uri;
-
   if(argc != 2)
   {
     puts(USAGE);
     exit(1);
   }
 
-  uri = argv[1];
+  g_uri = argv[1];
 
   struct evhttp_connection* ec;
   struct evhttp_request* er;
@@ -81,8 +99,8 @@
   assert(ec);
 
   gettimeofday(&g_t0, NULL);
-  er = evhttp_request_new(cb, NULL);
-  int ret = evhttp_make_request(ec, er, EVHTTP_REQ_GET, uri);
+  er = evhttp_request_new(cb, (void*)ec);
+  int ret = evhttp_make_request(ec, er, EVHTTP_REQ_GET, g_uri);
   event_dispatch();
 
   return 0;


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit

Reply via email to