Fennel: SimpleExecStreamGovernor Class Reference (original) (raw)
SimpleExecStreamGovernor is a reference implementation of ExecStreamGovernor. More...
#include <[SimpleExecStreamGovernor.h](SimpleExecStreamGovernor%5F8h-source.html)>
Inheritance diagram for SimpleExecStreamGovernor:

| Public Member Functions | |
|---|---|
| SimpleExecStreamGovernor (ExecStreamResourceKnobs const &knobSettings, ExecStreamResourceQuantity const &resourcesAvailable, SharedTraceTarget pTraceTarget, std::string name) | |
| virtual | ~SimpleExecStreamGovernor () |
| virtual bool | setResourceKnob (ExecStreamResourceKnobs const &knob, ExecStreamResourceKnobType knobType) |
| Informs the resource governor of a new knob setting. | |
| virtual bool | setResourceAvailability (ExecStreamResourceQuantity const &available, ExecStreamResourceType resourceType) |
| Informs the resource governor of a new resource availablity. | |
| virtual void | requestResources (ExecStreamGraph &graph) |
| Requests resources for an exec stream graph and assigns resources to each exec stream in the graph. | |
| virtual void | returnResources (ExecStreamGraph &graph) |
| Returns to the available resource pool resources that have been assigned to an exec stream graph. | |
| void | writeStats (StatsTarget &target) |
| Writes a current stats snapshot to a StatsTarget. | |
| virtual void | initTraceSource (SharedTraceTarget pTraceTarget, std::string name) |
| For use when initialization has to be deferred until after construction. | |
| void | trace (TraceLevel level, std::string message) const |
| Records a trace message. | |
| bool | isTracing () const |
| **Returns:**true iff tracing is enabled for this source | |
| bool | isTracingLevel (TraceLevel level) const |
| Determines whether a particular level is being traced. | |
| TraceTarget & | getTraceTarget () const |
| **Returns:**the TraceTarget for this source | |
| SharedTraceTarget | getSharedTraceTarget () const |
| **Returns:**the SharedTraceTarget for this source | |
| std::string | getTraceSourceName () const |
| Gets the name of this source. | |
| void | setTraceSourceName (std::string const &n) |
| Sets the name of this source. | |
| TraceLevel | getMinimumTraceLevel () const |
| void | disableTracing () |
| Protected Types | |
| typedef std::map< ExecStreamGraph *, SharedExecStreamResourceQuantity > | ExecStreamGraphResourceMap |
| Protected Member Functions | |
| void | traceCachePageRequest (uint assigned, ExecStreamResourceRequirements const &reqt, std::string const &name) |
| Traces the number of pages assigned to a stream, as well as its minimum and optimum requirements. | |
| Protected Attributes | |
| ExecStreamResourceKnobs | knobSettings |
| Current resource knob settings. | |
| ExecStreamResourceQuantity | resourcesAvailable |
| Keeps track of the total resources that are currently available for assignment. | |
| ExecStreamResourceQuantity | resourcesAssigned |
| Keeps track of resources that have been assigned. | |
| ExecStreamGraphResourceMap | resourceMap |
| Used to keep track of how much resources have been assigned to each of the currently active exec stream graphs. | |
| StrictMutex | mutex |
| Used to synchronize access. | |
| Private Member Functions | |
| uint | computePerGraphAllocation () |
| Computes the per graph allocation. | |
| void | assignCachePages (std::vector< SharedExecStream > &streams, boost::scoped_array< ExecStreamResourceRequirements > const &reqts, bool assignMin) |
| Assigns each stream either its minimum or optimum resource requirements. | |
| uint | distributeCachePages (std::vector< SharedExecStream > &streams, boost::scoped_array< ExecStreamResourceRequirements > const &reqts, boost::scoped_array< double > const &sqrtDiffOptMin, double totalSqrtDiffs, uint excessAvailable, bool assignOpt) |
| Distributes cache pages across streams according to the following formula:. | |
| Private Attributes | |
| uint | perGraphAllocation |
| Portion of resources that can be allocated to an exec stream graph. |
Detailed Description
SimpleExecStreamGovernor is a reference implementation of ExecStreamGovernor.
Version:
Id
//open/dev/fennel/exec/SimpleExecStreamGovernor.h#8
Definition at line 40 of file SimpleExecStreamGovernor.h.
Member Typedef Documentation
Constructor & Destructor Documentation
| SimpleExecStreamGovernor::~SimpleExecStreamGovernor | ( | | ) | [virtual] | | ---------------------------------------------------- | - | | - | ----------- |
Member Function Documentation
| uint SimpleExecStreamGovernor::computePerGraphAllocation | ( | | ) | [inline, private] | | --------------------------------------------------------------------------------------------------------------------- | - | | - | ------------------- |
| uint SimpleExecStreamGovernor::distributeCachePages | ( | std::vector< SharedExecStream > & | streams, |
|---|---|---|---|
| boost::scoped_array< ExecStreamResourceRequirements > const & | reqts, | ||
| boost::scoped_array< double > const & | sqrtDiffOptMin, | ||
| double | totalSqrtDiffs, | ||
| uint | excessAvailable, | ||
| bool | assignOpt | ||
| ) | [private] |
Distributes cache pages across streams according to the following formula:.
base amount for stream +
(# of extra pages above total min available to the stream graph) *
sqrt((opt for stream) - (min for stream)) /
sum of the sqrt of the differences between the opt and min for streams
that will receive excess allocations where the base amount is either the min or opt requirements of the
stream
Parameters:
| streams | streams to be assigned resources |
|---|---|
| reqts | resource requirements for each stream |
| sqrtDiffOptMin | sqrt of the difference between the opt and min for each stream |
| totalSqrtDiffs | sum of the sqrt of the differences between the opt and min for each stream |
| excessAvailable | excess cache pages to be distributed across certain streams |
| assignOpt | if true, assign at least the optimum amount to each stream; otherwise, assign at least the minimum amount |
Returns:
total number of cache pages assigned to streams
Definition at line 297 of file SimpleExecStreamGovernor.cpp.
References EXEC_RESOURCE_ACCURATE, EXEC_RESOURCE_UNBOUNDED, TraceSource::isTracingLevel(), ExecStreamResourceRequirements::minReqt, ExecStreamResourceQuantity::nCachePages, ExecStreamResourceRequirements::optReqt, ExecStreamResourceRequirements::optType, TRACE_FINER, and ExecStreamGovernor::traceCachePageRequest().
Referenced by requestResources().
Informs the resource governor of a new knob setting.
Called by ALTER SYSTEM SET commands that dynamically modify parameters controlling resource allocation.
Parameters:
| knob | new resource knob setting |
|---|---|
| knobType | indicates which knob setting to change |
Returns:
true if possible to apply new setting; false if the setting is below current in-use threshholds. E.g., if modifying cacheReservePercentage, the new number of reserved pages must allow for pages already assigned.
Implements ExecStreamGovernor.
Definition at line 50 of file SimpleExecStreamGovernor.cpp.
References ExecStreamResourceKnobs::cacheReservePercentage, computePerGraphAllocation(), EXEC_KNOB_CACHE_RESERVE_PERCENTAGE, EXEC_KNOB_EXPECTED_CONCURRENT_STATEMENTS, ExecStreamResourceKnobs::expectedConcurrentStatements, ExecStreamGovernor::knobSettings, ExecStreamGovernor::mutex, ExecStreamResourceQuantity::nCachePages, perGraphAllocation, ExecStreamGovernor::resourcesAssigned, ExecStreamGovernor::resourcesAvailable, and TRACE_FINE.
Informs the resource governor of a new resource availablity.
Called by ALTER SYSTEM SET commands that dynamically modify resources available.
Parameters:
| available | amount of resources now available |
|---|---|
| resourceType | type of resource to be set |
Returns:
true if possible to apply new settings; false if the setting is below current in-use threshholds. E.g., if modifying cachePagesInit, the value needs to be >= current number of cache pages that have been assigned.
Implements ExecStreamGovernor.
Definition at line 96 of file SimpleExecStreamGovernor.cpp.
References ExecStreamResourceKnobs::cacheReservePercentage, computePerGraphAllocation(), EXEC_RESOURCE_CACHE_PAGES, EXEC_RESOURCE_THREADS, ExecStreamGovernor::knobSettings, ExecStreamGovernor::mutex, ExecStreamResourceQuantity::nCachePages, ExecStreamResourceQuantity::nThreads, perGraphAllocation, ExecStreamGovernor::resourcesAssigned, ExecStreamGovernor::resourcesAvailable, and TRACE_FINE.
| void SimpleExecStreamGovernor::requestResources | ( | ExecStreamGraph & | graph | ) | [virtual] |
|---|
Requests resources for an exec stream graph and assigns resources to each exec stream in the graph.
Parameters:
| graph | the exec stream graph for which resources are being requested |
|---|
Implements ExecStreamGovernor.
Definition at line 130 of file SimpleExecStreamGovernor.cpp.
References assignCachePages(), distributeCachePages(), EXEC_RESOURCE_ACCURATE, EXEC_RESOURCE_ESTIMATE, EXEC_RESOURCE_UNBOUNDED, ExecStreamGraph::getSortedStreams(), min(), ExecStreamResourceRequirements::minReqt, ExecStreamGovernor::mutex, ExecStreamResourceQuantity::nCachePages, ExecStreamResourceQuantity::nThreads, ExecStreamResourceRequirements::optReqt, ExecStreamResourceRequirements::optType, perGraphAllocation, ExecStreamGovernor::resourceMap, ExecStreamGovernor::resourcesAssigned, ExecStreamGovernor::resourcesAvailable, and TRACE_FINE.
00131 {
00132 FENNEL_TRACE(TRACE_FINE, "requestResources");
00133
00134 StrictMutexGuard mutexGuard(mutex);
00135
00136 std::vector sortedStreams = graph.getSortedStreams();
00137 boost::scoped_array resourceReqts;
00138 boost::scoped_array sqrtDiffOptMin;
00139 uint nStreams = sortedStreams.size();
00140
00141 resourceReqts.reset(new ExecStreamResourceRequirements[nStreams]);
00142 sqrtDiffOptMin.reset(new double[nStreams]);
00143
00144
00145
00146 uint allocationAmount =
00147 std::min(resourcesAvailable.nCachePages, perGraphAllocation);
00148 FENNEL_TRACE(
00149 TRACE_FINE,
00150 allocationAmount << " cache pages available for stream graph");
00151
00152
00153
00154 uint totalMin = 0;
00155 uint totalOpt = 0;
00156 double totalSqrtDiffs = 0;
00157 bool allAccurate = true;
00158 for (uint i = 0; i < nStreams; i++) {
00159 ExecStreamResourceQuantity minQuantity, optQuantity;
00160 ExecStreamResourceSettingType optType;
00161 sortedStreams[i]->getResourceRequirements(
00162 minQuantity, optQuantity, optType);
00163 assert(
00164 optType == EXEC_RESOURCE_UNBOUNDED ||
00165 minQuantity.nCachePages <= optQuantity.nCachePages);
00166 assert(minQuantity.nThreads <= optQuantity.nThreads);
00167
00168 ExecStreamResourceRequirements &reqt = resourceReqts[i];
00169 reqt.minReqt = minQuantity.nCachePages;
00170 totalMin += reqt.minReqt;
00171 reqt.optType = optType;
00172
00173 switch (optType) {
00174 case EXEC_RESOURCE_ACCURATE:
00175 reqt.optReqt = optQuantity.nCachePages;
00176 sqrtDiffOptMin[i] = sqrt(double(reqt.optReqt - reqt.minReqt));
00177 break;
00178 case EXEC_RESOURCE_ESTIMATE:
00179 reqt.optReqt = optQuantity.nCachePages;
00180 sqrtDiffOptMin[i] = sqrt(double(reqt.optReqt - reqt.minReqt));
00181 allAccurate = false;
00182 break;
00183 case EXEC_RESOURCE_UNBOUNDED:
00184
00185
00186
00187
00188
00189
00190 sqrtDiffOptMin[i] = sqrt(double(allocationAmount));
00191 allAccurate = false;
00192
00193
00194 reqt.optReqt = reqt.minReqt + allocationAmount;
00195 break;
00196 }
00197 totalOpt += reqt.optReqt;
00198 totalSqrtDiffs += sqrtDiffOptMin[i];
00199 }
00200
00201
00202 if (totalMin > allocationAmount &&
00203 totalMin > resourcesAvailable.nCachePages)
00204 {
00205 FENNEL_TRACE(
00206 TRACE_FINE,
00207 "Minimum request of " << totalMin << " cache pages not met");
00208 throw ScratchMemExcn();
00209 }
00210
00211 uint totalAssigned;
00212
00213
00214 if (totalMin >= allocationAmount) {
00215 assignCachePages(sortedStreams, resourceReqts, true);
00216 totalAssigned = totalMin;
00217 FENNEL_TRACE(
00218 TRACE_FINE,
00219 "Mininum request of " << totalMin << " cache pages assigned");
00220
00221 } else if (totalOpt <= allocationAmount) {
00222
00223
00224 if (allAccurate) {
00225 assignCachePages(sortedStreams, resourceReqts, false);
00226 totalAssigned = totalOpt;
00227 FENNEL_TRACE(
00228 TRACE_FINE,
00229 "Optimum request of " << totalOpt << " cache pages assigned");
00230
00231 } else {
00232
00233
00234
00235
00236
00237
00238 uint assigned =
00239 distributeCachePages(
00240 sortedStreams, resourceReqts, sqrtDiffOptMin,
00241 totalSqrtDiffs, allocationAmount - totalOpt, true);
00242 totalAssigned = assigned;
00243 FENNEL_TRACE(
00244 TRACE_FINE,
00245 assigned <<
00246 " cache pages assigned, based on an optimum request for " <<
00247 totalOpt << " cache pages");
00248 }
00249
00250 } else {
00251
00252
00253 uint assigned =
00254 distributeCachePages(
00255 sortedStreams, resourceReqts, sqrtDiffOptMin, totalSqrtDiffs,
00256 allocationAmount - totalMin, false);
00257 totalAssigned = assigned;
00258 FENNEL_TRACE(
00259 TRACE_FINE,
00260 assigned <<
00261 " cache pages assigned based on an optimum request for " <<
00262 totalOpt << " cache pages");
00263 }
00264
00265
00266 resourcesAssigned.nCachePages += totalAssigned;
00267 resourcesAvailable.nCachePages -= totalAssigned;
00268 SharedExecStreamResourceQuantity
00269 pQuantity(new ExecStreamResourceQuantity());
00270 pQuantity->nCachePages = totalAssigned;
00271 resourceMap.insert(
00272 ExecStreamGraphResourceMap::value_type(&graph, pQuantity));
00273
00274 FENNEL_TRACE(
00275 TRACE_FINE,
00276 resourcesAvailable.nCachePages <<
00277 " cache pages remaining for assignment");
00278 }
| void SimpleExecStreamGovernor::returnResources | ( | ExecStreamGraph & | graph | ) | [virtual] |
|---|
Traces the number of pages assigned to a stream, as well as its minimum and optimum requirements.
Parameters:
| assigned | number of cache pages assigned to the stream |
|---|---|
| reqt | resource requirements for the stream |
| name | name of the stream |
Definition at line 53 of file ExecStreamGovernor.cpp.
References EXEC_RESOURCE_ACCURATE, EXEC_RESOURCE_ESTIMATE, EXEC_RESOURCE_UNBOUNDED, ExecStreamResourceRequirements::minReqt, ExecStreamResourceRequirements::optReqt, ExecStreamResourceRequirements::optType, and TRACE_FINER.
Referenced by assignCachePages(), and distributeCachePages().
00057 { 00058 switch (reqt.optType) { 00059 case EXEC_RESOURCE_ACCURATE: 00060 FENNEL_TRACE( 00061 TRACE_FINER, 00062 "Stream " << name << " assigned " << assigned << 00063 " pages based on accurate (min,opt) request of " << "(" << 00064 reqt.minReqt << "," << reqt.optReqt << ") pages"); 00065 break; 00066 case EXEC_RESOURCE_ESTIMATE: 00067 FENNEL_TRACE( 00068 TRACE_FINER, 00069 "Stream " << name << " assigned " << assigned << 00070 " pages based on estimated (min,opt) request of " << "(" << 00071 reqt.minReqt << "," << reqt.optReqt << ") pages"); 00072 break; 00073 case EXEC_RESOURCE_UNBOUNDED: 00074 FENNEL_TRACE( 00075 TRACE_FINER, 00076 "Stream " << name << " assigned " << assigned << 00077 " pages based on an unbounded opt request with " << 00078 reqt.minReqt << " min pages"); 00079 } 00080 }
| void ExecStreamGovernor::writeStats | ( | StatsTarget & | target | ) | [virtual, inherited] |
|---|
| void TraceSource::initTraceSource | ( | SharedTraceTarget | pTraceTarget, |
|---|---|---|---|
| std::string | name | ||
| ) | [virtual, inherited] |
| void TraceSource::trace | ( | TraceLevel | level, |
|---|---|---|---|
| std::string | message | ||
| ) | const [inherited] |
| bool TraceSource::isTracing | ( | | ) | const [inline, inherited] | | --------------------------- | - | | - | --------------------------- |
| bool TraceSource::isTracingLevel | ( | TraceLevel | level | ) | const [inline, inherited] |
|---|
| TraceTarget& TraceSource::getTraceTarget | ( | | ) | const [inline, inherited] | | ----------------------------------------------------------------- | - | | - | --------------------------- |
| std::string TraceSource::getTraceSourceName | ( | | ) | const [inline, inherited] | | ------------------------------------------- | - | | - | --------------------------- |
| void TraceSource::setTraceSourceName | ( | std::string const & | n | ) | [inline, inherited] |
|---|
Sets the name of this source.
Useful to construct dynamic names for fine-grained filtering.
Definition at line 136 of file TraceSource.h.
00137 { 00138 name = n; 00139 }
| TraceLevel TraceSource::getMinimumTraceLevel | ( | | ) | const [inline, inherited] | | ------------------------------------------------------------------------------------------------------ | - | | - | --------------------------- |
| void TraceSource::disableTracing | ( | | ) | [inherited] | | -------------------------------- | - | | - | ------------- |
Member Data Documentation
The documentation for this class was generated from the following files:
- /home/pub/open/dev/fennel/exec/SimpleExecStreamGovernor.h
- /home/pub/open/dev/fennel/exec/SimpleExecStreamGovernor.cpp
