# Patent

## Title
Method and system for spilling from a queue to a persistent store

## Abstract

Techniques for managing memory usage of a processing system by spilling data from a memory to a persistent store based upon an evict policy are provided. A triggering event is detected. In response to the triggering event and based on the evict policy, it is determined whether data from the memory of the processing system is to be spilled to the persistent storage. The determination is made by comparing a level of free memory of the processing system with a threshold specified by the evict policy. The data is evicted from the memory.

## Background
CROSS-REFERENCES TO RELATED APPLICATIONS
The present appilacation incorporates by reference for all purposes the entire contents of the following related appilications filed concurrently with the present appilication:
(1) U.S. patent application Ser. No. 12/396,464, filed Mar. 2, 2009, entitled “Framework for Dynamically Generating Tuple and Page Classes,”; and
(2) U.S. patent application Ser. No. 12/395,871, filed Mar. 2, 2009, entitled “Infrastructure for Spilling Pages to a Persistent Store,”.
BACKGROUND OF THE INVENTION
Embodiments of the present invention relate to memory management, and more specifically to techniques for spilling from memory to a persistent store based upon an evict policy.
In applications such as stock quote monitoring, automobile traffic monitoring, and data sensing, data is generated in the form of a stream of events over time. A data stream, also referred to as an event stream, is a real-time, continuous, sequence of events. Examples of sources that generate data streams include sensors and probes (e.g., RFID sensors, temperature sensors, etc.) configured to send a sequence of sensor readings, financial tickers, network monitoring and traffic management applications sending network status, click stream analysis tools, and others. The term “events” are used interchangeably with “tuples”. As used herein, tuples of a stream have the same set of attributes but not necessarily the same attribute values for those attributes. Each tuple is also associated with a particular time. A tuple may be considered to be logically similar to a single row or record in a relational database.
Processing the data streams is often referred to as “stream processing.” The data streams may be processed to detect complex patterns, event correlations, relationships between events, etc. For example, a sensor placed at a particular section of a highway may output a data stream comprising information detected by the sensor about automobiles that pass the particular section. A data stream output by the sensor may include information such as the type of automobile, the speed of the automobile, the time that the automobile was on the particular section, and other like information. This data stream may then be processed to determine heavy traffic congestion conditions (indicated by slow average speeds of automobiles), and other traffic related conditions or patterns.
In traditional database systems data is stored in a database, for example in tables in a database. The data stored in a database represents a finite data set against which queries and other data manipulation operations may be performed using a data management language such as SQL. SQL and other traditional database management tools and algorithms are designed based upon the assumption that the tools and algorithms are executed against a potentially large, but finite, collection of data. Such traditional tools and algorithms are unable to handle data streams, as described above, due to the possibly continuous and unbounded nature of data received via the data streams monitored system. Further, storing the events data in a table is impractical due to the large amounts of data that is continually received and the fast frequency at which the data may be received. Due to the ever increasing number of applications that transmit data in the form of a data stream, the ability to process such data streams has become important.
BRIEF SUMMARY OF THE INVENTION
Embodiments of the present invention provide memory management techniques for handling processing of data streams, including bursty data streams. In one embodiment, an evict policy is provided for automatically controlling the eviction of data related to incoming data streams from processing memory (e.g., RAM) to persistent storage (e.g., disk). For example, pages, which are comprised of tuples received by a processing system via one or more data streams, have been buffered in a processing memory of the processing system may be spilled from the processing memory to persistent storage based upon memory usage levels, as specified by the evict policy. This automatic spilling of data from processing memory to persistent store enables the processing system to more efficiently handle processing of data streams, including bursty data streams without significantly hampering the performance of the processing system.
Embodiments of the techniques provided herein enable the event processing server to run smoothly even when the rate at which events arrive suddenly spike, if the memory requirement of the tuples and subsequent processing is more than the memory can manage or if the window size is larger than what is supported by the memory.
In one embodiment, techniques for managing memory usage of a processing system by spilling data from a memory to a persistent store based upon an evict policy are provided. A triggering event is detected. In response to the triggering event and based on the evict policy, it is determined whether data from the memory of the processing system is to be spilled to the persistent storage. The determination is made by comparing a level of free memory of the processing system with a threshold specified by the evict policy. The data is evicted from the memory.
A further understanding of the nature and the advantages of the inventions disclosed herein may be realized by reference of the remaining portions of the specification and the attached drawings.



BRIEF DESCRIPTION OF THE DRAWINGS
The invention may best be understood by reference to the following description taken in conjunction with the accompanying drawings in which:
FIG. 1 is a simplified block diagram of a system that incorporates an embodiment of the present invention.
FIG. 2 depicts a simplified block diagram of EPS that is configured to spill streams to a persistent store in accordance with embodiments of the present invention.
FIG. 3A depicts a simplified method for spilling pages of tuples to disk storage according to an embodiment of the present invention.
FIG. 3B depicts another simplified method for spilling pages of tuples to disk storage by state determination using an evict policy according to an embodiment of the present invention.
FIG. 3C depicts another simplified method for spilling pages of tuples to disk storage by action determination using an evict policy according to an embodiment of the present invention.
FIG. 4A depicts an example of a state diagram according to an evict policy in accordance with embodiments of the present invention.
FIG. 4B depicts an example of a diagram correlating a level of free memory and states of an evict policy in accordance with embodiments of the present invention.
FIG. 5 depicts a simplified block diagram of a page manager system in accordance with embodiments of the present invention.
FIG. 6 is a block diagram illustrating components of an operating environment in which various embodiments of the present invention may be implemented.
FIG. 7 illustrates a computer system in which various embodiments of the present invention may be implemented.



