Presentation is loading. Please wait.

Presentation is loading. Please wait.

Buffering Database Operations for Enhanced Instruction Cache Performance Jingren Zhou, Kenneth A. Ross SIGMOD International Conference on Management of.

Similar presentations


Presentation on theme: "Buffering Database Operations for Enhanced Instruction Cache Performance Jingren Zhou, Kenneth A. Ross SIGMOD International Conference on Management of."— Presentation transcript:

1 Buffering Database Operations for Enhanced Instruction Cache Performance Jingren Zhou, Kenneth A. Ross SIGMOD International Conference on Management of Data 2004 Nihan Özman - 2005700452

2 Outline Introduction Introduction Related Work Related Work Memory Hierarchy Memory Hierarchy Pipelined Query Execution Pipelined Query Execution A New Buffer Operator A New Buffer Operator Buffering Strategies Buffering Strategies Instruction Footprint Analysis Instruction Footprint Analysis Overall Algorithm Overall Algorithm Experimental Validation Experimental Validation Conclusion and Future Work Conclusion and Future Work

3 Introduction Recent database research has demonstrated that most of the memory stalls are due to the data cache misses on the second-level cache and the instruction cache misses on the first-level instruction cache. Recent database research has demonstrated that most of the memory stalls are due to the data cache misses on the second-level cache and the instruction cache misses on the first-level instruction cache. With random access memory (RAM) getting cheaper and new 64-bit CPUs join the PC family, it becomes affordable and feasible to build computers with large main memories. With random access memory (RAM) getting cheaper and new 64-bit CPUs join the PC family, it becomes affordable and feasible to build computers with large main memories. Which implies more and more query processing work can be done in main memory. Which implies more and more query processing work can be done in main memory. Advance in CPU speeds have far outpaced the advances in memory latency Advance in CPU speeds have far outpaced the advances in memory latency Main memory access is becoming a significant cost component of database operations Main memory access is becoming a significant cost component of database operations

4 Introduction Relatively little research has been done on improving the instruction cache performance. Relatively little research has been done on improving the instruction cache performance. In this paper, the focus is on In this paper, the focus is on improving the instruction cache performance for conventional demand-pull database query engines improving the instruction cache performance for conventional demand-pull database query engines achieving fast query execution throughput achieving fast query execution throughput not making substantial modifications to existing database implementations not making substantial modifications to existing database implementations

5 Related Work There are many techniques proposed to improve instruction cache performance at compiler level. There are many techniques proposed to improve instruction cache performance at compiler level. For database systems, these techniques do not solve the fundamental problem: For database systems, these techniques do not solve the fundamental problem: Large instruction footprints during database query execution, leading to a large number of instruction cache misses Large instruction footprints during database query execution, leading to a large number of instruction cache misses The challenge: The challenge: Reducing the effective size of the query execution footprints without sacrificing performance Reducing the effective size of the query execution footprints without sacrificing performance This issue should be resolved at the “query compiler” level (during query optimization) This issue should be resolved at the “query compiler” level (during query optimization)

6 Related Work A block oriented processing technique for aggregation, expression evaluation and sorting operation is proposed by Padmanabhan, Malkemus, Agarwal and Jhingran. A block oriented processing technique for aggregation, expression evaluation and sorting operation is proposed by Padmanabhan, Malkemus, Agarwal and Jhingran. Each operation is performed on a block of records using a vector style processing strategy to Each operation is performed on a block of records using a vector style processing strategy to achieve better instruction pipeliningachieve better instruction pipelining minimize instruction count and function callsminimize instruction count and function calls Impact of instruction cache performance is not studied. Impact of instruction cache performance is not studied. The technique requires a complete redesign of database operations (all return block of tuples) The technique requires a complete redesign of database operations (all return block of tuples) The technique do not consider the operator footprint size when deciding whether to process data in blocks The technique do not consider the operator footprint size when deciding whether to process data in blocks

7 Related Work Zhou and Ross use a similar buffer strategy to batch access to a tree-based index (“Buffering accesses to memory-resident index structures”, In Proceedings of VLDB Conference, 2003) Zhou and Ross use a similar buffer strategy to batch access to a tree-based index (“Buffering accesses to memory-resident index structures”, In Proceedings of VLDB Conference, 2003) The performance benefits of such buffering are due to improved data cache hit rates. The performance benefits of such buffering are due to improved data cache hit rates. The impact of buffering on instruction-cache behaviour is not described. The impact of buffering on instruction-cache behaviour is not described.

