20.07.2013 Views

Beginning SQL

Beginning SQL

Beginning SQL

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 13<br />

Database Cache<br />

354<br />

In addition to the processor and disk caches, databases build their own cache that resides in system<br />

memory. The database cache (illustrated in Figure 13-2) is the only cache discussed so far that you have<br />

any direct control over, and you can in fact often tell the DBMS how much memory to request from the<br />

system to reserve for caches. In fact, it is often the other way around. With <strong>SQL</strong> Server, you must specify<br />

how much main memory not to use — to leave for the server and other applications running on the<br />

server. <strong>SQL</strong> Server takes all of the memory less this amount to use for its own purposes, and those purposes<br />

are mainly caching data.<br />

Hard Disk<br />

Cache<br />

Figure 13-2<br />

Head of Cache<br />

Blocks of Data<br />

Data Sent<br />

To Processor<br />

Cache<br />

Back to Head<br />

of Cache<br />

Tail of Cache<br />

Bit<br />

Bucket<br />

(trash)<br />

The database cache looks very similar to the hard disk cache. The biggest difference is the location of the<br />

cache. Whereas the hard disk cache physically resides on the hard disk and has to be read into main<br />

memory over the cables connecting the disk to the computer, the database cache resides in main memory.<br />

When data is read out of this database cache, it is on its way to the processor cache, and from there<br />

to the processor itself.<br />

Caches in system memory are second only to the processor cache in terms of speed. In today’s hardware,<br />

main system memory is approximately 25 to 100 times slower than processor cache; if the processor<br />

cache can move data into the processor in a single clock cycle, main memory takes 25 to 100 clock cycles<br />

to get the data into the processor. While this sounds a lot slower than processor cache (and it is), it is also<br />

the only cache that you have any direct control over, and so it is extremely useful to be aware of this<br />

level of caching. If your database is running on a machine with too little main memory, you can often get<br />

immense speed gains simply by throwing memory at the problem. At the price of memory today, it may<br />

very well cost less to double or quadruple the amount of main memory than for you to spend a week on<br />

query optimization. When it comes to databases, the more main memory, the better.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!