DETAILED DESCRIPTION OF THE INVENTION
In the following description, for the purposes of explanation, specific details are set forth in order to provide a thorough understanding of embodiments of the invention. However, it will be apparent that the invention may be practiced without these specific details.
A data stream or event stream is a real-time, continuous, sequence of events. The stream thus represents sets of data. The elements in the data stream can be viewed as a series of events and accordingly the data stream is also referred to as an event stream. Events may include temperature readings from a sensor such as 10°, 15°, 20°, etc. When a data stream is received by a system that is configured to process the data stream, referred to as an event processing server (EPS), the data stream is stored in a memory, such as random access memory (RAM), of the EPS as a sequence of <tuple, timestamp> pairs. The timestamps associated with tuples define an order in which the tuples are received. Timestamps in the data stream reflect an application's notion of time. The timestamp is part of the schema of the data stream, and two or more tuples can have the same timestamp or different timestamps.
An EPS may receive data streams either using a push or pull paradigm from one or more sources. In the case of a pull paradigm, the EPS pulls the data streams from a source as needed, and as such, the amount of data received by the EPS is automatically controlled by the EPS itself. On the other hand, in the more common push paradigm, the EPS is agnostic to the existence of the source, and cannot control the data streams and the frequency at which data is received by the EPS. Since the events received in a data stream are typically stored in the processing memory (e.g., RAM) of the EPS for processing, uncontrolled receipt of data streams may cause the memory to quickly fill up, especially if the data stream is a bursty stream. As a result, the EPS may face a memory shortage thereby severely hampering the performance of the event processing system and may even cause it to crash.
Embodiments of the present invention provide memory management techniques for handling processing of data streams, including bursty data streams. In one embodiment, an evict policy is provided for automatically controlling the eviction of data related to incoming data streams from processing memory (e.g., RAM) of the EPS to persistent storage (e.g., disk). For example, tuples received by an EPS via one or more data streams and which have been buffered in a processing memory of the EPS may be spilled from the processing memory to persistent storage based upon memory usage levels, as specified by the evict policy. This automatic spilling of data from processing memory to persistent store enables the EPS to more efficiently handle processing of data streams, including bursty data streams without running into any memory availability problems or without significantly hampering the performance of the EPS.
FIG. 1 is a simplified block diagram of a system 100 that incorporates an embodiment of the present invention. As depicted in FIG. 1, system 100 includes an event processing server (EPS) 110 that is configured to receive one or more data streams 104, 106, and 108. Streams 104, 106, and 108 may be received from one or more sources including a database, a file, a messaging service, various applications, devices such as various types of sensors (e.g., RFID sensors, temperature sensors, etc.), tickers, etc. In one embodiment of the present invention, event sources are configured to generate data streams 104, 106, 108. Event sources are event-driven applications. The tuples in the one or more streams 104, 106, and 108 are received by EPS 110 in a sequence at specific time points. EPS 110 may receive streams 104, 106, and 108 via a push-based mechanism or a pull-based mechanism or other mechanisms.
EPS 110 may be configured to perform various types of processing on the incoming streams 104, 106, and 108 such as running continuous queries on the incoming data streams, detecting patterns in the incoming events, etc. EPS 110 may generate an output stream of tuples 109 resulting from the processing. For example, output stream 109 may comprise a sequence of tuples resulting from a continuous query applied to one or more of streams 102, 106, and 108.
In the embodiment depicted in FIG. 1, EPS 110 includes memory 140, an eviction engine 130, and a query engine 120. Memory 140 is shown as being contained within the EPS 110, but may be located elsewhere in other embodiments of the invention. In one embodiment, memory 140 may be random access memory (“RAM”) 141.
In a typical scenario, the data received via the data streams is stored in memory 140 awaiting processing of the data. Memory 140, for example RAM, is configured to store <tuple, timestamp> pairs. In addition to the tuples, data structures associated with the tuples may also be stored. These data structures may include, for example, a queue, a store, a synopsis, and overhead for these structures in memory. A queue passes state data of the tuple from one operator to another, for example during execution of a query plan. A store is a data structure which maintains intermediate states of the tuple for performance of operations by operators. In one embodiment of the present invention, the store data structure is optimized to store specific types of state data, for example in a single list or a double list. As such, memory 140 not only stores the incoming data stream, but also the workload during processing of the tuples, such as during execution of a query on the tuples.
In one embodiment, events received by EPS 110 may be stored in one or more queues in memory 140. For example, as depicted in FIG. 1, memory 140 comprises buffer queues Q1, Q2, and Q3. The buffer queues may be implemented as First In First Out (FIFO) queues. The queues may be single reader-writer queues. A buffer queue may be used as a spill-over queue to handle bursty streams, for example, by storing the in-coming tuples. The spill-over queue holds data that may be spilled to disk.
Evict Policy 131 is configured to store information specifying how spilling is to be performed. In one embodiment, evict policy 131 specifies a state diagram comprising one or more states, criteria for transitioning between the states, and actions to be performed in each state. For example, evict policy 131 may identify a Normal state in which no spilling is performed. Accordingly, if EPS 110 is in this state, no spilling is performed. Other states may be specified in which spilling is performed. The nature or type of spilling performed in each state may be different. Actions may include spill or no spill. In one embodiment, the level of free memory available on EPS 110 determines the state of EPS 110. Evict policy 131 is invoked by a triggering event. A free memory level is the measurement of memory that is not in use at the time of measurement. In one embodiment, a weighted average of the consumption of free memory may be used. The level of free memory may be determined by measuring, for example, memory 140 and/or other memory units associated with EPS.
Eviction engine 130 is configured to enforce evict policy 131. Eviction engine 130 is configured to determine the state of EPS 110 at a point in time, monitor a level of free memory of EPS 110 to determine if a state transition is necessary, perform the actions associated with that state. Actions may include spilling data from memory 140 to persistent storage (e.g. disk) 150. As data is evicted, free space is made available in memory 140. In one embodiment of the present invention, the data that is evicted is a page. In one embodiment of the present invention, individual tuples may be stored as a collection in a page structure within memory 140. A page may be an array of tuples or other similar construct.
Enforcement of evict policy 131 may be triggered upon the occurrence of one or more events such as when a tuple is queued in a buffer queue (an enqueue event), when a tuple is removed from a buffer queue (a dequeue event), and other events. In one embodiment, the triggering event is configurable. For example, upon occurrence of an enqueue event, eviction engine 130 is configured to determine a state in which EPS 110 is operating, the state being one of the states specified by evict policy 131. Eviction engine 130 is configured to determine whether EPS 110 remains in the same state or to transition EPS 110 into a new state based on criteria for transition, which is specified by evict policy 131. Eviction engine 130 is also configured to perform actions that are associated with the new state, if a state transition occurred, or the same state, if no state transition was performed. If the new state or the same state is a spill state, spilling is performed from one or more queues. In one embodiment, the spilling is performed in a synchronous mode or asynchronous mode. In the synchronous mode, the action is performed using the thread from a caller (i.e., caller thread). In the asynchronous mode, the action is performed using a separate and independent thread which is asynchronous to the caller thread. In one embodiment the actions may be performed by eviction engine 130 or eviction engine 130 may facilitate the performance of the actions.
Disk 150 provides a persistent memory for storing pages and tuples that are spilled from memory 141 according to evict policy 131. Disk 150 may be internal or external (as shown in FIG. 1 to EPS 110. In general, disk 150 may be in a location accessible to eviction engine 130 for purposes of spilling pages from memory 140.
Evict policy 131 enables more efficient memory management such that EPS 110 is able to handle bursty streams without adversely impacting performance and enables adequate free space in memory 140 to be available for the workload. While the evict policy is being enforced, both of the evicted and non-evicted tuples may be processed by query engine 120 such as by running a continuous query, which is a long-running query, on the incoming data stream, etc. After processing, output data stream 109 is provided by the EPS 110.
By optimizing EPS 110 by performing management techniques, the performance of EPS 110 is greatly enhanced. For example, with more available space in memory 140, EPS 110 is able to handle faster streams, larger window sizes, and workloads which exceed the maximum size of memory 140.
FIG. 2 depicts a simplified block diagram of EPS 110 that is configured to spill streams to a persistent store in accordance with embodiments of the present invention. The components of EPS 110 as depicted in FIG. 2 may be implemented in software (e.g., code, instructions, program) executed by a processor, hardware, or combinations thereof.
EPS 110 is configured to receive data streams 104, 106, 108. EPS 110 is comprised of memory 140, query engine 120, and eviction engine 130. Memory 140 is configured to store pages, which are collections of tuples. Memory 140 may store a state of a tuple, such as data structures associated with the tuple, in a buffer queue Q2.
At step 1, a triggering event is determined. Pages which are stored in buffer queue Q2 may be evicted from memory 140 and written to disk 150 based on evict policy 131, as will be described below. In one embodiment of the present invention, a separate queue may be provided for each data stream for buffering tuples received via the data stream. In alternative embodiments, other buffering techniques may be used such as a single queue may be shared by different data streams, or tuples from one stream may be buffered in different queues. The triggering event invokes evict policy 131. Eviction engine 130 is configured to enforce a policy for eviction.
At step 2, a check eviction procedure is invoked by eviction engine 130. Eviction engine 130 uses information specified by evict policy 131 to carry out the check eviction procedure. Evict policy 131 specifies states of EPS, criteria for transitioning between the states, and actions to be performed in each state. To carry out the check eviction procedure, eviction engine 130 determines the state of EPS 110 at a current point in time, determines if a state transition is necessary to a new state, determines an eviction threshold that is associated with the current state or the new state. An eviction threshold is a threshold at which eviction should occur. The eviction threshold is compared to a free memory level. Where the level of free memory satisfies the eviction threshold, a TRUE value is returned, indicating that it is time for an eviction to occur. A FALSE value is returned if the eviction threshold is not satisfied, indicating that eviction is not needed. In one embodiment of the present invention, a more complex threshold methodology can be implemented. Before the triggering event is performed (i.e., enqueue, dequeue, etc.), the result of the check eviction procedure is determined.
Query engine 120 is configured to evict tuples according to evict policy 131 and to run continuous queries on the data sets. Query engine 120 includes page manager 220 and queue evictor 250. At step 3, where the check eviction process indicates that eviction is not required, that indication is made to page manager 220.
Page manager 220 is configured to manage pages, and more particularly, to allocate tuples to pages, keeping track of which tuples are allocated to which page, and spill-out the pages as needed in a synchronous manner. In one embodiment, page manager 220 is implemented as a simple page manager that maintains a list of simple pages. A simple page may be an array of the same type of tuple class. When it is determined that a page should be spilled, that page may be spilled as soon as it is full.
In one embodiment, upon receiving a tuple, an enqueue request is determined. After performing a spilling action, page manager 220 performs the enqueue request on the received tuple. An advance tail process is performed where the pointers associated with the tail of the queue are updated to point to the last tuples of the queue.
A process may be provided for checking the evict policy. Where the check eviction process indicates that eviction is required, at step 4, a run eviction procedure is invoked by eviction engine 130. In one embodiment, a scheduler may invoke the run eviction command. Thus far, evict policy 131 has been used to determine if an eviction is needed. Evict policy 131 may also specify actions that are associated with the current state or the new state. The actions may dictate from which queue to spill from if there are multiple buffer queues in memory 140 and may dictate how to spill, i.e., whether the spilling is to be accomplished via a synchronous mode or an asynchronous mode.
In one embodiment of the present invention, evict policy 131 may also specify candidates for eviction (eviction candidates). An eviction candidate may be a page, which is a collection of tuples. As such, evict policy 131 may dictate which page to evict within a particular queue. Under one approach, the page at the tail end of the queue (from which spilling occurs) is evicted. Other more complicated methods may also be implemented such as the methods described in U.S. patent application Ser. No. 12/395,871, filed Mar. 2, 2009, entitled “Infrastructure for Spilling Pages to a Persistent Store,” .
At step 5, eviction engine 130 determines a location of the eviction candidates in memory and provides the location information to page manager 220. The location information may include a page location.
Where evict policy 131 indicates that the mode of spilling is via synchronous eviction, step 6S is performed. At step 6S, page manager 220 uses the page location information to spill the page identified at step 5 from memory 140 and stores the page to disk 150. It should be noted that the page identified at step 5 is not spilled until it is full. Other embodiments are also contemplated. Since the action is performed using the thread from the caller, spilling is synchronized with the caller thread and the event source can be indirectly slowed-down. Once the page has been spilled, the thread returns back to the caller.
On the other hand, where evict policy 131 indicates that the mode of spilling is via asynchronous eviction, steps 6A1 and 6A2 are performed. In the asynchronous mode, queue evictor 250 is configured to perform the spilling, instead of performing the spilling directly by page manager 220. At step 6A1, the page location information is provided from page manager 220 to queue evictor 250. The thread upon which page manager 220 operates returns back to the caller. Queue evictor 250 operates on its own thread and at step 6A2, spills a page out to disk 150 at time that is asynchronous to the caller thread. For example, queue evictor 250 may perform the spilling action at a later point in time.
It should be noted that either one or a combination of the synchronous eviction mode or the asynchronous eviction mode may be implemented. In one embodiment of the present invention, a spilling thread uses a wait and notify scheme, for example. Since queue evictor 250 runs on its own thread (i.e., spilling thread), the asynchronous mode enables the spilling thread to be completed at any time.
In one embodiment of the present invention, evict policy 131 is invoked on dequeue by the stream source. On dequeue, a tuple is read from the front (head) of buffer queue Q2, or from disk 150. Dequeue is a triggering event for invoking evict policy 131. Before dequeue is performed, the check eviction process is invoked in the evict policy 131. The same or similar processing steps that were previously described may also be performed in the context of dequeue. In one embodiment of the present invention, although the check eviction process is invoked at both enqueue and dequeue, the actual eviction is performed on enqueue.
FIG. 3A depicts a simplified method 300 for spilling pages of tuples to disk storage according to an embodiment of the present invention. The processing depicted in FIG. 3A may be performed by software (e.g., code, instructions, program) executed by a processor, hardware, or combinations thereof.
At step S1, a triggering event is detected. Triggering events may include an enqueue or dequeue request for an incoming tuple. Tuples can be stored in a buffer queue within memory of EPS. The buffer queue may be a simple FIFO, reader-writer queue. Before the enqueue or dequeue request is fulfilled, the triggering event invokes an evict policy.
At step S2, it is determined whether spilling should be performed based on an evict policy. The evict policy specifies states, how transitions between states are performed, and actions to be performed in each state. Whether or not spilling should be performed is assessed by determining a current state and determining whether a transition is required to a new state based on a comparison of the level of free memory to a threshold for eviction. If either the new state or the current state (if no transition occurred) is a spill state, it is determined that spilling should be performed. A spill state is a state at which one or more pages are spilled from one or more queues. A Normal state is a state at which no spilling occurs. In other words, non-spill states operate under a memory mode.
If spilling should be performed, processing proceeds to step S3, where it is determined from where and how spilling should be performed. In one embodiment of the present invention, the memory of EPS includes a plurality of queues. In such cases, it is determined from which queue the spilling should occur. It may be determined, using the evict policy, that spilling occurs on one or more queues of the plurality of queues. Since the evict policy may look over all queues or a subset thereof, the queues from which spilling will occur are marked. Marking may be performed in any number of ways, for example by using a spilling flag of a queue. Furthermore, how spilling should be performed may be specified as a synchronous mode or an asynchronous mode.
At step S4, spilling is performed. In one embodiment, a page is evicted from the one or more buffer queues determined from step S3.
FIG. 3B depicts another simplified method 350 for spilling pages of tuples to disk storage by state determination using an evict policy according to an embodiment of the present invention. The processing depicted in FIG. 3B may be performed by software (e.g., code, instructions, program) executed by a processor, hardware, or combinations thereof.
Once the evict policy has been invoked, at step S3-1, a current state of EPS is determined. An evict policy may be implemented for EPS having multiple states, such as a spill state and a non-spill state. The current state is the state of EPS for a current point in time. In one embodiment, the evict policy runs globally (i.e., one instance) within the system.
At step S3-2, a threshold associated with the current state is determined. Which threshold to use is determined by the state of EPS. States may have unique thresholds associated therewith or may share thresholds with other states. In one embodiment of the present invention, the thresholds are configurable. At step S3-3, the threshold is compared to a free memory level. For example, the threshold may be an eviction threshold, which is a threshold at which eviction occurs.
At step S3-4, it is determined whether a transition to a new state is required based on the comparison at step S3-2. A state transition is a transition from one state to another state. For example, if the free memory level satisfies the eviction threshold a state transition is performed at step S3-5. Otherwise, the transition to the new state is not performed and EPS remains in the current state.
FIG. 3C depicts another simplified method 360 for spilling pages of tuples to disk storage by action determination using an evict policy according to an embodiment of the present invention. FIG. 3C may be continued from step S3-5 of FIG. 3B. In one embodiment, whereas the evict policy runs globally within the system in accordance with the steps described with relation to FIG. 3B, queues may run locally in accordance with one or more of the steps described with relation to FIG. 3C.
At step S3-6, an action that is associated with the new state or the current state is determined. The action includes information specifying from which queue the spilling should occur, where there are multiple queues in the memory. The action also includes information about how the spilling should occur, specifically, spilling according to a synchronous mode or an asynchronous mode. Where the new or current state is in a Normal state, it is determined that spilling need not be performed. Where the new state is in a Normal state such as after a transition from a spilling state (i.e., partial spill, full spill, and synchronous spill) to a Normal state, the new state is reset. Resetting may include clearing any spilling flags of the queue.
At step S3-7, a page is evicted synchronously from memory to disk based on the action. At step S3-8, a page is evicted asynchronously from memory to disk based on the action. In one embodiment of the present invention, the unit for eviction is a page. A page is evicted when full under both asynchronous and synchronous modes. Other eviction units are also contemplated, for example, a partially full page can also be evicted.
FIG. 4A depicts an example of a state diagram according to an evict policy in accordance with embodiments of the present invention. An eviction engine may use an evict policy, such as evict policy 131, to determine whether a transition between states is needed, whether spilling is required based on the state, and what actions are to be performed in each state. Actions may include where to evict from and how to evict. The eviction engine is responsible for monitoring memory usage according to the evict policy. As will be described herein, a more complex threshold methodology can be implemented. On a triggering event, the evict policy is invoked.
Normal State
In a Normal state, all queues are running in a memory mode and no spilling is performed. For example, EPS may include three queues operating in the memory mode, represented as follows:
















Ex)
Q1 (NO_EVICT)




