Implement new coroutines (RIPD-1043)

This commit is contained in:
Miguel Portilla
2015-10-19 10:45:41 -04:00
committed by Nik Bougalis
parent 880f354b90
commit 108906cb20
30 changed files with 1089 additions and 1462 deletions

View File

@@ -24,6 +24,7 @@
#include <ripple/app/misc/NetworkOPs.h>
#include <ripple/basics/CountedObject.h>
#include <ripple/basics/Log.h>
#include <ripple/core/JobCoro.h>
#include <ripple/json/to_string.h>
#include <ripple/net/InfoSub.h>
#include <ripple/net/RPCErr.h>
@@ -31,13 +32,11 @@
#include <ripple/protocol/JsonFields.h>
#include <ripple/resource/Fees.h>
#include <ripple/resource/ResourceManager.h>
#include <ripple/rpc/Coroutine.h>
#include <ripple/rpc/RPCHandler.h>
#include <ripple/server/Port.h>
#include <ripple/server/Role.h>
#include <ripple/json/to_string.h>
#include <ripple/rpc/RPCHandler.h>
#include <ripple/rpc/Yield.h>
#include <ripple/server/Role.h>
#include <ripple/websocket/WebSocket.h>
@@ -97,7 +96,8 @@ public:
message_ptr getMessage ();
bool checkMessage ();
void returnMessage (message_ptr const&);
Json::Value invokeCommand (Json::Value const& jvRequest, RPC::Suspend const&);
Json::Value invokeCommand (Json::Value const& jvRequest,
std::shared_ptr<JobCoro> jobCoro);
// Generically implemented per version.
void setPingTimer ();
@@ -240,7 +240,7 @@ void ConnectionImpl <WebSocket>::returnMessage (message_ptr const& ptr)
template <class WebSocket>
Json::Value ConnectionImpl <WebSocket>::invokeCommand (
Json::Value const& jvRequest, RPC::Suspend const& suspend)
Json::Value const& jvRequest, std::shared_ptr<JobCoro> jobCoro)
{
if (getConsumer().disconnect ())
{
@@ -281,10 +281,9 @@ Json::Value ConnectionImpl <WebSocket>::invokeCommand (
}
else
{
RPC::Context context {
app_.journal ("RPCHandler"), jvRequest, app_, loadType, m_netOPs, app_.getLedgerMaster(),
role, {app_, suspend, "WSClient::command"},
this->shared_from_this ()};
RPC::Context context {app_.journal ("RPCHandler"), jvRequest,
app_, loadType, m_netOPs, app_.getLedgerMaster(), role,
jobCoro, this->shared_from_this ()};
RPC::doCommand (context, jvResult[jss::result]);
}

View File

@@ -378,8 +378,8 @@ public:
message_job("more", cpClient);
}
bool do_message (Job& job, const connection_ptr& cpClient,
const wsc_ptr& conn, const message_ptr& mpMessage)
bool do_message (Job& job, const connection_ptr cpClient,
wsc_ptr conn, const message_ptr& mpMessage)
{
Json::Value jvRequest;
Json::Reader jrReader;
@@ -425,37 +425,23 @@ public:
job.rename ("WSClient::" + jCmd.asString());
}
auto const start = std::chrono::high_resolution_clock::now ();
struct HandlerCoroutineData
{
Json::Value jvRequest;
std::string buffer;
wsc_ptr conn;
};
auto data = std::make_shared<HandlerCoroutineData>();
data->jvRequest = std::move(jvRequest);
data->conn = conn;
auto j = app_.journal ("RPCHandler");
auto coroutine = [data, j] (RPC::Suspend const& suspend) {
data->buffer = to_string(
data->conn->invokeCommand(
data->jvRequest, suspend));
};
static auto const disableWebsocketsCoroutines = true;
auto useCoroutines = disableWebsocketsCoroutines ?
RPC::UseCoroutines::no : RPC::useCoroutines(desc_.config);
runOnCoroutine(useCoroutines, coroutine);
rpc_time_.notify (static_cast <beast::insight::Event::value_type> (
std::chrono::duration_cast <std::chrono::milliseconds> (
std::chrono::high_resolution_clock::now () - start)));
++rpc_requests_;
rpc_size_.notify (static_cast <beast::insight::Event::value_type>
(data->buffer.size()));
send (cpClient, data->buffer, false);
app_.getJobQueue().postCoro(jtCLIENT, "WSClient",
[this, conn, cpClient, jvRequest = std::move(jvRequest)]
(std::shared_ptr<JobCoro> jc)
{
using namespace std::chrono;
auto const start = high_resolution_clock::now();
auto buffer = to_string(conn->invokeCommand(jvRequest, jc));
rpc_time_.notify (
static_cast <beast::insight::Event::value_type> (
duration_cast <milliseconds> (
high_resolution_clock::now () - start)));
++rpc_requests_;
rpc_size_.notify (
static_cast <beast::insight::Event::value_type>
(buffer.size()));
send (cpClient, buffer, false);
});
}
return true;