# Patent

## Title
Estimating and managing energy consumption for query processing

## Abstract

Techniques are described for estimating and managing energy consumption for query processing. Embodiments of the invention may generally receive a query to be executed and calculate an initial estimated energy consumption value for the received query. If the initial estimated energy consumption value does not exceed a threshold amount of energy, embodiments of the invention may submit the query for execution. Once execution of the query has begun, embodiments of the invention may calculate an updated estimated energy consumption value for the executing query, and if the updated value exceeds the threshold amount of energy, may halt the execution of the query.

## Background
BACKGROUND
The present invention generally relates to database management, and more particularly, to managing query execution by estimating and managing energy consumption for query processing.
DESCRIPTION OF THE RELATED ART
Databases are computerized information storage and retrieval systems. A relational database management system is a computer database management system (DBMS) that uses relational techniques for storing and retrieving data. An object-oriented programming database is a database that is congruent with the data defined in object classes and subclasses.
Regardless of the particular architecture, a requesting entity (e.g., an application or the operating system) in a DBMS requests access to a specified database by issuing a database access request. Such requests may include, for instance, simple catalog lookup requests or transactions and combinations of transactions that operate to read, change and add specified records in the database. These requests (i.e., queries) are often made using high-level query languages such as the Structured Query Language (SQL). Upon receiving such a request, the DBMS may execute the request against a corresponding database, and return any result of the execution to the requesting entity.
As databases grow in size and in workload, particular queries may take a substantial amount of time and resources to execute. As such, database administrators may wish to limit the amount of energy that can be consumed in executing a particular query.
SUMMARY
Embodiments of the invention provide a method, system and computer program product for managing the execution of a query. The method, system and computer program product include receiving a query to be executed. Additionally, the method, system and computer program product include calculating an initial energy consumption value for the received query. The method, system and computer program product also include, upon determining the determined initial energy consumption value does not exceed a first threshold amount of energy, executing the query by operation of one or more computer processors.



BRIEF DESCRIPTION OF THE DRAWINGS
So that the manner in which the above recited aspects are attained and can be understood in detail, a more particular description of embodiments of the invention, briefly summarized above, may be had by reference to the appended drawings.
It is to be noted, however, that the appended drawings illustrate only typical embodiments of this invention and are therefore not to be considered limiting of its scope, for the invention may admit to other equally effective embodiments.
FIG. 1A-1B are block diagrams illustrating a networked system for estimating and managing energy consumption for query processing, according to embodiments of the invention.
FIG. 2 is a flow diagram illustrating a method of managing query execution, according to one embodiment of the invention.
FIG. 3 is a flow diagram illustrating a method of managing query execution, according to one embodiment of the invention.
FIGS. 4A-4D are exemplary energy consumption plans illustrating estimated energy consumption values, according to one embodiment of the invention.
FIG. 5 is a block diagram illustrating an exemplary computer memory of the query governor system of FIGS. 1A-1B, according to one embodiment of the invention.
FIG. 6 is an exemplary power pricing structure, according to one embodiment of the invention.