Q2 (NO_EVICT)




Q3 (NO_EVICT)










While in the Normal state, EPS may remain in a Normal state or may transition into a partial spill state. EPS remains in a Normal state if the free memory level is greater than an onThreshold. The onThreshold is a threshold that indicates when spilling should start. Satisfaction of the onThreshold results in a determination that it is time to start spilling. EPS transitions into the partial spill state if the free memory level is less than or equal to the onThreshold or otherwise satisfied. In one embodiment of the present invention, the onThreshold is 1⁄3 of the total system memory or 33%. For example, if the free memory level is less than 33% of the total system memory, EPS transitions to the partial spill state. If the free memory is equal to or greater than the onThreshold, no state transition occurs.
Partial Spill State
In the partial spill state, spilling is triggered from the largest queue, where the largest queue has the most number of pages in memory. The other queues run in memory mode. The page at the tail end of the largest queue is spilled when it is full. As previously discussed, checking to determine if an eviction should be done is performed on both enqueue and dequeue. In one embodiment of the present invention, although eviction checking is performed on both enqueue and dequeue, the actual eviction of pages happens on enqueue.
The spilling happens asynchronously by Queue Evictor 250, which operates on its own thread when the page is full. For example, EPS may include one queue operating in the asynchronous eviction mode and two queues operating in memory mode, represented as follows:














