The present invention generally relates to database management, and more particularly, to managing query execution using a query governor.
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 or requests may take a substantial amount of time and resources to execute. As such, database administrators may wish to control how long queries on a database system may execute.
Embodiments of the invention provide a method, product and system for managing query execution. The method, product and system include receiving a query for processing from a requesting entity. Additionally, the method, product and system include calculating an estimated execution time for executing the received query. The estimated execution time approximates an amount of time the received query will take to execute. A maximum allowable runtime for the received query is then determined. The method, product and system include also include adjusting an amount of memory compression used in executing the received query, based at least in part on the estimated execution time and the maximum allowable runtime for the received query. The query is then executed using the adjusted amount of memory compression.
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.
Since all computers have a limited amount of system resources for use in running programs, proper resource management is important to ensure that these limited resources are effectively utilized. To this end, in a database system, database administrators may wish to restrict how long a particular query may run when executed. That is, if executing a particular query would tie up system resources for an excessive amount of time, to the detriment of the execution other queries and tasks on the system, the database administrators may wish to reject the query for execution. Such a rejection may be definitive (e.g., a message may be returned to the requesting entity, explaining the query was denied for processing) or the execution may be delayed to another time (e.g., the system may process the query once system resources become idle). This ensures that no single database query may monopolize the resources of the system.
Although the memory resources of a computer may be fixed, one technique for effectively increasing the memory resources is by compressing data stored therein. For example, assume a particular file has a storage size of 100 megabytes. If the particular file is then read into system memory, it will consume 100 megabytes of space in memory, but if the particular file is compressed at a compression rate of 50%, the compressed file will only consume 50 megabytes of space in memory. One example of such a memory compression technique is the Active Memory Expansion component available on POWER7™ platforms by International Business Machines (“IBM”). Although such a technique may increase the time required to process requests using the compressed data, because additional processing resources are used to compress and decompress the data, in many situations, the processing costs may be outweighed by the gains in memory capacity.
Embodiments of the invention may receive a query for processing from a requesting entity and, responsive to receiving the query, may calculate an estimated execution time for executing the query. The estimated execution time generally reflects an approximation of how long the query will take to execute. Furthermore, embodiments may estimate this time using historical data, collected from processing previous queries. Embodiments may then determine a maximum allowable runtime for the query. Such a maximum allowable runtime may be a predetermined value applied to all queries, or may be determined based on specific attributes associated with the query. Upon determining the maximum allowable runtime for the query, embodiments may optimize the query by adjusting an amount of memory compression used in processing the query. The optimization may be based on the estimated execution time and the maximum allowable runtime for the received query. The optimized query may then be executed to produce query results, which may in turn be returned to the requesting entity.
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., a database management system or “DBMS”) or related data available in the cloud. For example, the DBMS could execute on a computing system in the cloud and receive queries pertaining to one or more databases managed by the DBMS. In such a case, a memory compression query governor 182 could monitor incoming queries and, for each query, calculate an estimated execution time for executing the query. The query governor 182 may also determine a maximum allowable runtime for the query, and may adjust an amount of memory compression used in processing the query based on the estimated execution time and the maximum allowable runtime for the query. Doing so allows a user to submit queries from any computing system attached to a network connected to the cloud (e.g., the Internet), and helps to ensure no single query consumes an impermissible amount of system resources during execution.
Referring now to
Generally speaking, any requesting entity (i.e., different query types) 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 database server 170 may execute the request on a database specified in the request, and then return a result of the executed request.
According to one embodiment of the invention, upon receiving a query for processing, a query governor on the query governor system 170 may calculate an estimated execution time for the received query. The estimated execution time generally reflects an amount of time it will take the DBMS to execute the received query. The query governor may calculate the estimated execution time using historical data collected from processing previous queries. As an example, assume that three previous queries containing SELECT statements for a particular database table took 15 seconds, 20 seconds and 25 seconds to execute. If the query governor system 170 then receives another query containing a SELECT statement for the particular database table, the query governor may estimate that the query will take 20 seconds to execute (i.e., the average of the three previous execution times).
Once the estimated execution time is calculated, the query governor may then determine a maximum allowable runtime for the query. Generally, the maximum allowable runtime specifies a threshold amount of the time that the query should finish executing within. In one embodiment, the user or application submitting the query may specify the maximum allowable runtime as part of the query. For example, the query may include a SQL tag specifying the maximum allowable runtime. In another embodiment, the query governor may retrieve the maximum allowable runtime associated with the query from one or more configuration files. Upon determining the maximum allowable runtime for the query, the query governor adjusts an amount of memory compression that will be used in processing the query, based on the estimated execution time and the maximum allowable runtime for the query. That is, as discussed above, the more memory compression that is used in processing the query, the longer the query will take to process, since additional processing resources are consumed in compressing and decompressing the data. Accordingly, the query governor may adjust the amount of memory compression to an amount where the query may still execute within the maximum allowable time. The DBMS may then execute the query using the adjusted amount of memory compression, and once the query is executed, any results produced from executing the query may be returned to the requesting entity from which the query was received.
Advantageously, by doing this, embodiments of the invention may minimize the amount of memory that individual queries may consume on the database systems, while ensuring that the queries still finish executing within the maximum allowable runtime. By doing this, embodiments may prevent a situation where a particular query consumes a substantial portion of the system resources, to the detriment of other queries and tasks on the database systems. Furthermore, embodiments of the invention may manage query execution in a way that does not simply reject the query for processing. Rather, embodiments of the invention may still process a query whose initial estimated execution time exceeds the maximum allowable runtime by using reducing the amount of memory compression used in processing the query. By doing this, embodiments process the received query while still minimizing memory usage on the database systems.
Illustratively, memory 128 contains a client application 130 and an operating system 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 130 is generally capable of generating database queries. Once the client application 130 generates a query, the query may be submitted to a server (e.g., DBMS 180) for execution, using the network 150. The operating system 132 may be any operating system capable of performing the functions described herein.
The database server 170 contains a computer processor 172, storage media 174, I/O devices 176, memory 178 and a network interface 186. Computer processor 172 may be any processor capable of performing the functions described herein. As shown, storage media 174 contains data pages 175. The data pages 175 generally contain one or more rows of data. In one embodiment of the invention, data contained in the data pages 175 is associated with one or more key values in the database 184. I/O devices 226 may represent a variety of input and output devices, including keyboards, mice, visual displays, printers and so on. The database server 170 may connect to the network 150 using the network interface card 186. 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 185 and a database management system (hereinafter “DBMS”) 180. 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 180 contains a memory compression query governor 182 and a database 184. The operating system 185 may be any operating system capable of performing the functions described herein.
As discussed above, when the DBMS 180 receives a query for processing, the query governor 182 may calculate an estimated execution time for processing the query. The query governor 182 may then determine a maximum allowable runtime for the received query. In one embodiment, the maximum allowable runtime is specified as part of the query. In another embodiment, the maximum allowable runtime is specified in a configuration file. The query governor 182 may then optimize the query by adjusting an amount of memory compression used in executing the query. Such optimize may include enabling memory compression for processing the query, if memory compression is disabled, or may include increasing or decreasing the compression rate used in processing the query. Once the query is optimized, the DBMS 180 may execute the query against the database 184 to produce a set of query results. The DBMS 180 may then return the set of query results to the requesting entity from which the query was received.
In one embodiment, the query governor 182 optimizes the query so that the actual execution time of the query is at or near the maximum allowable runtime for the query. By doing this, the query governor 182 may ensure that the query executes in an acceptable amount of time, while minimizing the amount of memory used in processing the query. As discussed above, because additional memory compression may result in additional processing activity, queries executed using a high amount of memory compression may take longer to execute than queries executed using a low amount or no memory compression. Thus, by adjusting the amount of memory compression so that the execution time of the query is at or near the maximum allowable runtime, the query governor 182 may conserve memory resources on the query governor system 170 while still ensuring that queries execute in an acceptable amount of time.
In one embodiment, the query governor 182 may consider other factors when determining the maximum allowable runtime for the query. Such factors may include, without limitation, the origin of the query, a priority value associated with the query, and a class of the query. For instance, assume that there are two applications which submit queries to the DBMS 180: a mission-critical real-time application with a high priority value and a logging application for collecting database statistics with a low priority value. In such an example, the query governor 182 may assign a lower maximum allowable runtime to queries received from the mission-critical application than for queries received from the logging application. The DBMS 180 may accordingly use less memory compression in processing queries received from the higher-priority mission-critical application and accordingly expedite the processing of these queries. That is, because the use of memory compression may consume additional processing resources on the database systems, queries that are processed using a greater amount of memory compression may take longer to process than queries processed using a lesser amount or no memory compression. Thus, by setting a lower maximum allowable runtime for the processing of queries received from higher-priority application, the query governor 182 may process these queries more quickly. At the same time, the query governor 182 may set a higher maximum allowable runtime for the processing of queries received from the lower-priority application, in order to use memory compression techniques to conserve system memory in executing these queries.
The memory 1782, in contrast, contains an uncompressed portion 2102, a compressed portion 2202, an expanded portion 2302 and an unused portion 2402 of memory. In this example, the memory 1782 effectively contains the same data as the memory 1781, but does so using memory compression. Thus, in the depicted example, the uncompressed memory 2102 relates to a portion of the uncompressed memory 2101. Likewise, the compressed memory 2202 relates to the remaining portion of the uncompressed memory 2101. That is, due to the use of memory compression, the data from uncompressed memory 2101 may be stored in uncompressed memory 2102 and compressed memory 2202 which, when combined, are smaller in size than the uncompressed memory 2101.
Advantageously, by using memory compression, embodiments of the invention may effectively create the expanded memory pool 2302, which may in turn be used to store additional data, either compressed or uncompressed. For example, a DBMS may use the expanded memory 2302 to store additional data during fetches to a storage media 174. Additionally, such memory compression not only expands available memory, but because the expanded memory 2302 may be used for other purposes, may also reduce paging on the database system as a result. Advantageous, because paging often leads to a greater delay than compressing and decompressing data, the memory compression may improve the performance of the database system as well. Furthermore, although
The query governor 182 then determines a maximum allowable runtime for the received query (step 330). As discussed above, the maximum allowable runtime generally refers to a threshold amount of time the received query should finish executing within. In one embodiment, the maximum allowable runtime may be specified (e.g., by the requesting entity) in the received query. In such an embodiment, the maximum allowable runtime may be defined using one or more SQL tags in the received query. In another embodiment, the maximum allowable runtime may be defined in a configuration file.
Additionally, the query governor 182 may determine the maximum allowable runtime based on a priority level or a class of the query. For example, assume a particular DBMS receives queries that may be classified as either high priority, medium priority or low priority. If the query governor 182 determines a particular received query is a high priority query, the query governor 182 may assign a relatively low maximum allowable runtime to the query. That is, because the query is of high importance, the query should generally be processed in a short amount of time. As a second example, if the query governor 182 determines a second received query is a low priority query, the query governor 182 may assign a relatively high maximum allowable runtime to the second query. That is, since the query is of low priority, it may be less important to process the query in a short amount of time, as compared to the processing of the high priority query. Furthermore, in one embodiment, the maximum allowable runtime is specified as a flat amount of time (e.g., 60 seconds). In another embodiment, the maximum allowable runtime is determined using an execution time adjustment threshold, which specifies a maximum percentage that the estimated execution time may be increased (e.g., 20%).
Once the maximum allowable runtime is determined, the query governor 182 adjusts the amount of memory compression used to process the received query (step 335). As discussed above, generally speaking, the more memory compression used in processing a particular query, the longer the processing of the particular query will take. That is, because the database system (e.g., query governor system 170) uses additional processing resources compressing and decompressing data when memory compression is enabled, these additional processing resources may not be used in the processing of the query. Accordingly, if the query governor 182 determines that the estimated execution time for a query is substantially less than the maximum allowable runtime for the query, the query governor 182 may increase the amount of memory compression used in processing the query. In one embodiment, the query governor 182 may increase the amount of memory compression (and thus the execution time of the query) until the estimated execution time for the query is at or near the maximum allowable runtime. By doing this, the query governor 182 may conserve the memory resources of the database system, while ensuring that the query will still execute within the maximum allowable runtime.
Once the amount of memory compression is adjusted, the DBMS 180 executes the query using the adjusted memory compression rate (step 340). The DBMS 180 may then return a set of query results produced by executing the query to the requesting entity from which the query originated (step 345). Once the set of query results are returned, the method 300 ends. One advantage to the method 300 is that because the amount of memory compression used in processing queries is adjusted based at least in part on a maximum allowable runtime for the query, embodiments may conserve system resources (i.e., memory 178) while still ensuring that queries are executed in an acceptable amount of time (i.e., within the maximum allowable runtime).
In contrast, the second timeline 415 represents a high priority query with a total execution time of 6 seconds. As shown, the non-shaded portion 4052 represents the initial estimated execution time for the query, and the shaded portion 4102 represents the additional execution time added due to the use of memory compression. Furthermore, assume that the query governor 182 is configured to use an execution time adjustment threshold of 20% for high priority queries. In this example, because the query represented by the timeline 415 is a high priority query, the query governor 182 has determined that the maximum allowable runtime for the query is 6 seconds (a percentage increase of 20% from the original 5 second estimated execution time). That is, because the query is a high priority query, the query governor 182 may minimize any delay to the processing of the query by using a lower maximum allowable runtime. Accordingly, the query governor 182 may determine that less memory compression (relative to the query depicted by timeline 400) should be used for processing the query depicted by the timeline 415.
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.