8 Memory Hierarchy Modern computer architectures have a hierarchical memory system, where access by the CPU to main memory is accelerated by various levels of cache memories. Modern computer architectures have a hierarchical memory system, where access by the CPU to main memory is accelerated by various levels of cache memories. Cache memories based on the principles of spatial and temporal locality. Cache memories based on the principles of spatial and temporal locality. A cache hit happens when the requested data (or instructions) are found in the cache. A cache hit happens when the requested data (or instructions) are found in the cache. A cache miss incurs when the CPU loads data (or instructions) from a lower cache or memory A cache miss incurs when the CPU loads data (or instructions) from a lower cache or memory

9 Memory Hierarchy There are typically two or three cache levels. There are typically two or three cache levels. Most of the CPU’s now have Level 1 and Level 2 caches integrated on die. Most of the CPU’s now have Level 1 and Level 2 caches integrated on die. Instruction and data caches are usually seperated in the first level and are shared in the second level. Instruction and data caches are usually seperated in the first level and are shared in the second level. Caches are characterized by: Caches are characterized by: capacity capacity cache-line size cache-line size associativity associativity

10 Memory Hierarchy Latency is the time span that passes after issuing a data access until the requested data is available in the CPU Latency is the time span that passes after issuing a data access until the requested data is available in the CPU In hierarchical memory systems, latency increases with distance from the CPU In hierarchical memory systems, latency increases with distance from the CPU L2 cache sizes are expected to increase(2MB for Pentium M), L1 cache sizes will not increase at the same rate. Larger L1 caches are slower than smaller L1 caches, and may slow down the processor clock. L2 cache sizes are expected to increase(2MB for Pentium M), L1 cache sizes will not increase at the same rate. Larger L1 caches are slower than smaller L1 caches, and may slow down the processor clock. The aim in this paper is to minimize L1 instruction cache misses The aim in this paper is to minimize L1 instruction cache misses

11 Memory Hierarchy Modern processors implement a Trace Cache instead of a conventional L1 instruction cache. Modern processors implement a Trace Cache instead of a conventional L1 instruction cache.Trace Cache Trace Cache A trace cache is an instruction cache that stores instructions either after they have been decoded, or as they are retired. This allows the instruction fetch unit of a processor to fetch several basic blocks, without having to worry about branches in the execution flow. A trace cache is an instruction cache that stores instructions either after they have been decoded, or as they are retired. This allows the instruction fetch unit of a processor to fetch several basic blocks, without having to worry about branches in the execution flow. Upon a trace cache miss, the instruction address is submitted to the instruction translation look aside buffer (ITLB), which translates the address into a physical memory address before the cache lookup is performed. Upon a trace cache miss, the instruction address is submitted to the instruction translation look aside buffer (ITLB), which translates the address into a physical memory address before the cache lookup is performed. The TLB ( Translation Look aside Buffer ) is responsible for translating the virtual address into a physical address. The TLB is a little cache that contains recent translations. If it's not in the TLB then the translation must be loaded from the memory hierarchy, possible all the way down from main memory. The TLB ( Translation Look aside Buffer ) is responsible for translating the virtual address into a physical address. The TLB is a little cache that contains recent translations. If it's not in the TLB then the translation must be loaded from the memory hierarchy, possible all the way down from main memory.

12 Memory Hierarchy Data memory latency can be hidden by correctly prefetching data in to the cache. Data memory latency can be hidden by correctly prefetching data in to the cache. Most of the modern CPU’s are pipelined CPU’s Most of the modern CPU’s are pipelined CPU’s The term pipeline represents the concept of splitting a job into sub processes in which the output of one sub process feeds into the next. (for Pentium 4 the pipeline is 20 stages deep) The term pipeline represents the concept of splitting a job into sub processes in which the output of one sub process feeds into the next. (for Pentium 4 the pipeline is 20 stages deep) Conditional branch instructions present another significant problem for modern pipelined CPUs because the CPUs do not know in advance which of the two possible outcomes of the comparison will happen. Conditional branch instructions present another significant problem for modern pipelined CPUs because the CPUs do not know in advance which of the two possible outcomes of the comparison will happen.