Ex)
Q1 - Largest (ASYNC_EVICT)
(FreeMem > OnThreshold)



Q2 (NO_EVICT)
(FreeMem < FullThreshold)



Q3 (NO_EVICT)









While in the partial spill state, EPS may transition into the Normal state, transition into a full spill state, or remain in the partial spill state. EPS transitions into the Normal state if the free memory level satisfies an offThreshold. The offThreshold is a threshold that indicates when spilling should stop. In one embodiment of the present invention, the offThreshold is 1⁄2 of the total EPS memory or 50%. Satisfaction of the offThreshold results in a determination that it is time to stop spilling. For example, if the free memory level is more than 50% of the total system memory, EPS transitions to the Normal state.
EPS transitions into the full spill state if the free memory level satisfies an fullThreshold. The fullThreshold is a threshold that indicates when spilling should be increased. In one embodiment of the present invention, the fullThreshold is 4⁄5 of the total system memory or 20%. Satisfaction of the fullThreshold results in a determination that it is time to increase spilling. For example, if the free memory level is less than 20% of the total system memory, EPS transitions to the full spill state. EPS remains in the partial spill state if the free memory level is less than a fullThreshold and more than an offThreshold.
Full Spill State
In the full spill state, all queues start spilling. The spilling happens asynchronously by Queue Evictor 250. On transition from the partial spill state to the full spill state, all pages in memory for the largest queue are spilled first, as the pages become full. Then, all other queues start spilling if it is determined that the amount of free memory is not under control. For example, EPS may include thee queues operating in the asynchronous eviction mode, represented as follows:














