[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] [gnuradio] 13/50: controlport: using threaded server f
From: |
git |
Subject: |
[Commit-gnuradio] [gnuradio] 13/50: controlport: using threaded server for multiple connections. |
Date: |
Wed, 15 Apr 2015 21:07:52 +0000 (UTC) |
This is an automated email from the git hooks/post-receive script.
jcorgan pushed a commit to branch master
in repository gnuradio.
commit 7eea2e4ba106ba165aa0e7180f93d28aa954b3a3
Author: Nate Goergen <address@hidden>
Date: Fri Feb 27 18:35:01 2015 -0600
controlport: using threaded server for multiple connections.
* Adding TThreadPoolServer support to ControlPort Thrift interface
** allow multiple concurrent connections
** NOTE: Hard coding the number of service threads to 10; should be set
through config file
* some code cleanup
---
.../include/gnuradio/thrift_application_base.h | 55 +++-------------------
.../include/gnuradio/thrift_server_template.h | 28 +++++++++--
.../controlport/thrift/rpcserver_booter_thrift.cc | 29 ++++++++++++
.../controlport/thrift/thrift_application_base.cc | 1 +
4 files changed, 60 insertions(+), 53 deletions(-)
diff --git a/gnuradio-runtime/include/gnuradio/thrift_application_base.h
b/gnuradio-runtime/include/gnuradio/thrift_application_base.h
index 1bf8416..120e7e9 100644
--- a/gnuradio-runtime/include/gnuradio/thrift_application_base.h
+++ b/gnuradio-runtime/include/gnuradio/thrift_application_base.h
@@ -23,35 +23,15 @@
#ifndef THRIFT_APPLICATION_BASE_H
#define THRIFT_APPLICATION_BASE_H
-#ifdef HAVE_WINDOWS_H
-#include <winsock2.h>
-#include <sys/time.h>
-#endif
-
#include <gnuradio/api.h>
-#include <gnuradio/prefs.h>
-#include <thrift/Thrift.h>
#include <boost/thread.hpp>
-#include <boost/thread/mutex.hpp>
-#include <stdio.h>
-#include <iostream>
-#include <set>
-#include <string>
-#include <stdio.h>
-
-#include <thrift/Thrift.h>
-#include <thrift/transport/TServerSocket.h>
-#include <thrift/transport/TBufferTransports.h>
-#include <thrift/server/TSimpleServer.h>
-#include <gnuradio/rpcserver_thrift.h>
-#include <ControlPort.h>
-
-using namespace apache;
namespace {
static const unsigned int THRIFTAPPLICATION_ACTIVATION_TIMEOUT_MS(600);
};
+namespace apache { namespace thrift { namespace server { class TServer; } } }
+
class GR_RUNTIME_API thrift_application_common
{
public:
@@ -66,7 +46,7 @@ class GR_RUNTIME_API thrift_application_common
static std::string d_endpointStr;
static boost::shared_ptr<boost::thread> d_thread;
- thrift::server::TSimpleServer* d_thriftserver;
+ apache::thrift::server::TServer* d_thriftserver;
thrift_application_common() {;}
int run(int, char*[]);
@@ -92,7 +72,9 @@ protected:
static TserverClass* d_this;
- thrift::server::TSimpleServer* d_thriftserver;
+ apache::thrift::server::TServer* d_thriftserver;
+
+ static const unsigned int d_default_num_thrift_threads;
private:
bool d_is_running;
@@ -120,31 +102,6 @@ thrift_application_base<TserverBase,
TserverClass>::thrift_application_base(Tser
//d_application->d_thriftserver = d_this->d_thriftserver;
}
-template<typename TserverBase, typename TserverClass>
-void thrift_application_base<TserverBase, TserverClass>::start_thrift()
-{
- //char* argv[2];
- //argv[0] = (char*)"";
- //
- //std::string conffile = gr::prefs::singleton()->get_string("ControlPort",
"config", "");
- //
- //if(conffile.size() > 0) {
- // std::stringstream thriftconf;
- // d_have_thrift_config = true;
- // d_main_called = true;
- // thriftconf << conffile;
- // main(0, argv, thriftconf.str().c_str());
- //}
- //else {
- // d_have_thrift_config = false;
- // d_main_called = true;
- // main(0, argv);
- //}
-
- //std::cerr << "thrift_application_base: start_thrift" << std::endl;
- d_thriftserver->serve();
- d_is_running = true;
-}
template<typename TserverBase, typename TserverClass>
void thrift_application_base<TserverBase, TserverClass>::kickoff()
diff --git a/gnuradio-runtime/include/gnuradio/thrift_server_template.h
b/gnuradio-runtime/include/gnuradio/thrift_server_template.h
index 261893d..3147696 100644
--- a/gnuradio-runtime/include/gnuradio/thrift_server_template.h
+++ b/gnuradio-runtime/include/gnuradio/thrift_server_template.h
@@ -27,7 +27,10 @@
#include <gnuradio/thrift_application_base.h>
#include <iostream>
-#include <thrift/Thrift.h>
+#include <thrift/server/TSimpleServer.h>
+#include <thrift/server/TThreadPoolServer.h>
+#include <thrift/concurrency/ThreadManager.h>
+#include <thrift/concurrency/PlatformThreadFactory.h>
#include <thrift/transport/TServerSocket.h>
#include <thrift/transport/TBufferTransports.h>
#include <ControlPort.h>
@@ -74,10 +77,27 @@ thrift_server_template<TserverBase, TserverClass,
TImplClass, TThriftClass>::thr
boost::shared_ptr<thrift::protocol::TProtocolFactory>
protocolFactory(new thrift::protocol::TBinaryProtocolFactory());
- thrift_application_base<TserverBase, TImplClass>::d_thriftserver =
- new thrift::server::TSimpleServer(processor, serverTransport,
transportFactory, protocolFactory);
+ if(thrift_application_base<TserverBase,
TImplClass>::d_default_num_thrift_threads <= 1)
+ { // "Thrift: Single-threaded server"
+ thrift_application_base<TserverBase, TImplClass>::d_thriftserver =
+ new thrift::server::TSimpleServer(processor, serverTransport,
transportFactory, protocolFactory);
+ } else { // std::cout << "Thrift Multi-threaded server : " <<
d_default_num_thrift_threads << std::endl;
+ boost::shared_ptr<thrift::concurrency::ThreadManager> threadManager(
+ thrift::concurrency::ThreadManager::newSimpleThreadManager(
+ thrift_application_base<TserverBase,
TImplClass>::d_default_num_thrift_threads));
- d_server = (TserverBase*)handler.get();
+ boost::shared_ptr<thrift::concurrency::PlatformThreadFactory>
threadFactory(
+ boost::shared_ptr<thrift::concurrency::PlatformThreadFactory>(new
thrift::concurrency::PlatformThreadFactory()));
+
+ threadManager->threadFactory(threadFactory);
+
+ threadManager->start();
+
+ thrift_application_base<TserverBase, TImplClass>::d_thriftserver =
+ new thrift::server::TThreadPoolServer(processor, serverTransport,
transportFactory, protocolFactory, threadManager);
+ }
+
+ d_server = handler.get();
}
template<typename TserverBase, typename TserverClass, typename TImplClass,
typename TThriftClass>
diff --git a/gnuradio-runtime/lib/controlport/thrift/rpcserver_booter_thrift.cc
b/gnuradio-runtime/lib/controlport/thrift/rpcserver_booter_thrift.cc
index 90fce2b..2d1ac52 100644
--- a/gnuradio-runtime/lib/controlport/thrift/rpcserver_booter_thrift.cc
+++ b/gnuradio-runtime/lib/controlport/thrift/rpcserver_booter_thrift.cc
@@ -56,3 +56,32 @@ rpcserver_booter_thrift::endpoints()
rpcserver_booter_thrift,
GNURadio::ControlPortIf>::endpoints();
}
+
+template<typename TserverBase, typename TserverClass>
+const unsigned int thrift_application_base<TserverBase,
TserverClass>::d_default_num_thrift_threads(10U);
+
+template<typename TserverBase, typename TserverClass>
+void thrift_application_base<TserverBase, TserverClass>::start_thrift()
+{
+ //char* argv[2];
+ //argv[0] = (char*)"";
+ //
+ //std::string conffile = gr::prefs::singleton()->get_string("ControlPort",
"config", "");
+ //
+ //if(conffile.size() > 0) {
+ // std::stringstream thriftconf;
+ // d_have_thrift_config = true;
+ // d_main_called = true;
+ // thriftconf << conffile;
+ // main(0, argv, thriftconf.str().c_str());
+ //}
+ //else {
+ // d_have_thrift_config = false;
+ // d_main_called = true;
+ // main(0, argv);
+ //}
+
+ //std::cerr << "thrift_application_base: start_thrift" << std::endl;
+ d_thriftserver->serve();
+ d_is_running = true;
+}
diff --git a/gnuradio-runtime/lib/controlport/thrift/thrift_application_base.cc
b/gnuradio-runtime/lib/controlport/thrift/thrift_application_base.cc
index 5f190c0..ee0a0f0 100644
--- a/gnuradio-runtime/lib/controlport/thrift/thrift_application_base.cc
+++ b/gnuradio-runtime/lib/controlport/thrift/thrift_application_base.cc
@@ -21,6 +21,7 @@
*/
#include <gnuradio/thrift_application_base.h>
+#include <thrift/server/TServer.h>
int thrift_application_common::d_reacquire_attributes(0);
bool thrift_application_common::d_main_called(false);
- [Commit-gnuradio] [gnuradio] 14/50: controlport: Thrift's binary type, (continued)
- [Commit-gnuradio] [gnuradio] 14/50: controlport: Thrift's binary type, git, 2015/04/16
- [Commit-gnuradio] [gnuradio] 09/50: controlport: cleanup and switching over to new Python common interface., git, 2015/04/16
- [Commit-gnuradio] [gnuradio] 23/50: controlport: cleaning up and using logger to display endpoint., git, 2015/04/16
- [Commit-gnuradio] [gnuradio] 34/50: controlport: replacement of nanosleep() with boost::sleep() in startup thread. Fix of merge error in booter_thrift., git, 2015/04/16
- [Commit-gnuradio] [gnuradio] 28/50: controlport: more cleaning up., git, 2015/04/16
- [Commit-gnuradio] [gnuradio] 31/50: controlport: moving the logger call that publishes Thrift's endpoint to i_impl()., git, 2015/04/16
- [Commit-gnuradio] [gnuradio] 24/50: controlport: adding performance and controlport monitor GRC blocks., git, 2015/04/16
- [Commit-gnuradio] [gnuradio] 29/50: controlport: changing the default port number on the Thrift interface to zero., git, 2015/04/16
- [Commit-gnuradio] [gnuradio] 21/50: controlport: Adds ability to configure Thrift through a config file, git, 2015/04/16
- [Commit-gnuradio] [gnuradio] 30/50: controlport: ephemeral / unused port number selection by OS working., git, 2015/04/16
- [Commit-gnuradio] [gnuradio] 13/50: controlport: using threaded server for multiple connections.,
git <=
- [Commit-gnuradio] [gnuradio] 39/50: controlport: documentation cleanup, git, 2015/04/16
- [Commit-gnuradio] [gnuradio] 35/50: controlport: cleanup, git, 2015/04/16
- [Commit-gnuradio] [gnuradio] 33/50: controlport: more cleanup and conveniences, git, 2015/04/16
- [Commit-gnuradio] [gnuradio] 11/50: controlport: more work on the translation layer; properties and setting parameters in gr-ctrlport-monitor now working., git, 2015/04/16
- [Commit-gnuradio] [gnuradio] 45/50: controlport: ensure proper ctrlport shutdown., git, 2015/04/16
- [Commit-gnuradio] [gnuradio] 08/50: controlport: adding abstraction layer for the controlport backends; support thrift currently., git, 2015/04/16
- [Commit-gnuradio] [gnuradio] 25/50: controlport: fixing up some issues; generate thrift sources into thrift subdir., git, 2015/04/16
- [Commit-gnuradio] [gnuradio] 16/50: controlport: switching rpcpmtconverter::to_pmt() to To_PMT singleton, git, 2015/04/16
- [Commit-gnuradio] [gnuradio] 40/50: controlport: documentation cleanup, git, 2015/04/16
- [Commit-gnuradio] [gnuradio] 10/50: controlport: more cleanup of python code to help generalize the interface, git, 2015/04/16