[svn] commit: r2603 - in /experiments/stephen-receptionist: common/ contractor/ intermediary/ server/ worker/

BIND 10 source code commits bind10-changes at lists.isc.org
Fri Jul 23 17:18:45 UTC 2010


Author: stephen
Date: Fri Jul 23 17:18:45 2010
New Revision: 2603

Log:
Added multi-threading to intermediary in client-intermediary-worker model

Removed:
    experiments/stephen-receptionist/contractor/contractor_controller.cc
    experiments/stephen-receptionist/contractor/contractor_controller.h
    experiments/stephen-receptionist/server/server_controller.cc
    experiments/stephen-receptionist/server/server_controller.h
    experiments/stephen-receptionist/worker/worker_controller.cc
    experiments/stephen-receptionist/worker/worker_controller.h
Modified:
    experiments/stephen-receptionist/common/packet_counter.h
    experiments/stephen-receptionist/intermediary/Makefile.am
    experiments/stephen-receptionist/intermediary/intermediary_controller.cc
    experiments/stephen-receptionist/intermediary/intermediary_controller.h

Modified: experiments/stephen-receptionist/common/packet_counter.h
==============================================================================
--- experiments/stephen-receptionist/common/packet_counter.h (original)
+++ experiments/stephen-receptionist/common/packet_counter.h Fri Jul 23 17:18:45 2010
@@ -21,7 +21,7 @@
 
 #include <csignal>
 #include <iostream>
-#include <vector>
+#include <iomanip>
 
 /// \brief Counts Packets
 ///
@@ -40,6 +40,7 @@
 
             // Register the exit handler and SIGTERM handler.
             signal(SIGTERM, sigtermHandler);
+            signal(SIGHUP,  sighupHandler);
             handler_registered_ = true;
         }
         send_count_ = receive_count_ = 0;
@@ -79,16 +80,30 @@
     /// This is the SIGTERM handler which prints out the statistics and
     /// then exits the program.
     static void sigtermHandler(int sig) {
+        printCounters();
+        exit(0);
+    }
+
+    /// \brief SIGHUP Handler
+    ///
+    /// Prints the counters on receipt of a SIGHUP.
+    static void sighupHandler(int sign) {
+        printCounters();
+    }
+
+    /// \brief Prints the send and receive counters
+    static void printCounters() {
         std::cout << "send() calls:        " << send_count_ << "\n"
-                  << "receive() calls:     " << receive_count_ << "\n";
+                  << "receive() calls:     " << receive_count_
+                  << std::endl;
 
         // Print out additional counters only if either is greater than
         // zero (simplifies output for programs that don't use them).
         if (send2_count_ or receive2_count_) {
             std::cout << "send() calls (2):    " << send2_count_ << "\n"
-                      << "receive() calls (2): " << receive2_count_ << "\n";
+                      << "receive() calls (2): " << receive2_count_
+                      << std::endl;
         }
-        exit(0);
     }
 
 private:

Modified: experiments/stephen-receptionist/intermediary/Makefile.am
==============================================================================
--- experiments/stephen-receptionist/intermediary/Makefile.am (original)
+++ experiments/stephen-receptionist/intermediary/Makefile.am Fri Jul 23 17:18:45 2010
@@ -2,7 +2,7 @@
 
 AM_CPPFLAGS = -I$(top_srcdir)/common
 
-AM_LDFLAGS  = -lboost_program_options -lboost_system
+AM_LDFLAGS  = -lboost_program_options -lboost_system -lboost_thread
 
 intermediary_LDADD = $(top_srcdir)/common/libcommon.a
 

Modified: experiments/stephen-receptionist/intermediary/intermediary_controller.cc
==============================================================================
--- experiments/stephen-receptionist/intermediary/intermediary_controller.cc (original)
+++ experiments/stephen-receptionist/intermediary/intermediary_controller.cc Fri Jul 23 17:18:45 2010
@@ -19,6 +19,8 @@
 #include <list>
 #include <utility>
 