Ex)
Q1 (ASYNC_EVICT)
(FreeMem < FullThreshold)



Q2 - Largest., Evict all pages in




memory (ASYNC_EVICT)




Q3 (ASYNC_EVICT)









While in the full spill state, EPS may transition into the Normal state, transition into a synchronous spill state, or remain in the full spill state. EPS transitions into the Normal state if the free memory level satisfies the offThreshold. EPS transitions into the synchronous spill state if the free memory level satisfies a syncThreshold. The syncThreshold is a threshold that indicates when synchronous spilling should be performed. In one embodiment of the present invention, the syncThreshold is 9/10 of the total system memory or 10%. Satisfaction of the syncThreshold results in a determination that it is time to change spilling to the synchronous mode. For example, if the free memory level is less than 10% of the total system memory, EPS transitions to the synchronous spill state. EPS remains in the full spill state if the free memory level is less than the offThreshold and more than the syncThreshold.
Synchronous Spill State
In the synchronous spill state, all queues start spilling synchronously using page manager 220. As such, the client is blocked when the page is evicted. It is possible that queue evictor 250 may hold many pages because it could not catch up with the intake stream. The synchronous spill state can artificially slow-down the client to fill up the queue fast. Note that even in this mode, the page will not be evicted until it is full. In one embodiment, the size of a page may be changed to a smaller size or each tuple may be spilled in this state. For example, EPS may include three queues operating in the synchronous eviction mode, represented as follows:
