13 Memory Hierarchy CPUs try to predict the outcome of branches, and have special hardware for maintaining the branching history of many branch instructions. CPUs try to predict the outcome of branches, and have special hardware for maintaining the branching history of many branch instructions. For Pentium 4 processors, the trace cache integrates branch prediction into the instruction cache by storing traces of instructions that have previously been executed in sequence, including branches. For Pentium 4 processors, the trace cache integrates branch prediction into the instruction cache by storing traces of instructions that have previously been executed in sequence, including branches.

14 Pipelined Query Execution Each operator supports an open-next-close iterator interface Each operator supports an open-next-close iterator interface Open(): initializes the state of the iterator by allocating buffers for its inputs and output, and is also used to pass in arguments such as selection predicates that modify the behavior of the operator. Open(): initializes the state of the iterator by allocating buffers for its inputs and output, and is also used to pass in arguments such as selection predicates that modify the behavior of the operator. Next(): calls the next() function on each input node recursively and processes the input tuples until one output tuple is generated. The state of the operator is updated to keep track of how much input has been consumed. Next(): calls the next() function on each input node recursively and processes the input tuples until one output tuple is generated. The state of the operator is updated to keep track of how much input has been consumed. Close(): deallocates the state information and performs final housekeeping Close(): deallocates the state information and performs final housekeeping

15 Pipelined Query Execution Pipelining requires much less space for intermediate results during execution, and this query execution model can be executed by a single process or thread. Pipelining requires much less space for intermediate results during execution, and this query execution model can be executed by a single process or thread. Demand driven pipelined query plans exhibit poor instruction locality and have bad instruction cache behavior Demand driven pipelined query plans exhibit poor instruction locality and have bad instruction cache behavior For a query plan with a pipeline of operators, all the operators instructions on the pipeline must be executed at least once to generate one output tuple. For a query plan with a pipeline of operators, all the operators instructions on the pipeline must be executed at least once to generate one output tuple. The query execution shows large instruction footprints. The query execution shows large instruction footprints. footprints

16 Instruction Cache Thrashing If the instruction cache is smaller than the total instruction footprint, every operator finds that some of its instructions are not in the cache. If the instruction cache is smaller than the total instruction footprint, every operator finds that some of its instructions are not in the cache. By loading its own instructions into the instruction cache, capacity cache misses occur to evict instructions for other operators from the cache. By loading its own instructions into the instruction cache, capacity cache misses occur to evict instructions for other operators from the cache. However, the evicted instructions are required by subsequent requests to the operators, and have to be loaded again in the future. This happens for every output tuple and for every operator in the pipeline. However, the evicted instructions are required by subsequent requests to the operators, and have to be loaded again in the future. This happens for every output tuple and for every operator in the pipeline. The resulting instruction cache thrashing can have a severe impact on the overall performance The resulting instruction cache thrashing can have a severe impact on the overall performance

17 Simple Query SELECT SUM(l_extendedprice * (1 - l_discount) * (1 + l_tax)) as sum_charge, AVG(l_quantity) as avg_qty, COUNT(*) as count_order FROM lineitem WHERE l_shipdate <= date '1998-11-01'; (TPC-H Schema)TPC-H Schema

18 A New Buffer Operator Given a query plan, a special buffer operator is added in certain places between a parent and a child operator. Given a query plan, a special buffer operator is added in certain places between a parent and a child operator. During query execution, each buffer operator stores a large array of pointers to intermediate tuples generated by the child operator. During query execution, each buffer operator stores a large array of pointers to intermediate tuples generated by the child operator. Rather than returning control to the parent operator after one tuple, the buffer operator calls its array with intermediate results by repeatedly calling child operator. Rather than returning control to the parent operator after one tuple, the buffer operator calls its array with intermediate results by repeatedly calling child operator. Control returns to the parent operator once the buffer's array is filled (or when there are no more tuples). Control returns to the parent operator once the buffer's array is filled (or when there are no more tuples). When the parent operator requests additional tuples, they are returned from the buffer's array without executing any code from the child operator. When the parent operator requests additional tuples, they are returned from the buffer's array without executing any code from the child operator.