+#include <boost/thread.hpp>
+
 #include "communicator.h"
 #include "debug.h"
 #include "intermediary_controller.h"
@@ -26,14 +28,23 @@
 #include "udp_buffer.h"
 #include "utilities.h"
 
+// Forward task wrapper.  It is only specified to simplify the starting of
+// the wrd ask in a separate thread.
+static void forwardTaskWrapper(IntermediaryController& controller,
+    Communicator& client_communicator, Communicator& contractor_communicator)
+{
+    controller.forwardTask(client_communicator, contractor_communicator);
 
-// Starts the intermediary task.  Never returns.
+    return;
+}
+
+// Forwarded task - forward packets from client to contractor in bursts
+
 void
-IntermediaryController::run(Communicator& client_communicator,
+IntermediaryController::forwardTask(Communicator& client_communicator,
    Communicator& contractor_communicator)
 {
-    PacketCounter counter;
-
+    PacketCounter counter;              // Access global counters
     std::list<UdpBuffer> queue;         // Packet queue...
     std::list<UdpBuffer>::iterator li;  // and its iterator
 
@@ -53,8 +64,20 @@
             contractor_communicator.send(*li);
         }
         queue.clear();
+    }
+}
 
-        // Now read the packets from the contractor and store in the queue.
+void
+IntermediaryController::returnTask(Communicator& client_communicator,
+   Communicator& contractor_communicator)
+{
+    PacketCounter counter;              // Access global counters
+    std::list<UdpBuffer> queue;         // Packet queue...
+    std::list<UdpBuffer>::iterator li;  // and its iterator
+
+    while (true) {
+
+        // Read the packets from the contractor and store in the queue.
         for (int i = 0; i < burst_; ++i) {
             Debug::log(counter.incrementReceive2(),
                 "Receiving data from contractor");
@@ -72,3 +95,22 @@
 
     return;
 }
+
+
+// Starts the intermediary task.  Never returns.
+void
+IntermediaryController::run(Communicator& client_communicator,
+   Communicator& contractor_communicator)
+{
+ 
+    // Start the forwarding task in a separate thread.
+    boost::thread forward_thread(forwardTaskWrapper,
+        boost::ref(*this), boost::ref(client_communicator),
+        boost::ref(contractor_communicator));
+
+    // ... and start the return task in this thread.
+    returnTask(client_communicator, contractor_communicator);
+
+    // Should never terminate!
+    return;
+}

Modified: experiments/stephen-receptionist/intermediary/intermediary_controller.h
==============================================================================
--- experiments/stephen-receptionist/intermediary/intermediary_controller.h (original)
+++ experiments/stephen-receptionist/intermediary/intermediary_controller.h Fri Jul 23 17:18:45 2010
@@ -48,11 +48,28 @@
 
     /// \brief Runs the controller
     ///
-    /// Loops reading burst_ packets, appending a checksum, then sending
-    // them back.  It never returns.
+    /// Just starts the forward and return tasks; never returns.
     /// \param communicator Communicator to use for I/O to the client
     /// \param communicator Communicator to use for I/O to the processor
     virtual void run(Communicator& client_communicator,
+        Communicator& processor_communicator);
+
+    /// \brief Forward packets from client to contractor
+    ///
+    /// Simple loop, reading "burst_" packets at a time from the client before
+    /// forwarding them to the contractor.
+    /// \param communicator Communicator to use for I/O to the client
+    /// \param communicator Communicator to use for I/O to the processor
+    virtual void forwardTask(Communicator& client_communicator,
+        Communicator& processor_communicator);
+
+    /// \brief Return packets from contractor to client
+    ///
+    /// Simple loop, reading "burst_" packets at a time from the contractor
+    /// before returning them to the client.
+    /// \param communicator Communicator to use for I/O to the client
+    /// \param communicator Communicator to use for I/O to the processor
+    virtual void returnTask(Communicator& client_communicator,
         Communicator& processor_communicator);
 
 private:




More information about the bind10-changes mailing list