Ex)
Q1 (SYNC_EVICT)
(FreeMem < SyncThrehsold)




Q2 (SYNC_EVICT)





Q3 (SYNC_EVICT)









While in the synchronous spill state, EPS may transition into the Normal state, transition into a partial spill state, or remain in the synchronous spill state. EPS transitions into the Normal state if the free memory level satisfies the offThreshold and it is determined that spilling is not required. EPS transitions into the partial spill state if the free memory level exceeds the fullThreshold. For example, if the free memory level is greater than 20% of the total system memory, EPS transitions to the partial spill state and it is determined that synchronous spilling is no longer needed. EPS remains in the full spill state if the free memory level is less than the offThreshold and more than the fullThreshold.
In one embodiment of the present invention, the thresholds and/or actions are adjustable, for example by a user. This can allow for greater control of the evict policy.
FIG. 4B depicts an example of a diagram correlating a level of free memory and states of an evict policy in accordance with embodiments of the present invention.
At stages 1 and 6, where memory usage is low, EPS operates in a Normal state when a level of free memory measures 100%-50%. EPS operates in a partial eviction state when the free memory level measures 20%-33%, at stages 2 and 5 where the memory usage is increasing and decreasing, respectively. EPS operates in a full eviction state when the free memory level measures 10%-20%, at stage 3 where the memory usage is increasing. At stage 4 where memory usage is at its peak, EPS operates in a synchronous eviction state when the free memory level measures less than 10% and continues in the synchronous eviction state as long as the free memory level is more than 20%.
FIG. 5 depicts a simplified block diagram of a page manager system 500 in accordance with embodiments of the present invention. Page manager system 500 is configured to manage pages in use, and more particularly, to allocate tuples to pages in memory, keeping track of which tuples are allocated to which page, and spill-out the pages as needed.
In one embodiment of the present invention, tuples may be grouped in a page. A page is a structure for storing a collection of tuples. A page may be implemented as an array of tuples or other similar construct. In another embodiment of the present invention, a page may include an individual array for every attribute of an object. For example, as previously described, a tuple may be considered to be logically similar to a single row or record in a relational database and the attributes of the tuple are represented by columns. As such, a page may include an array for every column (i.e., attribute) of the tuple. For example, column 1 might represent an integer, column 2 might represent a float, etc. Each column may be implemented as an individual array, such that array_integer is an array with integer values of multiple tuples and array_float is an array with float values of multiple tuples, for example. The page construct makes manipulation of tuples, including storage and removal of tuples, more efficient. Storage by page, as opposed to storage by individual tuples, decreases overhead by minimizing the disk access.
Page manager system 500 may include page table 510, empty slot list 520, and free page list 530. Page table 510 is configured to keep the pages in use indexed by a page identifier. Page table 510 may be an array of page pointers (PagePtr), or similar construct, which thereby implements the allocation of tuples to pages in memory. The array elements of page table 510 are accessed via a page identifier.
Empty slot list 520 is configured to maintain a list of the empty slots or pages on page table 510. Free page list 530 is configured to maintains a list of pages on page table 510 which have been partially allocated and capable of further allocation. Free page list 530 may be implemented as an array of page pointers. As shown, free page list 530 includes PagePtrs to pages 550, 560, and 570.
In one embodiment of the present invention, an allocation scheme may be implemented by allocating tuples first to a partially allocated page, using the free page list 530. Where a partially allocated page exists, the tuple is allocated to a page at the head of the free page list 530. Partially allocated pages are filled-up until fully allocated. If a page is full and is positioned at the head of the free page list 530, the page is removed from the free page list 530.
Where the free page list 530 indicates that there are no partially allocated pages which are capable of further allocation, a new page may be added. For example, a page from empty slot list 520 may be added to free page list 530 and tuples are allocated to the new page. In another embodiment of the present invention, where the empty slot list 520 is empty and all pages pointed to by page table 510 are completely full, a new page is added, page table 510 is updated to reflect the new page.
The tuple that is to be spilled may be evicted by eviction of the page to which it belongs. As previously described, tuples may be stored in pages in memory when received in a data stream. A free tuple scheme may be implemented such that tuples that have been identified for spilling are evicted from a belonging page in memory. After storing these tuples on disk, these tuples may be evicted or otherwise removed from a belonging page in memory. Where the page is empty, page table 510 is updated with an empty slot and empty slot list 520 is updated. In other embodiments of the present invention, page manager system 500 can support various allocation and free tuple schemes. The default allocation scheme is a “first fit” policy.
In one embodiment of the present invention, a simple page manager may be implemented for a FIFO queue where an entry in the queue is a page. The simple page manager only maintains the head pointer (i.e., page and offset in the page) and the tail pointer. Pages are linked on enqueue and through the advance tail process, the tail pointer is advanced. If the tail page is not full, the offset is increased. Otherwise, a new page is allocated and linked to the current tail page, and the offset points the first element in the page. On dequeue, the head pointer is advanced. If the head pointer reaches the end of the page, the head pointer is set to the next page following the link. In another embodiment, the head pointer is set to the next offset.
FIG. 6 is a block diagram illustrating components of an operating environment in which various embodiments of the present invention may be implemented. The system 600 can include one or more user computers, computing devices, or processing devices 612, 614, 616, 618, which can be used to operate a client, such as a dedicated application, web browser, etc. The user computers 612, 614, 616, 618 can be general purpose personal computers (including, merely by way of example, personal computers and/or laptop computers running various versions of Microsoft Windows and/or Apple Macintosh operating systems), cell phones or PDAs (running software such as Microsoft Windows Mobile and being Internet, e-mail, SMS, Blackberry, or other communication protocol enabled), and/or workstation computers running any of a variety of commercially-available UNIX or UNIX-like operating systems (including without limitation, the variety of GNU/Linux operating systems). These user computers 612, 614, 616, 618 may also have any of a variety of applications, including one or more development systems, database client and/or server applications, and Web browser applications. Alternatively, the user computers 612, 614, 616, 618 may be any other electronic device, such as a thin-client computer, Internet-enabled gaming system, and/or personal messaging device, capable of communicating via a network (e.g., the network 610 described below) and/or displaying and navigating Web pages or other types of electronic documents. Although system 600 is shown with four user computers, any number of user computers may be supported.
In most embodiments, the system 600 includes some type of network 610. The network may can be any type of network familiar to those skilled in the art that can support data communications using any of a variety of commercially-available protocols, including without limitation TCP/IP, SNA, IPX, AppleTalk, and the like. Merely by way of example, the network 610 can be a local area network (“LAN”), such as an Ethernet network, a Token-Ring network and/or the like; a wide-area network; a virtual network, including without limitation a virtual private network (“VPN”); the Internet; an intranet; an extranet; a public switched telephone network (“PSTN”); an infra-red network; a wireless network (e.g., a network operating under any of the IEEE 802.11 suite of protocols, the Bluetooth protocol known in the art, and/or any other wireless protocol); and/or any combination of these and/or other networks.
The system may also include one or more server computers 602, 604, 606 which can be general purpose computers, specialized server computers (including, merely by way of example, PC servers, UNIX servers, mid-range servers, mainframe computers rack-mounted servers, etc.), server farms, server clusters, or any other appropriate arrangement and/or combination. One or more of the servers (e.g., 606) may be dedicated to running applications, such as a business application, a Web server, application server, etc. Such servers may be used to process requests from user computers 612, 614, 616, 618. The applications can also include any number of applications for controlling access to resources of the servers 602, 604, 606.
The Web server can be running an operating system including any of those discussed above, as well as any commercially-available server operating systems. The Web server can also run any of a variety of server applications and/or mid-tier applications, including HTTP servers, FTP servers, CGI servers, database servers, Java servers, business applications, and the like. The server(s) also may be one or more computers which can be capable of executing programs or scripts in response to the user computers 612, 614, 616, 618. As one example, a server may execute one or more Web applications. The Web application may be implemented as one or more scripts or programs written in any programming language, such as Java, C, C# or C++, and/or any scripting language, such as Perl, Python, or TCL, as well as combinations of any programming/scripting languages. The server(s) may also include database servers, including without limitation those commercially available from Oracle, Microsoft, Sybase, IBM and the like, which can process requests from database clients running on a user computer 612, 614, 616, 618.
The system 600 may also include one or more databases 620. The database(s) 620 may reside in a variety of locations. By way of example, a database 620 may reside on a storage medium local to (and/or resident in) one or more of the computers 602, 604, 606, 612, 614, 616, 618. Alternatively, it may be remote from any or all of the computers 602, 604, 606, 612, 614, 616, 618, and/or in communication (e.g., via the network 610) with one or more of these. In a particular set of embodiments, the database 620 may reside in a storage-area network (“SAN”) familiar to those skilled in the art. Similarly, any necessary files for performing the functions attributed to the computers 602, 604, 606, 612, 614, 616, 618 may be stored locally on the respective computer and/or remotely, as appropriate. In one set of embodiments, the database 620 may be a relational database, such as Oracle 10 g, that is adapted to store, update, and retrieve data in response to SQL-formatted commands.
FIG. 7 illustrates a computer system 700, in which various embodiments of the present invention may be implemented. The system 700 may be used to implement any of the computer systems, such as EPS 110, described above. The computer system 700 is shown comprising hardware elements that may be electrically coupled via a bus 724. The hardware elements may include one or more central processing units (CPUs) 702, one or more input devices 704 (e.g., a mouse, a keyboard, etc.), and one or more output devices 706 (e.g., a display device, a printer, etc.). The computer system 700 may also include one or more storage devices 708. By way of example, the storage device(s) 708 can include devices such as disk drives, optical storage devices, solid-state storage device such as a random access memory (“RAM”) and/or a read-only memory (“ROM”), which can be programmable, flash-updateable and/or the like.
The computer system 700 may additionally include a computer-readable storage media reader 712, a communications system 714 (e.g., a modem, a network card (wireless or wired), an infra-red communication device, etc.), and working memory 718, which may include RAM and ROM devices as described above. In some embodiments, the computer system 700 may also include a processing acceleration unit 716, which can include a digital signal processor DSP, a special-purpose processor, and/or the like.
The computer-readable storage media reader 712 can further be connected to a computer-readable storage medium 710, together (and, optionally, in combination with storage device(s) 708) comprehensively representing remote, local, fixed, and/or removable storage devices plus storage media for temporarily and/or more permanently containing computer-readable information. The communications system 714 may permit data to be exchanged with the network and/or any other computer described above with respect to the system 700.
The computer system 700 may also comprise software elements, shown as being currently located within a working memory 718, including an operating system 720 and/or other code 722, such as an application program (which may be a client application, Web browser, mid-tier application, RDBMS, etc.). It should be appreciated that alternate embodiments of a computer system 700 may have numerous variations from that described above. For example, customized hardware might also be used and/or particular elements might be implemented in hardware, software (including portable software, such as applets), or both. Further, connection to other computing devices such as network input/output devices may be employed.
Storage media and computer readable media for containing code, or portions of code, can include any appropriate media known or used in the art, including storage media and communication media, such as but not limited to volatile and non-volatile, removable and non-removable media implemented in any method or technology for storage and/or transmission of information such as computer readable instructions, data structures, program modules, or other data, including RAM, ROM, EEPROM, flash memory or other memory technology, CD-ROM, digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic tape, magnetic disk storage or other magnetic storage devices, data signals, data transmissions, or any other medium which can be used to store or transmit the desired information and which can be accessed by the computer. Based on the disclosure and teachings provided herein, a person of ordinary skill in the art will appreciate other ways and/or methods to implement the various embodiments.
In the foregoing specification, the invention is described with reference to specific embodiments thereof. It will be recognized by those skilled in the art that while the invention is described above in terms of preferred embodiments, it is not limited thereto. Various features and aspects of the above-described invention may be used individually or jointly. Further, although the invention has been described in the context of its implementation in a particular environment and for particular applications, those skilled in the art will recognize that its usefulness is not limited thereto and that it can be utilized in any number of environments and applications without departing from the broader spirit and scope thereof. The specification and drawings are, accordingly, to be regarded in an illustrative rather than a restrictive sense.