DETAILED DESCRIPTION
Many DBMS include some form of query governor. Query governors generally control how long queries may execute. For example, a query governor may enable a database administrator to have queries time out (i.e., execution of the query is halted) if a predetermined amount of time elapses before the execution completes. Additionally, before the database executes the query, a query governor may estimate the time it will take to execute the query, and if the estimated time exceeds a threshold amount, may reject the query. Continuing this example, if the query governor determines the estimated time is less than or equal to the threshold amount, the query governor may submit the query to the database for execution.
In addition to limiting the amount of time a particular query can take to execute, a business may also wish to limit the amount of energy that may be consumed in executing a particular query. For example, as part of a “green” initiative, a business may only allow queries whose execution consumes 10 or fewer units of energy to be executed by a particular DBMS. As such, if the query governor for the DBMS determines that a received query will consume approximately 20 units of energy when executed, the query governor may reject the received query for execution.
Alternatively, a business may wish to limit the monetary cost associated with executing a received query. As an example, as part of a cost-saving initiative, the business may wish to execute only queries that may be executed using less than $5.00 worth of energy. Thus, if the query governor in the example determines that a received query will consume approximately $10.00 worth of energy when executed, the query governor may reject the received query for execution. Because the determination of monetary cost also factors in the price of each unit of energy, and because these prices may change over time, a query that consumes a fixed amount of energy may be rejected by a monetary cost query governor at certain hours of the day, but accepted during other hours of the day. For example, assume that a particular query will require 5 units of energy to execute, and further assume that peak energy costs $3.00 per unit of energy, while off-peak energy only costs $1.00 per unit of energy. If the threshold monetary cost for a particular DBMS is $10.00 per query, the monetary cost query governor may reject the exemplary query during the peak hours of the day, but may accept the exemplary query for processing during the off-peak hours. As such, although the concepts of energy consumption and monetary cost of energy as described herein are related, these determinations are not identical.
Embodiments of the invention generally calculate an initial estimated energy consumption for a received query statement. If the initial estimated energy consumption exceeds a predetermined threshold amount of energy, embodiments of the invention may reject the query for execution. Upon determining that the initial estimated energy consumption does not exceed the predetermined threshold amount of energy, embodiments of the invention may begin execution of the query statement. Once execution of the query has begun, embodiments of the invention may then determine an estimated remaining energy consumption value for the executing query. If the estimated remaining energy consumption value exceeds a second predetermined threshold amount of energy, embodiments of the invention may halt the execution of the query, and reject the query for execution. If, instead, the estimated remaining energy consumption does not exceed the second predetermined threshold amount of energy, embodiments of the invention may allow the execution of the query to finish.
In the following, reference is made to embodiments of the invention. However, it should be understood that the invention is not limited to specific described embodiments. Instead, any combination of the following features and elements, whether related to different embodiments or not, is contemplated to implement and practice the invention. Furthermore, although embodiments of the invention may achieve advantages over other possible solutions and/or over the prior art, whether or not a particular advantage is achieved by a given embodiment is not limiting of the invention. Thus, the following aspects, features, embodiments and advantages are merely illustrative and are not considered elements or limitations of the appended claims except where explicitly recited in a claim(s). Likewise, reference to “the invention” shall not be construed as a generalization of any inventive subject matter disclosed herein and shall not be considered to be an element or limitation of the appended claims except where explicitly recited in a claim(s).
As will be appreciated by one skilled in the art, aspects of the present invention may be embodied as a system, method or computer program product. Accordingly, aspects of the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment (including firmware, resident software, micro-code, etc.) or an embodiment combining software and hardware aspects that may all generally be referred to herein as a “circuit,” “module” or “system.” Furthermore, aspects of the present invention may take the form of a computer program product embodied in one or more computer readable medium(s) having computer readable program code embodied thereon.
Any combination of one or more computer readable medium(s) may be utilized. The computer readable medium may be a computer readable signal medium or a computer readable storage medium. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any suitable combination of the foregoing. More specific examples (a non-exhaustive list) of the computer readable storage medium would include the following: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or Flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the context of this document, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device.
A computer readable signal medium may include a propagated data signal with computer readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated signal may take any of a variety of forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device.
Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.
Computer program code for carrying out operations for aspects of the present invention may be written in any combination of one or more programming languages, including an object oriented programming language such as Java, Smalltalk, C++ or the like and conventional procedural programming languages, such as the “C” programming language or similar programming languages. The program code may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the latter scenario, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or the connection may be made to an external computer (for example, through the Internet using an Internet Service Provider).
Aspects of the present invention are described below with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems) and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and/or block diagrams, and combinations of blocks in the flowchart illustrations and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions/acts specified in the flowchart and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer readable medium that can direct a computer, other programmable data processing apparatus, or other devices to function in a particular manner, such that the instructions stored in the computer readable medium produce an article of manufacture including instructions which implement the function/act specified in the flowchart and/or block diagram block or blocks.
The computer program instructions may also be loaded onto a computer, other programmable data processing apparatus, or other devices to cause a series of operational steps to be performed on the computer, other programmable apparatus or other devices to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide processes for implementing the functions/acts specified in the flowchart and/or block diagram block or blocks.
Embodiments of the invention may be provided to end users through a cloud computing infrastructure. Cloud computing generally refers to the provision of scalable computing resources as a service over a network. More formally, cloud computing may be defined as a computing capability that provides an abstraction between the computing resource and its underlying technical architecture (e.g., servers, storage, networks), enabling convenient, on-demand network access to a shared pool of configurable computing resources that can be rapidly provisioned and released with minimal management effort or service provider interaction. Thus, cloud computing allows a user to access virtual computing resources (e.g., storage, data, applications, and even complete virtualized computing systems) in “the cloud,” without regard for the underlying physical systems (or locations of those systems) used to provide the computing resources.
Typically, cloud computing resources are provided to a user on a pay-per-use basis, where users are charged only for the computing resources actually used (e.g. an amount of storage space consumed by a user or a number of virtualized systems instantiated by the user). A user can access any of the resources that reside in the cloud at any time, and from anywhere across the Internet. In context of the present invention, a user may access applications (e.g., the DBMS) available in the cloud. For example, the DBMS could execute on a computing system in the cloud and receive user requests (e.g., queries) to access databases managed by the DBMS. In such a case, an autonomic query governor may calculate an estimated energy consumption value for a received request, and then determine whether to submit the query to the DBMS for execution based on the determined energy consumption value. If the autonomic query governor does submit the query for execution, the autonomic query governor may further monitor the execution of the query and calculate an estimated remaining energy consumption value for the query. Doing so allows a user to access the database information from any computing system attached to a network connected to the cloud (e.g., the Internet).
FIG. 1A-1B are block diagrams illustrating a networked system for estimating and managing energy consumption for query processing, according to embodiments of the invention. As shown, FIG. 1A is a block diagram illustrating a networked system for estimating and managing energy consumption for query processing, according to one embodiment of the invention. In the depicted embodiment, the system 100 includes a client system 120 and a query governor system 170, connected by a network 150. Generally, the client system 120 may submit requests (i.e., queries) over the network 150 to a DBMS running on the query governor system 170. The term “query” denominates a set of commands for retrieving data from a stored database. Queries take the form of a command language, such as the Structured Query Language (SQL), that lets programmers and programs select, insert, update, find out the location of data, and so forth. Generally speaking, any requesting entity can issue queries against data in a database. For example, software applications (such as by an application running on the client system 120), operating systems, and, at the highest level, users may submit queries to the database. These queries may be predefined (i.e., hard coded as part of an application) or may be generated in response to input (e.g., user input). Upon receiving the request, the DBMS on the query governor system 170 may execute the request against a database specified in the request, and then return the result of the executed request.
However, it may be desirable for the query governor system 170 to only process certain requests it receives. That is, if a particular request would consume an excessive amount of energy to process, the query governor system 170 may wish to reject this query. According to embodiments of the invention, the query governor system 170 may include an autonomic query governor configured to determine which received requests the DBMS should execute. In one embodiment of the invention, upon receiving a query from the client system 120, the query governor may calculate an estimated energy consumption value for the query. If the query governor then determines that the estimated energy consumption exceeds a predetermined threshold amount of energy, the query governor may refuse the query for processing. For example, assume that the threshold amount of energy is 5 units of energy. If the query governor receives a query and estimates it will take 10 units of energy to process the received query, the query governor may refuse the query for processing, and may notify the client system 120 accordingly.
Furthermore, if the autonomic query governor determines that the estimated energy consumption does not exceed the threshold amount of energy, the query governor may submit the query to the DBMS for processing. Once the processing of the query has begun, the autonomic query governor may periodically calculate an updated estimated energy consumption value for the query. If, while the query is executing, the query governor determines that the updated estimated energy consumption exceeds the threshold amount of energy, the query governor may halt the execution of the query. For example, assume that the threshold amount of energy is 5 units of energy, and further assume that the query governor calculated the initial estimated energy consumption to be 2 units of energy. Because the estimated energy consumption does not exceed the predetermined threshold amount of energy, the query governor will submit the query to the DBMS for execution.
However, continuing with the example, if, while the query is executing, the query governor calculates an updated estimated energy consumption of 10 units of energy for processing the query, the query governor may then halt the execution of the query. The difference between the initial estimated energy consumption value and the updated estimated energy consumption value may be the result of, for instance, inaccurate data used to calculate the initial estimated energy consumption value. As such, embodiments of the invention enable the implementation of a more accurate, and thus a more useful query governor for restricting the amount of energy a query can consume when executed.
Referring now to FIG. 1B, FIG. 1 is a block diagram of a networked computer system configured to estimate and manage energy consumption for query processing, according to one embodiment of the invention. As shown, the system 110 contains a client system 120 and a query governor system 170. The client system 120 contains a computer processor 122, storage media 124, memory 128 and a network interface 138. Computer processor 122 may be any processor capable of performing the functions described herein. The client system 120 may connect to the network 150 using the network interface 138. Furthermore, as will be understood by one of ordinary skill in the art, any computer system capable of performing the functions described herein may be used.
In the pictured embodiment, memory 128 contains an operating system 130 and a client application 132. Although memory 128 is shown as a single entity, memory 128 may include one or more memory devices having blocks of memory associated with physical addresses, such as random access memory (RAM), read only memory (ROM), flash memory or other types of volatile and/or non-volatile memory. The client application 132 is generally capable of generating database queries. Once the client application 132 generates a query, the query may be submitted to a DBMS (e.g., DBMS 182) for execution over the network 150. The operating system 130 may be any operating system capable of performing the functions described herein.
The query governor system 170 contains a computer processor 172, storage media 174, memory 178 and a network interface 190. Computer processor 172 may be any processor capable of performing the functions described herein. Storage media 174 contains historical data 176. The historical data 176 may include data and metadata on previously executed queries. For example, in one embodiment of the invention, the historical data 176 includes information about the amount of energy required to execute previously executed queries. The query governor system 170 may connect to the network 150 using the network interface 190. Furthermore, as will be understood by one of ordinary skill in the art, any computer system capable of performing the functions described herein may be used.
In the pictured embodiment, memory 178 contains an operating system 180 and a DBMS 182. Although memory 178 is shown as a single entity, memory 178 may include one or more memory devices having blocks of memory associated with physical addresses, such as random access memory (RAM), read only memory (ROM), flash memory or other types of volatile and/or non-volatile memory. The DBMS 182 contains a database 184 and an autonomic query governor 186. The operating system 180 may be any operating system capable of performing the functions described herein.
Generally, the client application 132 may generate and submit queries to the DBMS 182 using the network 150. According to embodiments of the invention, once the DBMS 182 receives a query, the autonomic query governor 186 may calculate an estimated energy consumption for the query. Such a calculation may be based on values in the received query. For example, the query governor 186 may determine that a SELECT statement from a particular table in the database 184 will require 30 units of energy to execute. Additionally, the calculation may be based on collected metadata describing the received query. Furthermore, the query governor 186 may use the historical data 176 in calculating the estimated energy consumption for the received query. Thus, for example, the historical data 176 may contain data indicating that the DBMS 182 has previously processed a similar (or identical) query to the received query. In such a case, the query governor 186 may calculate the estimated energy consumption for the received query based on a recorded energy consumption value for the previously processed query stored in the historical data 176. Of course, the above examples are merely for illustrative purposes, and one of ordinary skill in the art will recognize that other data, metadata and historical data, as well as combinations therebetween, may be used as well.
FIG. 2 is a flow diagram illustrating a method of managing query execution, according to one embodiment of the invention. As shown, the method 200 begins at step 220, where the autonomic query governor 186 receives a query for processing. Upon receiving the query, the autonomic query governor 186 calculates an estimated energy consumption value for executing the received query (step 222). As discussed above, the estimated energy consumption may be calculated using data contained in the received query, metadata describing the received query, or historical data 176. Additionally, the query governor 186 may calculate the estimated energy consumption based on information about the query governor system 170. Thus, the query governor 186 may use resource information for the query governor system 170 to calculate the estimated energy consumption. As an example, such resource information may include the type of computer processor 172 in the query governor system 170, the energy consumption of the computer processor 172, the number of processors 172, the amount of memory 178, etc. Furthermore, the query governor 186 may calculate the estimated energy consumption based on workload information about the query governor system 170. Exemplary workload information includes CPU usage, memory usage, virtual memory usage, disk I/O, etc.
Once the estimated energy consumption value is calculated, the autonomic query governor 186 determines whether the estimated energy consumption value exceeds a threshold amount of energy (step 224). In one embodiment of the invention, the threshold amount of energy is a preset (e.g., by a database administrator) amount of energy that is used for all queries received by the DBMS 182. In another embodiment of the invention, the threshold amount of energy is based on the type of query received by the DBMS 182. For example, the threshold energy value for a SELECT statement may differ from the threshold energy value for an INSERT statement. In yet another embodiment, the threshold amount of energy is based on a priority value assigned to the incoming query. For instance, the priority value may be assigned based on the origin of the query. Thus, for example, a query statement received from a customer-facing production-stage application may receive a larger threshold amount of energy than a query received from an internal application that is still under development. Additionally, the threshold amount of energy may be derived from which user submitted the query, or a group the user submitting the query belongs to. Furthermore, the above examples are for illustrative purposes only, and one of ordinary skill in the art will quickly recognize that other factors may be used for calculating the threshold amount of energy as well.
If the query governor 186 determines that the estimated energy consumption value exceeds the threshold amount of energy, the query governor 186 rejects the query for processing (step 228). The query governor 186 may further notify the client application 132 that submitted the query. For example, the query governor 186 may return a message to the client application 132 that submitted the query, indicating that the query was rejected for processing because of the estimated energy consumption value. If instead the query governor 186 determines that the estimated energy consumption does not exceed the threshold amount of energy, the query governor 186 submits the query for processing (step 226). Once the query is submitted for processing, or once the query governor 186 rejects the query for processing, the method 200 ends.
In an alternate embodiment, upon determining that the estimated energy consumption value exceeds the threshold amount of energy, the query governor 186 may wait for a period of time and then recalculate the estimated energy consumption value. Once the value is recalculated, the query governor 186 may determine whether the recalculated energy consumption value exceeds the threshold amount of energy, and if it does, the query governor 186 may reject the query for processing. In one embodiment of the invention, the query governor 186 is configured to pause and recalculate the estimated energy consumption value multiple times. By doing this, embodiments of the invention may more accurately determine which queries should be rejected for processing. For example, if the initial estimated energy consumption value was artificially high (e.g., because of a spike in system workload), embodiments of the invention may avoid improperly rejecting the query by recalculating the estimated energy consumption value.
FIG. 3 is a flow diagram illustrating a method of managing query execution, according to one embodiment of the invention. As shown, the method 300 begins at step 320, where the DBMS 182 begins processing the received query. For example, the DBMS 182 may begin processing the query after the completion step 226 of the method 200 discussed above. Once the execution of the query has begun, the query governor 186 determines whether the execution of the query has completed (step 322). If the execution of the query has completed, the DBMS 182 returns the result of executing the query (step 330). Generally, the DBMS 182 will return the result produced from executing the query to whatever entity submitted the query. Thus, for example, if the query was submitted by a client application 132, the DBMS 182 will return the result to the client application 132.
If instead the query governor 186 determines that execution of the query has not completed, the query governor 186 calculates an updated estimated energy consumption value for the query (step 324). The updated energy consumption value may be based on the factors discussed above in calculating the initial estimated energy consumption value. Of note, the values of the factors used to calculate the updated estimated energy consumption value may have changed since the initial estimated energy consumption value was calculated. Additionally, the updated estimated energy consumption value may be based on how much of the query execution has been competed thus far. As an example, assume the initial query energy consumption value was calculated to be 5 units of energy. If, however, after the execution of the query has already consumed 5 units of energy, only 50% of the query has been executed, the query governor 186 may determine that the updated estimated energy consumption value for the query is 10 units of energy, based on the 5 units of energy required to execute 50% of the query.
In an alternate embodiment of the invention, the query governor 186 may determine a plurality of operations involved in the execution of the query, and may determine a separate estimated energy consumption value for each portion of the query execution. As an example, the query governor 186 may determine that a first portion of the query execution involves a SELECT statement executed against the database 184, and a second portion of the query execution involves a request submitted to a third party service. Continuing the example, the query governor 186 may further calculate that the first portion will take an estimated 10 units of energy to execute, while the second portion will take an estimated 5 units of energy to execute. Thus, the query governor 186 may calculate that the estimated energy consumption value for the entire query is 15 units of energy.
The query governor 186 then determines whether the updated estimated energy consumption value exceeds the threshold amount of energy (step 326). If the query governor 186 determines that the updated estimated energy consumption value does exceed the threshold amount of energy, the query governor 186 halts the execution of the query and rejects the query for processing (step 332). As used herein, halting the execution of the query may mean either suspending the execution or terminating the execution of the query. When the execution is suspended, the state of the query execution is saved, such that the DBMS may resume processing the query from the point the query was suspended. If the execution is terminated, the DBMS would resume processing the query from the beginning. On the other hand, if the query governor 186 determines the updated estimated energy consumption value does not exceed the threshold amount of energy, then the execution of the query continues (step 328), and the method begins again at step 322, where the query governor again determines whether the query has finished executing. Once the DBMS 182 returns the result of the query, or once the query governor halts the execution of the query and rejects the query for execution, the method 300 ends.
Advantageously, the method 300 enables the DBMS 182 to avoid processing queries that would consume an excessive amount of energy to process. That is, if the query governor 186 determines that a particular query will use an excessive amount of energy if executed, the query governor 186 rejects the query for processing, and if the execution of the query has already begun, halts the execution. A further advantage of the method 300 is even if the autonomic query governor 186 calculates an incorrect initial energy consumption value, the query governor 186 may correct this mistake when the updated estimated energy consumption value is calculated. For instance, the initial estimated energy consumption value may be incorrect because the data used to calculate the initial estimate was incorrect or incomplete. However, if the query governor 186 detects that the query is consuming more energy than was initially estimated, and further determines that, based on the energy consumed so far and the updated estimated energy consumption value, the query execution will not be able to complete within the threshold amount of energy, the query governor 186 may halt the execution of the query and reject the query for processing. Thus, a further advantage of the method 300 is that the query governor 186 may detect the query will not be able to complete within the threshold amount of energy, even after the initial estimated energy consumption value is calculated, but before the threshold amount of energy has been consumed. As such, even when the initial estimated energy consumption value is incorrect, the method 300 minimizes any wasteful energy consumption by the query governor system 170.
FIGS. 4A-4D are exemplary energy consumption plans illustrating estimated energy consumption, according to one embodiment of the invention. As shown, FIG. 4A shows an exemplary energy consumption plan 400 illustrating an estimated energy consumption value 420 for a particular query. In the depicted example, the query governor 186 may have determined that the execution of the query will include three separate operations, and has calculated an estimated energy consumption value for each portion 422. Furthermore, the query governor 186 may have determined the total estimated energy consumption for the particular query is PE 424. Additionally, the energy consumption plan 400 shows that the threshold energy amount Pthreshold 410 in this example is 20 units of energy. Thus, because in the depicted example the estimated energy consumption PE 424 is less than the threshold amount of energy Pthreshold 410, the query governor 186 may determine (e.g., at step 224) that execution of the particular query will consume a satisfactory amount of energy, and will allow the query to be executed. Alternatively, if the execution of the query has already begun, the query governor 186 may determine (e.g., at step 326) that the particular query will finish executing using a satisfactory amount of energy, and will allow the execution of the query to continue. As such, the energy consumption plan 400 shows an estimated energy consumption value for a query in the acceptable range of energy consumption (i.e., less than the threshold amount Pthreshold 410).
FIG. 4B shows an exemplary energy consumption plan 430 illustrating an estimated energy consumption value 440 for a particular query. In the depicted example, the query governor 186 may have determined that the execution of the query will include three separate operations, and has calculated an estimated energy consumption value for each portion 442. Furthermore, the query governor 186 may have determined the total estimated energy consumption value for the particular query is PE 444. Additionally, the energy consumption plan 430 shows that the threshold Pthreshold 410 in this example is 2 minutes. Thus, because in the depicted example the estimated energy consumption PE 444 is greater than the threshold amount of energy Pthreshold 410, the query governor 186 may determine (e.g., at step 224) that the particular query will consume an excessive amount of energy in execution, and thus will reject the query for execution. Alternatively, if the execution of the query has already begun, the query governor 186 may determine (e.g., at step 326) that the particular query will consume an excessive amount of energy by finishing executing, and thus will halt the execution of the query and reject the query for processing.
In the depicted example, portion 1 4421 of the received query has finished executing and has consumed less than the threshold amount of energy Pthreshold 410. However, as shown, the query governor 186 estimates that executing portion 2 4422 and portion 3 4423 of the received query will consume PE 444 units of energy. Since the estimated energy consumption value PE 444 for executing the received query exceeds the threshold amount of energy Pthreshold 410, the query governor 186 may halt the execution of the query and reject the query for processing.
Advantageously, because the autonomic query governor 186 detects the query will consume more than the threshold amount of energy after the first portion 4421 of the query has executed, the query governor 186 may halt the execution of the query before the entire threshold amount of energy Pthreshold 410 has been consumed.
Thus, even if the calculated initial estimated energy consumption value was incorrect (e.g., because of incorrect data), the autonomic energy query governor 186 may correct this mistake and halt the execution of the query, without waiting on the entire threshold amount of energy Pthreshold 410 to be consumed. In other words, even when the initial estimate is incorrect, embodiments of the invention mitigate the amount of energy wasted by the query governor system 170.
As shown, FIG. 4C shows an exemplary energy consumption plan 450 illustrating an estimated energy consumption value 460 for a particular query. In the depicted example, the query governor 186 may have determined that the execution of the query will include three separate operations, and has calculated an estimated energy consumption value for each portion 462. Furthermore, the query governor 186 may have determined the total estimated energy consumption value for the particular query is PE 464. Additionally, the energy consumption plan 400 shows that the threshold amount of energy P threshold 410 in this example is 20 units of energy. Thus, because in the depicted example the estimated energy consumption PE 464 is greater than the threshold Pthreshold 410, the query governor 186 may determine (e.g., at step 224) that the particular query will consume an excessive amount of energy if executed, and thus will reject the query for execution. Alternatively, if the execution of the query has already begun, the query governor 186 may determine (e.g., at step 326) that the particular query will consume an excessive amount of energy by finishing executing, and thus will halt the execution of the query and reject the query for processing.
In the depicted example, the query governor 186 has determined that the threshold amount of energy has been consumed before portion 1 4621 of the query has finished executing. As such, the query governor 186 may determine that the entire query will not finish executing until PE 464 units of energy have been consumed. As such, the query governor 186 may halt the execution of the query, and notify the entity (e.g., the client application 132) that the query was rejected for processing.
In one embodiment of the invention, the query governor 186 may consider how much energy has already been expended towards executing the query in determining whether to halt the execution of the query and reject the query for execution. As an example, assume that 10 units of energy have already been consumed in executing the query, and that the query governor 186 determines that 3 units of energy will be required to finish the execution of the query. In this example, even if the threshold amount of energy is 12 units of energy, the query governor 186 may determine that the execution of the query should be allowed to finish, even though to do so would consume more than the threshold amount of energy, because to halt the execution of the query would waste the 10 already-consumed units of energy.
As shown, FIG. 4D shows an exemplary energy consumption plan 470 illustrating an estimated energy consumption value 480 for a particular query. In the depicted example, the query governor 186 may have determined that the execution of the query will include three separate operations, and has calculated an estimated energy consumption value for each portion 482. Furthermore, the query governor 186 may have determined the total estimated energy consumption value for the particular query is PE 484. Additionally, the energy consumption plan 400 shows that the threshold amount of energy Pthreshold 410 in this example is 20 units of energy. Thus, because in the depicted example the estimated energy consumption PE 484 is greater than the threshold Pthreshold 410, the query governor 186 may determine (e.g., at step 224) that the particular query will consume an excessive amount of energy if executed, and thus will reject the query for execution. Alternatively, if the execution of the query has already begun, the query governor 186 may determine (e.g., at step 326) that the particular query will consume an excessive amount of energy by finishing executing, and thus will halt the execution of the query and reject the query for processing.
As shown, the autonomic query governor 186 has calculated the updated estimated energy consumption value 480 while portion 1 4821 of the query is in the process of executing. In the depicted example, the query governor 186 has determined that portion 2 4822 of the query is estimated to consume more energy than was originally estimated (e.g., in FIG. 4A) to complete. For example, the data used to estimate the original energy consumption value for portion 2 4822 of the query (e.g., the historical data 176) may be inaccurate or incomplete, and thus the original estimated energy consumption value was incorrect. Thus, because the estimated energy consumption value PE 484 is greater than the threshold time Pthreshold 410, the query governor 186 will thus halt the execution of the query and reject the query for processing.
Advantageously, because the autonomic query governor 186 calculates the updated estimated energy consumption value PE 484 before the threshold amount of energy Pthreshold 410 has been consumed, the query governor 186 may halt the execution of the query without waiting on the entire threshold amount of energy Pthreshold 410 to be wasted. Thus, even if the initial estimated energy consumption value is calculated incorrectly, the autonomic query governor 186 mitigates the impact of this incorrect calculation by periodically calculating the updated estimated energy consumption value for the received query. As such, the autonomic query governor 186 mitigates the wasteful usage of processing resources on the query governor system 170.
In addition to managing query execution based on the estimated energy consumption from executing queries, embodiments of the invention may be further configured to manage query execution based on the monetary cost of energy consumed in executing queries. FIG. 5 is a block diagram illustrating an exemplary computer memory of the query governor system of FIGS. 1A-1B, according to one embodiment of the invention. As shown, the memory 178 contains an operating system 180, an autonomic query governor 186, a power pricing structure 500, historical power usage data 505, and a DBMS 182. The DBMS 182 includes a database 184. The power pricing structure 500 may generally contain information on the price per unit of power consumption. In one embodiment of the invention, the power pricing structure 500 further contains information on the price per unit of power consumption over time. The historical power usage data 505 generally contains data on the amount of power consumed by previously executed queries.
FIG. 6 is a graph showing an exemplary power pricing structure, according to one embodiment of the invention. In the depicted example, the graph 600 represents a power pricing schedule 500 for a business that owns a number of solar panels, and as such is able to operate its query governor system 170 using solar power during the hours of 9:00 am and 4:00 pm. As shown, the graph 600 includes three pricing levels 620. Each pricing level 620 corresponds to a price 622 per unit of power and a time range. The time range may be specified by two time values 624. For example, the time range may include a start time value 624 and an end time value 624. Thus, for example, pricing level 6201 corresponds to a price 6221 of $10.00 per unit of power, and a time range beginning at start time midnight 6241 and end time 9:00 am 6242. As a second example, pricing level 6202 corresponds to a price 6222 of $5.00 per unit of power, and a time range beginning at start time 9:00 am 6242 and end time 4:00 pm 6243. Thus, FIG. 6 shows an exemplary power price schedule 500 where the price for power varies depending on the time of day. Furthermore, although the price of power in this example varies because of solar power, other factors may cause the price of power to shift depending on the time of day. For instance, a power company may charge a premium for power usage during peak hours, but may charge a reduced rate for power usage during off-peak hours.
According to embodiments of the invention, the autonomic query governor 186 may use the power pricing structure 500 to calculate an estimated monetary cost for executing a particular query. As an example, assume that the query governor 186 estimates that a particular query will consume 5 units of power to execute. Thus, for example, if the query is to be executed at 1:00 pm, the query governor 186 may use the power pricing structure 500 to determine that the query will cost $25.00 to execute, since the power pricing structure indicates that the price per unit of power at that time is $5.00, and the query requires an estimated 5 units of power to execute. As a second example, if the exact same query is received at 1:00 am, the query governor 186 may use the power pricing structure 500 to determine that the query will cost $50.00 to execute, since the power pricing structure indicates that the price per unit of power at that time is $10.00, and the query requires an estimated 5 units of power to execute. Thus, according to embodiments of the invention, the query governor 186 may be configured to operate based on at least one of energy consumption and monetary cost. Furthermore, although the concepts of energy consumption and monetary cost of energy consumption are related, the two metrics are not the same.
The flowchart and block diagrams in the Figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present invention. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware-based systems that perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
While the foregoing is directed to embodiments of the present invention, other and further embodiments of the invention may be devised without departing from the basic scope thereof, and the scope thereof is determined by the claims that follow.

