From 4ddf3385a84c69c9b6262f5226d02cad153976c5 Mon Sep 17 00:00:00 2001 From: Kao Makino Date: Tue, 19 Jan 2021 17:13:27 -0800 Subject: [PATCH] Reserve the priority queue container --- flow/Knobs.cpp | 1 + flow/Knobs.h | 1 + flow/Net2.actor.cpp | 13 ++++++++++++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/flow/Knobs.cpp b/flow/Knobs.cpp index 28b7deb180..da722d2079 100644 --- a/flow/Knobs.cpp +++ b/flow/Knobs.cpp @@ -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 ); diff --git a/flow/Knobs.h b/flow/Knobs.h index 5dd746cc84..258ea28ea2 100644 --- a/flow/Knobs.h +++ b/flow/Knobs.h @@ -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; diff --git a/flow/Net2.actor.cpp b/flow/Net2.actor.cpp index c77078dfcb..5ffa5f250b 100644 --- a/flow/Net2.actor.cpp +++ b/flow/Net2.actor.cpp @@ -111,6 +111,16 @@ struct OrderedTask { bool operator < (OrderedTask const& rhs) const { return priority < rhs.priority; } }; +template +class ReadyQueue : public std::priority_queue> +{ +public: + typedef typename std::priority_queue>::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> ready; + ReadyQueue ready; ThreadSafeQueue 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),