## Claims

1. A method performed by a data stream processing system for managing memory usage of the data stream processing system, the method comprising:
detecting a triggering event;
responsive to the triggering event, determining, based upon an evict policy, whether data from a memory of the data stream processing system is to be spilled to a persistent storage, wherein the memory includes a plurality of buffer queues, and wherein the determining comprises:
determining a threshold from a plurality of thresholds associated with a current state of the data stream processing system based upon the evict policy; and
comparing the threshold with a level of free memory of the data stream processing system; and

evicting the data from the memory.

2. The method of claim 1, further comprising:
storing the data to the persistent storage.

3. The method of claim 1, wherein the triggering event is receiving an enqueue request or a dequeue request.

4. The method of claim 1, further comprising:
transitioning the data stream processing system from the current state to a new state based upon the comparison.

5. The method of claim 1, wherein the current state of the data stream processing system is associated with one or more thresholds of the plurality of thresholds.

6. The method of claim 1, further comprising:
selecting a buffer queue of the plurality of buffer queues from which to perform eviction based upon the evict policy, wherein the data is evicted from the selected buffer queue.

7. The method of claim 1, wherein the evicted data comprises one or more pages of a data stream.

8. The method of claim 7, wherein the eviction of the one or more pages occurs from the largest buffer queue of the plurality of buffer queues.