## Claims

1. A computer-implemented method of managing the execution of a query, comprising:
receiving a query to be executed;
calculating an initial energy consumption value for the received query, wherein the initial energy consumption value represents a first estimated amount of energy that will be consumed when the query is executed;
upon determining the initial energy consumption value does not exceed a first threshold amount of energy, executing the query by operation of one or more computer processors;
while the query is executing, calculating an updated energy consumption value for the received query, wherein the updated energy consumption value represents a second estimated amount of energy that will be consumed in executing the query; and
upon determining that the updated energy consumption value exceeds a second threshold amount of energy, halting execution of the query.

2. The method of claim 1, wherein calculating an updated energy consumption value for the received query further comprises: dividing the received query into a plurality of query portions; and calculating a partial energy consumption value for each query portion in the plurality of query portions.

3. The method of claim 1, wherein calculating an initial energy consumption value for the received query is based on at least one of (i) historical data collected from previously executed queries, (ii) a value in the received query, and (iii) collected metadata describing the received query.

4. The method of claim 1, wherein the query is received from a user, and further comprising: upon halting the execution of the query, returning a message to the user indicating that execution of the query was halted.

5. The method of claim 1, wherein the query is received from a user, and further comprising: upon halting the execution of the query, sending the query to another computer system for execution.

