Tidy up JobQueue, add ripple_core module

This commit is contained in:
Vinnie Falco
2013-06-22 16:35:40 -07:00
parent fcb4c35fce
commit 64c8d406df
8 changed files with 107 additions and 54 deletions

View File

@@ -87,8 +87,17 @@ public:
std::vector<std::string> IPS; // Peer IPs from rippled.cfg.
std::vector<std::string> SNTP_SERVERS; // SNTP servers from rippled.cfg.
enum StartUpType { FRESH, NORMAL, LOAD, NETWORK };
enum StartUpType
{
FRESH,
NORMAL,
LOAD,
NETWORK
};
StartUpType START_UP;
std::string START_LEDGER;
// Database
@@ -101,6 +110,16 @@ public:
int LEDGER_PROPOSAL_DELAY_SECONDS;
int LEDGER_AVALANCHE_SECONDS;
bool LEDGER_CREATOR; // Should be false unless we are starting a new ledger.
/** Operate in stand-alone mode.
In stand alone mode:
- Peer connections are not attempted or accepted
- The ledger is not advanced automatically.
- If no ledger is loaded, the default ledger with the root
account is created.
*/
bool RUN_STANDALONE;
// Note: The following parameters do not relate to the UNL or trust at all

View File

@@ -7,24 +7,27 @@
SETUP_LOG (JobQueue)
JobQueue::JobQueue (boost::asio::io_service& svc)
: mLastJob (0), mThreadCount (0), mShuttingDown (false), mIOThreadCount (0), mMaxIOThreadCount (1), mIOService (svc)
: mLastJob (0)
, mThreadCount (0)
, mShuttingDown (false)
, mIOService (svc)
{
mJobLoads[jtPUBOLDLEDGER].setTargetLatency (10000, 15000);
mJobLoads[jtVALIDATION_ut].setTargetLatency (2000, 5000);
mJobLoads[jtPROOFWORK].setTargetLatency (2000, 5000);
mJobLoads[jtTRANSACTION].setTargetLatency (250, 1000);
mJobLoads[jtPROPOSAL_ut].setTargetLatency (500, 1250);
mJobLoads[jtPUBLEDGER].setTargetLatency (3000, 4500);
mJobLoads[jtWAL].setTargetLatency (1000, 2500);
mJobLoads[jtVALIDATION_t].setTargetLatency (500, 1500);
mJobLoads[jtWRITE].setTargetLatency (750, 1500);
mJobLoads[jtTRANSACTION_l].setTargetLatency (100, 500);
mJobLoads[jtPROPOSAL_t].setTargetLatency (100, 500);
mJobLoads [ jtPUBOLDLEDGER ].setTargetLatency (10000, 15000);
mJobLoads [ jtVALIDATION_ut ].setTargetLatency (2000, 5000);
mJobLoads [ jtPROOFWORK ].setTargetLatency (2000, 5000);
mJobLoads [ jtTRANSACTION ].setTargetLatency (250, 1000);
mJobLoads [ jtPROPOSAL_ut ].setTargetLatency (500, 1250);
mJobLoads [ jtPUBLEDGER ].setTargetLatency (3000, 4500);
mJobLoads [ jtWAL ].setTargetLatency (1000, 2500);
mJobLoads [ jtVALIDATION_t ].setTargetLatency (500, 1500);
mJobLoads [ jtWRITE ].setTargetLatency (750, 1500);
mJobLoads [ jtTRANSACTION_l ].setTargetLatency (100, 500);
mJobLoads [ jtPROPOSAL_t ].setTargetLatency (100, 500);
mJobLoads[jtCLIENT].setTargetLatency (2000, 5000);
mJobLoads[jtPEER].setTargetLatency (200, 1250);
mJobLoads[jtDISK].setTargetLatency (500, 1000);
mJobLoads[jtACCEPTLEDGER].setTargetLatency (1000, 2500);
mJobLoads [ jtCLIENT ].setTargetLatency (2000, 5000);
mJobLoads [ jtPEER ].setTargetLatency (200, 1250);
mJobLoads [ jtDISK ].setTargetLatency (500, 1000);
mJobLoads [ jtACCEPTLEDGER ].setTargetLatency (1000, 2500);
}
void JobQueue::addJob (JobType type, const std::string& name, const FUNCTION_TYPE<void (Job&)>& jobFunc)
@@ -177,13 +180,18 @@ void JobQueue::shutdown ()
void JobQueue::setThreadCount (int c)
{
if (theConfig.RUN_STANDALONE)
{
c = 1;
}
else if (c == 0)
{
c = boost::thread::hardware_concurrency ();
// VFALCO NOTE According to boost, hardware_concurrency cannot return
// negative numbers/
//
if (c < 0)
c = 2;
c = 2; // VFALCO NOTE Why 2?
if (c > 4) // I/O will bottleneck
c = 4;
@@ -192,12 +200,15 @@ void JobQueue::setThreadCount (int c)
WriteLog (lsINFO, JobQueue) << "Auto-tuning to " << c << " validation/transaction/proposal threads";
}
// VFALCO TODO Split the function up. The lower part actually does the "do",
// The part above this comment figures out the value for numThreads
//
boost::mutex::scoped_lock sl (mJobLock);
mMaxIOThreadCount = 1 + (c / 3);
while (mJobCounts[jtDEATH].first != 0)
{
mJobCond.wait (sl);
}
while (mThreadCount < c)
{
@@ -208,7 +219,9 @@ void JobQueue::setThreadCount (int c)
while (mThreadCount > c)
{
if (mJobCounts[jtDEATH].first != 0)
{
mJobCond.wait (sl);
}
else
{
mJobSet.insert (Job (jtDEATH, 0));
@@ -219,27 +232,6 @@ void JobQueue::setThreadCount (int c)
mJobCond.notify_one (); // in case we sucked up someone else's signal
}
void JobQueue::IOThread (boost::mutex::scoped_lock& sl)
{
// call with a lock
++mIOThreadCount;
sl.unlock ();
setCallingThreadName ("IO+");
try
{
mIOService.poll ();
}
catch (...)
{
WriteLog (lsWARNING, JobQueue) << "Exception in IOThread";
}
setCallingThreadName ("waiting");
sl.lock ();
--mIOThreadCount;
}
// do jobs until asked to stop
void JobQueue::threadEntry ()
{
@@ -249,19 +241,9 @@ void JobQueue::threadEntry ()
{
setCallingThreadName ("waiting");
// bool didIO = false;
while (mJobSet.empty () && !mShuttingDown)
{
// if ((mIOThreadCount < mMaxIOThreadCount) && !didIO && !theApp->isShutdown())
// {
// IOThread(sl);
// didIO = true;
// }
// else
// {
mJobCond.wait (sl);
// didIO = false;
// }
}
if (mJobSet.empty ())

View File

@@ -43,7 +43,6 @@ public:
private:
void threadEntry ();
void IOThread (boost::mutex::scoped_lock&);
boost::mutex mJobLock;
boost::condition_variable mJobCond;
@@ -54,8 +53,6 @@ private:
int mThreadCount;
bool mShuttingDown;
int mIOThreadCount;
int mMaxIOThreadCount;
boost::asio::io_service& mIOService;
std::map<JobType, std::pair<int, int > > mJobCounts;