Improve performance of PC polling with many paired PCs

This commit is contained in:
Cameron Gutman 2017-09-02 20:30:18 -07:00
parent f485c8ce49
commit 94df20bbee
4 changed files with 24 additions and 10 deletions

View File

@ -80,7 +80,7 @@ int http_request(char* url, PHTTP_DATA data) {
curl_easy_setopt(curl, CURLOPT_MAXCONNECTS, 0L); curl_easy_setopt(curl, CURLOPT_MAXCONNECTS, 0L);
curl_easy_setopt(curl, CURLOPT_FRESH_CONNECT, 1L); curl_easy_setopt(curl, CURLOPT_FRESH_CONNECT, 1L);
curl_easy_setopt(curl, CURLOPT_FORBID_REUSE, 1L); curl_easy_setopt(curl, CURLOPT_FORBID_REUSE, 1L);
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 5L); curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 3L);
curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1L); curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1L);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, data); curl_easy_setopt(curl, CURLOPT_WRITEDATA, data);
curl_easy_setopt(curl, CURLOPT_URL, url); curl_easy_setopt(curl, CURLOPT_URL, url);

View File

@ -22,8 +22,6 @@
MoonlightInstance* g_Instance; MoonlightInstance* g_Instance;
MoonlightInstance::~MoonlightInstance() {}
class MoonlightModule : public pp::Module { class MoonlightModule : public pp::Module {
public: public:
MoonlightModule() : pp::Module() {} MoonlightModule() : pp::Module() {}
@ -258,13 +256,15 @@ void MoonlightInstance::HandleOpenURL(int32_t callbackId, pp::VarArray args) {
std::string url = args.Get(0).AsString(); std::string url = args.Get(0).AsString();
bool binaryResponse = args.Get(1).AsBool(); bool binaryResponse = args.Get(1).AsBool();
openHttpThread.message_loop().PostWork(m_CallbackFactory.NewCallback(&MoonlightInstance::NvHTTPRequest, callbackId, url, binaryResponse)); m_HttpThreadPool[m_HttpThreadPoolSequence++ % HTTP_HANDLER_THREADS]->message_loop().PostWork(
m_CallbackFactory.NewCallback(&MoonlightInstance::NvHTTPRequest, callbackId, url, binaryResponse));
PostMessage(pp::Var (url.c_str())); PostMessage(pp::Var (url.c_str()));
} }
void MoonlightInstance::HandlePair(int32_t callbackId, pp::VarArray args) { void MoonlightInstance::HandlePair(int32_t callbackId, pp::VarArray args) {
openHttpThread.message_loop().PostWork(m_CallbackFactory.NewCallback(&MoonlightInstance::PairCallback, callbackId, args)); m_HttpThreadPool[m_HttpThreadPoolSequence++ % HTTP_HANDLER_THREADS]->message_loop().PostWork(
m_CallbackFactory.NewCallback(&MoonlightInstance::PairCallback, callbackId, args));
} }
void MoonlightInstance::PairCallback(int32_t /*result*/, int32_t callbackId, pp::VarArray args) { void MoonlightInstance::PairCallback(int32_t /*result*/, int32_t callbackId, pp::VarArray args) {

View File

@ -38,6 +38,11 @@
#define DR_FLAG_FORCE_SW_DECODE 0x01 #define DR_FLAG_FORCE_SW_DECODE 0x01
// These will mostly be I/O bound so we'll create
// a bunch to allow more concurrent server requests
// since our HTTP request libary is synchronous.
#define HTTP_HANDLER_THREADS 8
struct Shader { struct Shader {
Shader() : program(0), texcoord_scale_location(0) {} Shader() : program(0), texcoord_scale_location(0) {}
~Shader() {} ~Shader() {}
@ -61,7 +66,7 @@ class MoonlightInstance : public pp::Instance, public pp::MouseLock {
m_AccumulatedTicks(0), m_AccumulatedTicks(0),
m_MouseDeltaX(0), m_MouseDeltaX(0),
m_MouseDeltaY(0), m_MouseDeltaY(0),
openHttpThread(this) { m_HttpThreadPoolSequence(0) {
// This function MUST be used otherwise sockets don't work (nacl_io_init() doesn't work!) // This function MUST be used otherwise sockets don't work (nacl_io_init() doesn't work!)
nacl_io_init_ppapi(pp_instance(), pp::Module::Get()->get_browser_interface()); nacl_io_init_ppapi(pp_instance(), pp::Module::Get()->get_browser_interface());
@ -71,10 +76,18 @@ class MoonlightInstance : public pp::Instance, public pp::MouseLock {
m_GamepadApi = static_cast<const PPB_Gamepad*>(pp::Module::Get()->GetBrowserInterface(PPB_GAMEPAD_INTERFACE)); m_GamepadApi = static_cast<const PPB_Gamepad*>(pp::Module::Get()->GetBrowserInterface(PPB_GAMEPAD_INTERFACE));
openHttpThread.Start(); for (int i = 0; i < HTTP_HANDLER_THREADS; i++) {
m_HttpThreadPool[i] = new pp::SimpleThread(this);
m_HttpThreadPool[i]->Start();
}
} }
virtual ~MoonlightInstance(); virtual ~MoonlightInstance() {
for (int i = 0; i < HTTP_HANDLER_THREADS; i++) {
m_HttpThreadPool[i]->Join();
delete m_HttpThreadPool[i];
}
}
bool Init(uint32_t argc, const char* argn[], const char* argv[]); bool Init(uint32_t argc, const char* argn[], const char* argv[]);
@ -178,7 +191,8 @@ class MoonlightInstance : public pp::Instance, public pp::MouseLock {
float m_AccumulatedTicks; float m_AccumulatedTicks;
int32_t m_MouseDeltaX, m_MouseDeltaY; int32_t m_MouseDeltaX, m_MouseDeltaY;
pp::SimpleThread openHttpThread; pp::SimpleThread* m_HttpThreadPool[HTTP_HANDLER_THREADS];
uint32_t m_HttpThreadPoolSequence;
}; };
extern MoonlightInstance* g_Instance; extern MoonlightInstance* g_Instance;

View File

@ -138,7 +138,7 @@ NvHTTP.prototype = {
completion(this); completion(this);
} }
}.bind(this), function() { }.bind(this), function() {
if (++this._consecutivePollFailures >= 3) { if (++this._consecutivePollFailures >= 2) {
this.online = false; this.online = false;
} }