6. The method of claim 1, further comprising:
calculating a monetary cost value for executing the received query; and
if the calculated monetary cost value exceeds a predetermined threshold cost value, halting the execution of the query.

7. The method of claim 1, wherein the first threshold amount of energy is based on at least one of (i) a predetermined threshold value, (ii) an origin of the received query, and (iii) a priority value associated with the received query.

8. The method of claim 1, further comprising resuming the execution of the halted query.

9. A system, comprising:
a computer processor; and
a memory containing a program that, when executed on the computer processor, performs and operation for managing the execution of a query, comprising:
receiving a query to be executed;
calculating an initial energy consumption value for the received query, wherein the initial energy consumption value represents a first estimated amount of energy that will be consumed when the query is executed;
upon determining the initial energy consumption value does not exceed a first threshold amount of energy, executing the query,
while the query is executing, calculating an updated energy consumption value for the received query, wherein the updated energy consumption value represents a second estimated amount of energy that will be consumed in executing the query; and
upon determining that the updated energy consumption value exceeds a second threshold amount of energy, halting execution of the query.

10. The system of claim 9, wherein calculating an updated energy consumption value for the received query further comprises: dividing the received query into a plurality of query portions; and calculating a partial energy consumption value for each query portion in the plurality of query portions.

11. The system of claim 9, wherein calculating an initial energy consumption value for the received query is based on at least one of (i) historical data collected from previously executed queries, (ii) a value in the received query, and (iii) collected metadata describing the received query.

