Databases Reference
In-Depth Information
You can estimate the optimal concurrency, but it requires accurate profiling. It's usually
easier to either experiment with different concurrency values and see what gives the
peak throughput without degrading response time, or measure your real workload and
analyze it. Percona Toolkit's pt-tcp-model tool can help you measure and model your
system's scalability and performance characteristics from a TCP dump.
Caching
Caching is vital for high-load applications. A typical web application serves a lot of
content that costs much more to generate than it costs to cache (including the cost of
checking and expiring the cache), so caching can usually improve performance by or-
ders of magnitude. The trick is to find the right combination of granularity and expi-
ration policies. You also need to decide what content to cache and where to cache it.
A typical high-load application has many layers of caching. Caching doesn't just happen
in your servers: it happens at every step along the way, including the user's web browser
(that's what content expiration headers are for). In general, the closer the cache is to
the client, the more resources it saves and the more effective it is. Serving an image from
the browser's cache is better than serving it from the web server's memory, which is
better than reading it from the server's disk. Each type of cache has unique character-
istics, such as size and latency; we examine some of them in the following sections.
You can think about caches in two broad categories: passive caches and active caches .
Passive caches do nothing but store and return data. When you request something from
a passive cache, either you get the result or the cache tells you “that doesn't exist.” An
example of a passive cache is memcached .
In contrast, an active cache does something when there's a miss. It usually passes your
request on to some other part of the application, which generates the requested result.
The active cache then stores the result and returns it. The Squid caching proxy server
is an active cache.
When you design your application, you usually want your caches to be active (also
called transparent ), because they hide the check-generate-store logic from the applica-
tion. You can build active caches on top of passive caches.
Caching Below the Application
The MySQL server has its own internal caches, and you can build your own cache and
summary tables, too. You can custom-design your cache tables so that they're most
useful for filtering, sorting, joining to other tables, counting, or any other purpose.
Cache tables are also more persistent than many application-level caches, because
they'll survive a server restart.
We wrote about these cache strategies in Chapter 4 and Chapter 5 , so in this chapter
we focus on caching at the application level and above.
 
Search WWH ::




Custom Search