19 An Example for Usage of Buffer Operator

20 A New Buffer Operator To avoid the instruction cache thrashing problem, implementing a new light-weight buffer operator using the conventional iterator interface is proposed. To avoid the instruction cache thrashing problem, implementing a new light-weight buffer operator using the conventional iterator interface is proposed. A buffer operator simply batches the intermediate results of the operators below it. A buffer operator simply batches the intermediate results of the operators below it. Organize the tree of operators into execution groups. Execution groups are candidate units of buffering. Organize the tree of operators into execution groups. Execution groups are candidate units of buffering. The new buffer operator supports the open-next-close interface. The new buffer operator supports the open-next-close interface.

21 Query Execution Plan

22 Pseudocode For Buffer Operator

23 Buffer Operator Here is an example of a buffer operator with size 8. Here is an example of a buffer operator with size 8. The operator maintains a buffer array which stores pointers to previous intermediate tuples from the child operator The operator maintains a buffer array which stores pointers to previous intermediate tuples from the child operator

24 Point of Buffering The point of buffering is that it increases temporal and spatial instruction locality below the buffer operator. The point of buffering is that it increases temporal and spatial instruction locality below the buffer operator. When the child operator is executed, its instructions are loaded into the L1 instruction cache. When the child operator is executed, its instructions are loaded into the L1 instruction cache. Instead of being used to generate one tuple, these instructions are used to generate many tuples. Instead of being used to generate one tuple, these instructions are used to generate many tuples. As a result, the memory overhead for bringing the instructions into the cache and the CPU overhead of decoding the instructions is smaller. As a result, the memory overhead for bringing the instructions into the cache and the CPU overhead of decoding the instructions is smaller. Buffering also improves Query throughput. Buffering also improves Query throughput.

25 Buffering Strategies Every buffer operator incurs the cost of maintaining operator state and pointers to tuples during execution. Every buffer operator incurs the cost of maintaining operator state and pointers to tuples during execution. If the cost of buffering is significant compared with the performance gain then there is too much buffering. If the cost of buffering is significant compared with the performance gain then there is too much buffering. If the total footprint of an execution group is larger than the L1 instruction cache then it results in large number of instruction cache misses. If the total footprint of an execution group is larger than the L1 instruction cache then it results in large number of instruction cache misses. Operators with small cardinality estimates are unlikely to benefit from putting new buffers. Operators with small cardinality estimates are unlikely to benefit from putting new buffers. The cardinality threshold at which the benefits outweigh the costs can be determined using a calibration experiment on the target architecture. The cardinality threshold at which the benefits outweigh the costs can be determined using a calibration experiment on the target architecture.

26 Buffering Strategies This threshold can be determined once, in advance, by the database system. This threshold can be determined once, in advance, by the database system. The calibration experiment would consist of running a single query with and without buffering at various cardinalities. The calibration experiment would consist of running a single query with and without buffering at various cardinalities. The cardinality at which the buffered plan begins to beat the unbuffered plan would be the cardinality threshold for buffering. The cardinality at which the buffered plan begins to beat the unbuffered plan would be the cardinality threshold for buffering.

27 Instruction Footprint Analysis The basic strategy is to break a pipeline of operators into execution groups so that the instruction footprint of each execution group combined with the footprint of a new buffer operator is less than the L1 instruction cache size. This eliminates instruction cache thrashing within an execution group. The basic strategy is to break a pipeline of operators into execution groups so that the instruction footprint of each execution group combined with the footprint of a new buffer operator is less than the L1 instruction cache size. This eliminates instruction cache thrashing within an execution group. An ideal footprint estimate can only be measured when actually running the query, in an environment typical of the query being posed. However, it would be too expensive to run the whole query first just for estimating footprint sizes. An ideal footprint estimate can only be measured when actually running the query, in an environment typical of the query being posed. However, it would be too expensive to run the whole query first just for estimating footprint sizes. No matter which data is used, the same set of functions are almost always executed for each module. Thus, the core database system can be calibrated once by running a small query set that covers all kinds of operators. No matter which data is used, the same set of functions are almost always executed for each module. Thus, the core database system can be calibrated once by running a small query set that covers all kinds of operators.

