Merge pull request #4217 from sfc-gh-kmakino/pq_hack

Reserve the priority queue container
This commit is contained in:
Andrew Noyes 2021-01-20 18:42:32 -08:00 committed by GitHub
commit b62406fb48
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 1 deletions

View File

@ -122,6 +122,7 @@ FlowKnobs::FlowKnobs(bool randomize, bool isSimulated) {
init( SLOW_LOOP_SAMPLING_RATE, 0.1 );
init( TSC_YIELD_TIME, 1000000 );
init( CERT_FILE_MAX_SIZE, 5 * 1024 * 1024 );
init( READY_QUEUE_RESERVED_SIZE, 8192 );
//Network
init( PACKET_LIMIT, 100LL<<20 );

View File

@ -143,6 +143,7 @@ public:
int64_t TSC_YIELD_TIME;
int64_t REACTOR_FLAGS;
int CERT_FILE_MAX_SIZE;
int READY_QUEUE_RESERVED_SIZE;
//Network
int64_t PACKET_LIMIT;

View File

@ -111,6 +111,16 @@ struct OrderedTask {
bool operator < (OrderedTask const& rhs) const { return priority < rhs.priority; }
};
template <class T>
class ReadyQueue : public std::priority_queue<T, std::vector<T>>
{
public:
typedef typename std::priority_queue<T, std::vector<T>>::size_type size_type;
ReadyQueue(size_type capacity = 0) { reserve(capacity); };
void reserve(size_type capacity) { this->c.reserve(capacity); }
};
thread_local INetwork* thread_network = 0;
class Net2 sealed : public INetwork, public INetworkConnections {
@ -190,7 +200,7 @@ public:
TaskPriority lastMinTaskID;
std::priority_queue<OrderedTask, std::vector<OrderedTask>> ready;
ReadyQueue<OrderedTask> ready;
ThreadSafeQueue<OrderedTask> threadReady;
struct DelayedTask : OrderedTask {
@ -843,6 +853,7 @@ Net2::Net2(const TLSConfig& tlsConfig, bool useThreadPool, bool useMetrics)
reactor(this),
stopped(false),
tasksIssued(0),
ready(FLOW_KNOBS->READY_QUEUE_RESERVED_SIZE),
// Until run() is called, yield() will always yield
tsc_begin(0), tsc_end(0), taskBegin(0), currentTaskID(TaskPriority::DefaultYield),
lastMinTaskID(TaskPriority::Zero),