9. The method of claim 7, wherein the eviction of the one or more pages occurs from each buffer queue of the plurality of buffer queues.

10. The method of claim 7, wherein the eviction of the one or more pages is executed by a thread independent from a caller thread.

11. The method of claim 1, wherein prior to eviction, a buffer queue of the plurality of buffer queues operates according to a memory mode where spilling is not performed.

12. A computer-readable storage medium storing a computer program product for managing memory usage of a data stream processing system, the computer program product comprising:
computer code for detecting a triggering event;
computer code for responsive to the triggering event, determining, based upon an evict policy, whether data from a memory of the data stream processing system is to be spilled to a persistent storage, wherein the memory includes a plurality of buffer queues, and wherein the determining comprises:
determining a threshold from a plurality of thresholds associated with a current state of the data stream processing system based upon the evict policy; and
comparing the threshold with a level of free memory of the data stream processing system; and

computer code for evicting the data from the memory.

13. The computer program product according to claim 12, wherein the triggering event is receiving an enqueue request or a dequeue request.

14. The computer program product according to claim 12, wherein the current state of the processing system is associated with one or more thresholds of the plurality of thresholds.

15. The computer program product according to claim 12, the computer program product further comprising:
computer code for selecting a buffer queue of the plurality of buffer queues from which to perform eviction based upon the evict policy, wherein the data is evicted from the selected buffer queue.

16. A system comprising:
a processor configured to:
detect a triggering event;
responsive to the triggering event, determine, based upon an evict policy, whether data from a memory of a data stream processing system is to be spilled to a persistent storage, wherein the memory includes a plurality of buffer queues, and wherein the determining comprises:
determining a threshold from a plurality of thresholds associated with a current state of the data stream processing system based upon the evict policy; and
comparing the threshold with a level of free memory of the data stream processing system; and

evict the data from the memory.

17. The system according to claim 16, wherein the triggering event is receiving an enqueue request or a dequeue request.

18. The system according to claim 16, wherein the current state of the processing system is associated with one or more thresholds of the plurality of thresholds.

19. The system according to claim 16, wherein the processor is further configured to:
select a buffer queue of the plurality of buffer queues from which to perform eviction based upon the evict policy, wherein the data is evicted from the selected buffer queue.