28 Overall Algorithm The database system is first calibrated by running a small set of simple queries which cover all the operator types, and the instruction footprint for each operator is measured. The database system is first calibrated by running a small set of simple queries which cover all the operator types, and the instruction footprint for each operator is measured. Plan refinement algorithm accepts a query plan tree from the optimizer as input. It produces as output an equivalent enhanced plan tree with buffer operators added. Plan refinement algorithm accepts a query plan tree from the optimizer as input. It produces as output an equivalent enhanced plan tree with buffer operators added.

29 Overall Algorithm 1. Consider only nonblocking operators with output cardinalities exceeding the calibration threshold. 2. A bottom-up pass is made of the query plan. Each leaf operator is initially an execution group. Try to enlarge each execution group by including parent operators or merging adjacent execution groups until any further action leads to a combined footprint larger than the L1 instruction cache. When that happens, finish with the current execution group and label the parent operator as a new execution group, and continue the bottom-up traversal. 3. Add a buffer operator above each execution group and return the new plan.

30 Specification of Experimental System

31 Experimental Validation Large buffer pool is allocated so that all tables can be memory-resident. Large buffer pool is allocated so that all tables can be memory-resident. Enough memory for sorting and hashing operations is also allocated. Enough memory for sorting and hashing operations is also allocated.

32 Validating Buffer Strategies SELECT COUNT(*) as count_order FROM lineitem WHERE l_shipdate <= date '1998-11-01'; The results confirms that The results confirms that The overhead of buffering is small The overhead of buffering is small Buffering within a group of operators that already fit in the trace cache does not improve instruction cache performance. Buffering within a group of operators that already fit in the trace cache does not improve instruction cache performance.

33 Validating Buffer Strategies SELECT SUM(l_extendedprice * (1 - l_discount) * (1 + l_tax)) as sum_charge, AVG(l_quantity) as avg_qty, COUNT(*) as count_order FROM lineitem WHERE l_shipdate <= date '1998-11-01'; The results shows that The results shows that Combined footprint is 23KB Combined footprint is 23KB Number of trace cache misses reduced by 80% Number of trace cache misses reduced by 80% Number of branch mispredictions reduced by 21% Number of branch mispredictions reduced by 21%

34 Cardinality Effects Query 1 is used as a query template to calibrate the system, in order to determine a cardinality threshold for buffering. Query 1 is used as a query template to calibrate the system, in order to determine a cardinality threshold for buffering. The threshold is not sensitive to the choice of operator The threshold is not sensitive to the choice of operator The benefits of buffering become more obvious as the predicate becomes less selective The benefits of buffering become more obvious as the predicate becomes less selective

35 Buffer Size Buffering parameter is the size of array used to buffer tuple pointers. Buffering parameter is the size of array used to buffer tuple pointers. The size is set during operator initialization. The size is set during operator initialization. The number of reduced trace cache misses is roughly proportional to 1/buffersize. Once buffer is of moderate size, there is only a small incentive to make it bigger. The number of reduced trace cache misses is roughly proportional to 1/buffersize. Once buffer is of moderate size, there is only a small incentive to make it bigger. Buffered query performance as a function of the buffer size for Query 1 Buffered query performance as a function of the buffer size for Query 1

36 Buffer Size Execution Time Breakdown for Varied Buffer Sizes Execution Time Breakdown for Varied Buffer Sizes As the buffer size increases, As the buffer size increases, trash cache miss penalty drops trash cache miss penalty drops the buffered plan shows better performance the buffered plan shows better performance Buffer operators incur more L2 data cache misses (hardware prefetching hides most of this miss latency, since the data is allocated or accessed sequentially) Buffer operators incur more L2 data cache misses (hardware prefetching hides most of this miss latency, since the data is allocated or accessed sequentially)

37 Complex Queries SELECT sum(o_totalprice), count(*), avg(l_discount) FROM lineitem, orders WHERE l_orderkey = o_orderkey AND l_shipdate <= date '1998-11-01';

38 Nest Loop Join Nest Loop Joins Reduced cache trace misses by 53% Reduced cache trace misses by 53% Reduced branch mispredictions by 26% Reduced branch mispredictions by 26%

39 Hash Join HashJoin Joins Reduced cache trace misses by 70% Reduced cache trace misses by 70% Reduced branch mispredictions by 44% Reduced branch mispredictions by 44%