12. The system of claim 9, wherein the query is received from a user, and the operation further comprising: upon halting the execution of the query, returning a message to the user indicating that execution of the query was halted.

13. The system of claim 9, wherein the query is received from a user, and the operation further comprising: upon halting the execution of the query, sending the query to another computer system for execution.

14. The system of claim 9, further comprising:
calculating a monetary cost value for executing the received query; and
if the calculated monetary cost value exceeds a predetermined threshold cost value, halting the execution of the query.

15. The system of claim 9, wherein the first threshold amount of energy is based on at least one of (i) a predetermined threshold value, (ii) an origin of the received query, and (iii) a priority value associated with the received query.

16. The system of claim 9, the operation further comprising resuming the execution of the halted query.

17. A computer program product for managing the execution of a query, comprising:
a computer-readable storage memory having computer readable program code embodied therewith, the computer readable program code comprising:
computer readable program code to receive a query to be executed;
computer readable program code to calculate an initial energy consumption value for the received query, wherein the initial energy consumption value represents a first estimated amount of energy that will be consumed when the query is executed;
computer readable program code to, upon determining the initial energy consumption value does not exceed a first threshold amount of energy, execute the query;
computer readable program code to, while the query is executing, calculate an updated energy consumption value for the received query, wherein the updated energy consumption value represents a second estimated amount of energy that will be consumed in executing the query; and
computer readable program code to, upon determining that the updated energy consumption value exceeds a second threshold amount of energy, halt execution of the query.