Skip to content

Commit

Permalink
add webserver-thread-pool-size to webserver_plugin/config files
Browse files Browse the repository at this point in the history
  • Loading branch information
mkochanowicz committed Aug 11, 2017
1 parent 29aa826 commit a131faa
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
3 changes: 3 additions & 0 deletions contrib/config-for-docker.ini
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ p2p-user-agent = Graphene Reference Implementation
# The local IP and port to listen for incoming websocket connections.
# webserver-ws-endpoint =

# Number of threads used to handle queries. Default: 256.
webserver-thread-pool-size = 1024

# Enable block production, even if the chain is stale.
enable-stale-production = false

Expand Down
3 changes: 3 additions & 0 deletions contrib/fullnode.config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ p2p-user-agent = Graphene Reference Implementation
# The local IP and port to listen for incoming websocket connections.
# webserver-ws-endpoint =

# Number of threads used to handle queries. Default: 256.
webserver-thread-pool-size = 1024

# Enable block production, even if the chain is stale.
enable-stale-production = false

Expand Down
31 changes: 22 additions & 9 deletions libraries/plugins/webserver/webserver_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <boost/asio.hpp>
#include <boost/optional.hpp>
#include <boost/bind.hpp>
#include <boost/preprocessor/stringize.hpp>

#include <websocketpp/config/asio_client.hpp>
#include <websocketpp/config/asio.hpp>
Expand All @@ -21,8 +22,6 @@
#include <memory>
#include <iostream>

#define WEBSERVER_THREAD_POOL_SIZE 256

namespace steemit { namespace plugins { namespace webserver {

namespace asio = boost::asio;
Expand All @@ -34,6 +33,11 @@ using boost::asio::ip::tcp;
using std::shared_ptr;
using websocketpp::connection_hdl;

#define WEBSERVER_DEFAULT_THREAD_POOL_SIZE 256
#define WEBSERVER_THREAD_POOL_SIZE_OPTION "webserver-thread-pool-size"

typedef uint32_t thread_pool_size_t;

namespace detail {

struct asio_with_stub_log : public websocketpp::config::asio
Expand Down Expand Up @@ -110,10 +114,10 @@ std::vector<fc::ip::endpoint> resolve_string_to_ip_endpoints( const std::string&
class webserver_plugin_impl
{
public:
webserver_plugin_impl() :
webserver_plugin_impl(thread_pool_size_t thread_pool_size) :
api_work( this->api_ios )
{
for( uint32_t i = 0; i < WEBSERVER_THREAD_POOL_SIZE; i++ )
for( thread_pool_size_t i = 0; i < thread_pool_size; ++i )
api_thread_pool.create_thread( boost::bind( &asio::io_service::run, &api_ios ) );
}

Expand All @@ -134,19 +138,28 @@ class webserver_plugin_impl
plugins::json_rpc::json_rpc_plugin* api;
};

webserver_plugin::webserver_plugin() : _my( new webserver_plugin_impl() ) {}
webserver_plugin::~webserver_plugin(){}
webserver_plugin::webserver_plugin() {}
webserver_plugin::~webserver_plugin() {}

void webserver_plugin::set_program_options( options_description&, options_description& cfg )
{
cfg.add_options()
("webserver-http-endpoint", bpo::value< string >(), "The local IP and port to listen for incoming http connections.")
("webserver-ws-endpoint", bpo::value< string >(), "The local IP and port to listen for incoming websocket connections.")
;
("webserver-http-endpoint", bpo::value< string >(), "The local IP and port to listen for incoming http connections.")
("webserver-ws-endpoint", bpo::value< string >(), "The local IP and port to listen for incoming websocket connections.")
(WEBSERVER_THREAD_POOL_SIZE_OPTION, bpo::value<thread_pool_size_t>()->default_value(WEBSERVER_DEFAULT_THREAD_POOL_SIZE),
"Number of threads used to handle queries. Default: " BOOST_PP_STRINGIZE(WEBSERVER_DEFAULT_THREAD_POOL_SIZE) ".")
;
}

void webserver_plugin::plugin_initialize( const variables_map& options )
{
FC_ASSERT(options.count(WEBSERVER_THREAD_POOL_SIZE_OPTION) != 0, WEBSERVER_THREAD_POOL_SIZE_OPTION "is required!");
auto thread_pool_size = options.at(WEBSERVER_THREAD_POOL_SIZE_OPTION).as<thread_pool_size_t>();
if (thread_pool_size <= 0)
thread_pool_size = WEBSERVER_DEFAULT_THREAD_POOL_SIZE;
_my.reset(new webserver_plugin_impl(thread_pool_size));
ilog( "configured with ${tps} thread pool size", ("tps", thread_pool_size) );

if( options.count( "webserver-http-endpoint" ) )
{
auto http_endpoint = options.at( "webserver-http-endpoint" ).as< string >();
Expand Down

0 comments on commit a131faa

Please sign in to comment.