40 Merge Join Merge Joins Reduced cache trace misses by 79% Reduced cache trace misses by 79% Reduced branch mispredictions by 30% Reduced branch mispredictions by 30%

41 General Results Buffered plans lead to more L2 cache misses Buffered plans lead to more L2 cache misses The overhead is much smaller than the performance gain from the trace cache and branch prediction The overhead is much smaller than the performance gain from the trace cache and branch prediction Overall Improvement

42 General Results Better instruction cache performance leads to lower CPI (Cost-Per-Instruction) Better instruction cache performance leads to lower CPI (Cost-Per-Instruction) The original and buffered plans have almost the same number (less than 1% difference) of instructions executed The original and buffered plans have almost the same number (less than 1% difference) of instructions executed Result: Buffer operators are light-weight Result: Buffer operators are light-weight CPI Improvement

43 Conclusion Techniques to buffer query execution of query plans to exploit instruction cache spatial and temporal locality are proposed Techniques to buffer query execution of query plans to exploit instruction cache spatial and temporal locality are proposed A new buffer operator over the existing open-next- close interface is implemented (without changing the implementation of other operators) A new buffer operator over the existing open-next- close interface is implemented (without changing the implementation of other operators) Buffer operators are useful for complex queries which have large instruction footprints and large output cardinalities Buffer operators are useful for complex queries which have large instruction footprints and large output cardinalities

44 Conclusion Plan refinement algorithm traverses the query plan in a botoom-up fashion and makes buffering decisions based on footprint and large output cardinalities Plan refinement algorithm traverses the query plan in a botoom-up fashion and makes buffering decisions based on footprint and large output cardinalities Instruction cache misses are reduced by up to 80% Instruction cache misses are reduced by up to 80% The query performance is improved by up to 15% The query performance is improved by up to 15%

45 Future Work Integrate buffering with in the plan generator of a query optimizer Integrate buffering with in the plan generator of a query optimizer Break the operators with very large footprints into several sub-operators and execute them in stages. Break the operators with very large footprints into several sub-operators and execute them in stages. Reschedule the execution so that operators that are of the same type are scheduled together for complex query plans Reschedule the execution so that operators that are of the same type are scheduled together for complex query plans

46 References S. Padmanabhan, T. Malkemus, R. Agarwal, and A. Jhingran. Block oriented processing of relational database operations in modern computer architectures. In Proceedings of ICDE Conference, 2001. S. Padmanabhan, T. Malkemus, R. Agarwal, and A. Jhingran. Block oriented processing of relational database operations in modern computer architectures. In Proceedings of ICDE Conference, 2001. J. Zhou, and K. A. Ross. Bufferring accesses to memory- resident index structures. In Proceedings of VLDB conference, 2003. J. Zhou, and K. A. Ross. Bufferring accesses to memory- resident index structures. In Proceedings of VLDB conference, 2003. K.A. Ross, J. Cieslewicz, J. Rao, and J. Zhou. Architecture Sensitive Database Design: Examples from the Columbia Group. Bulletin of the IEEE Computer Society Technical Committe on Data Engineering, 2005 K.A. Ross, J. Cieslewicz, J. Rao, and J. Zhou. Architecture Sensitive Database Design: Examples from the Columbia Group. Bulletin of the IEEE Computer Society Technical Committe on Data Engineering, 2005

47 References Transaction Processing Performance Council. TPC Benchmark H. Available via http://www.tpc.com/tpch/. Transaction Processing Performance Council. TPC Benchmark H. Available via http://www.tpc.com/tpch/.http://www.tpc.com/tpch/ A. Ailamaki, D. J. DeWitt, M. D. Hill, and D. A. Wood. DBMSs on a modern processor: Where does time go? In Proceedings of VLDB conference, 1999. A. Ailamaki, D. J. DeWitt, M. D. Hill, and D. A. Wood. DBMSs on a modern processor: Where does time go? In Proceedings of VLDB conference, 1999.

48 Questions?

49 Thank You

50 Pentium 4 Cache Memory System

51 Instruction Footprints

52 TPC-H Schema


Download ppt "Buffering Database Operations for Enhanced Instruction Cache Performance Jingren Zhou, Kenneth A. Ross SIGMOD International Conference on Management of."

Similar presentations


Ads by Google