Sunday, 11 October 2009

Recursive FTP/HTTP Download

Recursive FTP/HTTP Download: "



wget is a great tool. Here’s a short example on how to recursively get a directory from an FTP or HTTP server, also specifying credentials if required.


In short, wget -r http://www.domain.com/directory/ – this works the same with FTP: wget -r ftp://www.domain.com/directory/


If you need to specify a username and password to the FTP server: wget -r ftp://username:password@www.domain.com/directory/


To resume an existing session, specify -c and each file downloaded will attempt to resume from where it left off, if necessary.




"

Thursday, 8 October 2009

Dynamic General and Slow Query Log Before MySQL 5.1

Dynamic General and Slow Query Log Before MySQL 5.1: "

This is a hack, but it is a good one. I was looking at some machines on a new client, and they had the general log turned on. I was surprised, because it was a fairly busy server, and they had had many problems with the server a few months ago. I thought perhaps they had turned on the general log to diagnose a problem and forgotten to turn it off, or something similar.


When I looked at the log on disk, I saw it was a symlink to /dev/null. They were running MySQL 5.0, so I immediately realized that it was a hack to have a general log they could “turn on” without having to restart mysqld.


On a different server, I saw the same link to /dev/null done with a slow query log.


The drawbacks to doing it this way is that MySQL still has the overhead of writing to the log file. The I/O overhead is greatly reduced because the writes are to /dev/null, but there’s still overhead from other resources such as RAM, CPU, etc.


But if you are in a similar position — where you frequently need to turn the general log or slow query log on temporarily for debugging purposes — this tip just might help.


PlanetMySQL Voting:
Vote UP /
Vote DOWN"

Google Wave 101 [Google Wave]

Google Wave 101 [Google Wave]: "

So you've snagged an invitation to Google Wave—or a pal is sending one your way—and you've already taken a look at what to expect. Let's dive deeper into Wave features, etiquette, and extensions.

Learn Wave's Keyboard Shortcuts

Every good webapp has a full set of keyboard shortcuts for getting around and performing the most common actions, and happily Google Wave is no exception. While Wave is still missing a whole lot of shortcuts, there are a few you must know now. Here are the essential shortcuts to learn first:

  • Arrow keys: Move up/down within a list of waves, and left/right from inbox to open wave panel with your arrow keys.
  • Spacebar: Go to the next unread wave in a list
  • Ctrl+E: Edit a selected wave
  • Shift+Enter (in edit mode): Finish editing your wave; equivalent to clicking the 'Done' button
  • Enter: Add a reply to a selected wave directly under it
  • Shift+Enter (in view mode): Add a reply to the bottom of a list of waves

Here's the full list of keyboard shortcuts. Alternately, you can click on the image below to see them all.

Filter Waves with Advanced Operators and Saved Searches

Wave is a very Googly product, so searching is simply a matter of typing a keyword into the search box. But like Gmail, Google Wave also offers several advanced search operators that let you find waves based on who they're with, what they're tagged, and other attributes. For example, to see all the public waves—that is, waves in which anyone using Wave can see—use the with: operator. In fact, if you're feeling lonely in Wave, the first Wave search you should try is with:public.

To save a search for reuse, click on the 'Save Search' button on the bottom right of your Wave inbox. When you save a search you can also specify filter actions for all the waves that match it. Right now the only choices are 'Archive' and 'Mark as read.' Once you run that with:public search, every public wave you read will end up in your inbox, which becomes overwhelming almost immediately. So save your with:public search and check off 'Archive' so they don't clutter up your inbox. (You can also 'Mute' chatty public waves that did make it into your inbox if you're not interested in every new update.)

The opposite of with:public, the with:me search is very useful for just seeing waves that are explicitly with you as an individual (versus in the public group). To limit your results to only waves you've updated, use by:me.

Other search operators include tag: for tags, and has: for attachments like images, files, and gadgets. For example, has:gadget returns waves with gadgets; has:image returns waves with images in them, and has:attachment returns waves with gadgets, images, or files. You can combine search operators, like with:public has:gadget, and use the minus sign to exclude waves as well, like -has:image. Here's the full list of Wave's advanced search operators.

Make a Wave Public

Now that you know how to find public waves, you probably want to make one of your waves public—especially if you don't have many friends on Wave yet—but there's no one-click button to make a wave public. The trick is to add public@a.gwave.com to your contacts list. To do so, click the + button on the bottom right of your Contacts module. Type public@a.gwave.com into the Address field, and even when Wave says 'User does not have a Google Wave account', press Enter. The public group will appear in your contacts list, as shown. Add public to any wave you want to make public, but be prepared: Public waves often get destroyed by newbs and bots who haven't been in Wave long enough to grok the etiquette (see below). Also note that if you switch computers, you may have to add public@a.gwave.com to your contacts list again.

Know Wave's Bot Etiquette (and Bounce Unwanted Bots)

One of the biggest problems with public waves is that anyone can edit them or add recipients to them: including content-changing, and sometimes busted, bots. When you do your with:public search, you'll find dozens of waves that have been destroyed by newbs adding bots to them that delete or mangle the existing content so bad that even playback is broken. Good Wave etiquette dictates that you don't add bots to public waves. If you want to mess with a public wave, from its menu choose 'Copy to New Wave' and go to town with your private copy.

If you've created a public wave and someone added a bot to it that you want out, add the Bouncy bot to your contacts (bouncy-wave@appspot.com). Then, add Bouncy to the wave, and reply to it adding the command bounce:botaddress, replacing botaddress with the email address of the bot to bounce. Bouncy will oust the unwanted bot from your wave. This only works on bots. After Bouncy's done his job, you can delete the wave with the command and Bouncy's response. Speaking of...

Garden Your Waves

Like a wiki, useful and popular waves require oversight and gardening, or else they fall in to disrepair or go out of date or get vandalized (especially if they're public). You can oversee, clean up, edit, and update any wave you're a participant in, and everyone will appreciate it if you do.

First, empty 'blips' or replies are a common occurrence around Wave, which is still kind of twitchy in different browsers and new to a lot of folks who might accidentally hit Enter when they didn't mean to reply. Delete empty blips when you come across them by clicking on the wave action drop-down on the top right of it, and choosing 'Delete.'

To automate this process on waves you create, add the Sweepy bot (sweepy-wave@appspot.com) to your contacts and to the wave itself. Sweepy will not delete existing empty blips, but it will delete any newly-added empty replies automatically. (Sweepy is one of the very few bots that may supersede the 'never add bots to public waves' rule, as Sweepy's functionality cleans up the wave. For more on bots and gadgets, see this Google Wave Extensions list.)

If a wave becomes totally destroyed and you want to restore it to a former useful state, use its playback feature. Pause at the revision you want, and use the 'Copy to a new wave' menu item to fork it into a new copy.

Bookmark a Custom Wave Layout

Netbook owners or those who keep Wave open in a sized-down window appreciate the ability to minimize unneeded Wave modules and maximize the reading or writing area on the wave you're working on at the moment. To load Wave with certain modules minimized by default, you can use a custom Wave URL with the #minimized parameter. For example, https://wave.google.com/wave/#minimized:nav,minimized:contact launches Wave with the Navigation and Contacts modules minimized. The https://wave.google.com/wave/#minimized:nav,minimized:contact,minimized:search URL minimizes Navigation, Contacts, and Search panes as shown here.

URL-observers will also notice that every individual wave has an ID that appears in the URL when you click on it. This means you could bookmark or IM a link to a public wave to anyone on Wave.

What Doesn't Work in Wave

The Wave Preview is a pre-beta webapp, and lots of things aren't working or just simply aren't implemented yet. From the 'it's not just you' department, here are some notes on what's not working:

  • Some bots and gadgets: A couple of bots I mentioned in my first look at Google Wave worked in the Developer preview, but don't work in the regular preview, namely Bloggy, Polly, and several others. The best way to see if a bot works is to just try it, or search for its name and the with:public operator to find discussions about it.
  • Requests, or waves from other servers: The Requests link in the Navigation pane is presumably for you to approve waves that come from other servers. However, while Wave server federation is part of the protocol, it's not yet working for real. That's why users on the Developer preview can't wave at users on googlewave.com. Yet.
  • Removing Wave recipients: Right now you cannot remove non-bots from a Wave once they've been added to it. Copy your wave to a new one and reinvite folks instead.
  • Uploading files (that are not images): While you can drag and drop images into a wave (and be sure to try that, it's fantastic fun), you can't upload other filetypes using the Files button yet.
  • The 'I'm online' green dot: When the Wave preview first launched, a pretty green dot would show you which of your contacts was online at the moment. This feature had a serious bug involved so the Wave team had to pull it. Expect those dots to come back in the next few weeks.
  • Playback (sometimes): If a wave is huge and has lots of revisions or a bot has made extreme changes, playback on waves can be wonky or just not work at all.
  • Blog publishing: The Bloggy bot does not work right now, and while the Madoqua bot will give you Javascript embed code to add to your blog, ONLY people who are signed into Wave will be able to see your wave (and it has to be public, which makes it editable by anyone). So, while publishing waves on any web page with proper permissions and access by anyone on the web will happen, it's not working right now.

Overall, Wave is a rich platform with a huge community of people discovering more of its ins and outs and quirks and workarounds every day. Wave users, what are your favorite tricks and tips for getting more out of Wave? Post up your comments below or in this public wave.

Gina Trapani, Lifehacker's founding editor, really hopes to meet Dr. Wave someday to tell him just how shiny everything is. Her weekly feature, Smarterware, appears every Wednesday on Lifehacker. Subscribe to the Smarterware tag feed to get new installments in your newsreader.






"

Tuesday, 6 October 2009

A MySQL problem or something else?

A MySQL problem or something else?: "Sometimes problems manifest inside of MySQL but the MySQL server is really not the problem. A good example is how MySQL uses reverse DNS lookups for authentication.



The Problem



You are alerted to a problem with a MySQL server either by Nagios or whatever… You log into the server and everything seems to be working correctly until you run “show full processlist”. The majority of your connections are in an “Unauthenticated” state and the rest are in some other state, probably “Sleeping”. You speak with the lead developer and they state that there have not been any code changes for 1 month. It’s an odd problem, when you see it; however, the solution is not that obscure when you think about how MySQL uses DNS.



The Solution



When you restart MySQL with “skip-name-resolve” enabled you might think that all of your problems are gone based on the issue describe above. Well, just make sure that all of the hosts in the mysql.user table are IPs or IP ranges and not FQDN.



Not only will enabling 'skip-name-resolve” save time and money if DNS goes down, it is also good for performance. Here are some quick tests to illustrate the performance gains:



-- Performance Benefit



Without “skip-name-resolve” enabled



shell> date; mysql -u root -h 192.168.0.1 ; date

Mon Oct 5 15:20:40 PDT 2009

ERROR 1130 (00000): Host '192.168.0.2' is not allowed to connect to this MySQL server

Mon Oct 5 15:20:43 PDT 2009



Note the time change is 3 seconds



With “skip-name-resolve” enabled:



shell> date; mysql -u root -h 192.168.0.1 ; date

Mon Oct 5 15:22:01 PDT 2009

ERROR 1130 (00000): Host '192.168.0.2' is not allowed to connect to this MySQL server

Mon Oct 5 15:22:01 PDT 2009



Note that the server comes back immediately with the same error



Best Practice

I always make sure the “skip-name-resolve” is in any MySQL configuration file (my.cnf) in all of my installations.
PlanetMySQL Voting:
Vote UP /
Vote DOWN"

Saturday, 3 October 2009

Taste test: Innobackup vs. Xtrabackup

Taste test: Innobackup vs. Xtrabackup: "

Firstly, I have to thank my co-workers Singer Wang and Gerry Narvaja for doing a lot of the work that resulted in this comparison.


After running both InnoDB Hot Backup and Xtrabackup, we have found that there is a measurable but not large difference between the resources that Xtrabackup and InnoDB Hot Backup consume.


Xtrabackup:

  • Free


  • takes 1.1% longer (2 min during a 3 hour backup)


  • uses 1.4% more space (1G more in a 70G backup — this was for uncompressed backups)


  • uses 1.115% more cpu overall


  • split as 0.12% user, 0.66% nice, 0.025% system, 0.31% more iowait, 0% more steal




InnoDB Hot Backup:

  • Commercial


  • slightly fewer resources (see xtrabackup)



  • The server has 32G of RAM, 8 Dual-Core AMD Opteron(tm) Processor 8220, with a speed of 2800 Mhz (2.734 Ghz) and a cache size of 1024 Kb, and is also used as a reporting server. We ran Xtrabackup on odd days, and InnoDB hot backup on even days. Both are stable and have responsive developers, and both projects have developers that know the internals of MySQL.


    The clients of ours that use InnoDB Hot Backup (including the client this test was run on) already have purchased indefinite licenses for it. For those clients, there is not a big reason to switch to Xtrabackup.


    For companies that are not using a hot backup solution yet, we recommend both InnoDB Hot Backup and Xtrabackup, and they end up choosing what best fits their environment. Some companies shun InnoDB Hot Backup because of its price tag. Some companies are wary of Xtrabackup because it has been less than a year since the release was announced, and feel better paying money to a company for their backup solution. I did not put the “feelings” in the lists above, because they are dependent on the environment — I have the same trust in the skill and commitment of the developers of Xtrabackup and the developers of InnoDB Hot Backup. Other such feelings might be “supporting open source” or “using the backup software that is developed by a partner organization.”


    We felt it was easier to set up InnoDB Hot Backup than Xtrabackup, but that may be because we have been using InnoDB Hot Backup for years. However, neither setup is too complex — it is not necessary to have a senior-level DBA set up the backups, no matter which software you choose.


    PlanetMySQL Voting:
    Vote UP /
    Vote DOWN"

    Scaling writes in MySQL

    Scaling writes in MySQL: "We use MySQL on most of our projects. One of these projects has a an access pattern unlike any other I've worked on. Several million records a day need to be written to a table. These records are then read out once at the end of the day, summarised and then very rarely touched again. Each record is about 104 bytes long (thre's one VARCHAR column, everything else is fixed), and that's after squeezing out every byte possible. The average number of records that we write in a day is 40 million, but this could go up.

    A little bit about the set up. We have fairly powerful boxes with large disks using RAID1/0 and 16GB RAM, however at the time they only had 4GB. For BCP, we have a multi-master set up in two colos with statement level replication. We used MySQL 5.1.

    My initial tests with various parameters that affect writes showed that while MyISAM performed slightly better than InnoDB while the tables were small, it quickly deteriorated as the table size crossed a certain point. InnoDB performance deteriorated as well, but at a higher table size. The table size turned out to be related to the innodb_buffer_pool_size, and that in turn was capped by the amount of RAM we had on the system.

    I decided to go with InnoDB since we also needed transactions for the summary tables and I preferred not to divide my RAM between two different engines. I stripped out all indexes, and retained only the primary key. Since InnoDB stores the table in the primary key, I decided that rather than use an auto_increment column, I'd cover several columns with the primary key to guarantee uniqueness. This had the added advantage that if the same record was inserted more than once, it would not result in duplicates. This small point was crucial for BCP, because it meant that we did not have to keep track of which records had already been inserted. If something crashed, we could just reinsert the last 30 minutes worth of data, possibly into the secondary master, and not have any duplicates at the end of it. I used INSERT IGNORE to get this done automatically.

    Now to get back to the table size limit that we were facing. Initial tests showed that we could insert at most 2100 records per second until the table size got to a little over the innodb_buffer_pool_size and at that point it degraded fairly rapidly to around 150 records per second. This was unacceptable because records were coming in to the system at an average rate of 1000 per second. Since we only needed to read these records at the end of the day, it was safe to accumulate them into a text file and periodically insert them in bulk. I decided to insert 40,000 records at one time. The number I chose was arbitrary, but later tests that I ran on batches of 10K, 20K and 80K showed no difference in insert rates. With batch inserts, we managed to get an insert rate of 10,000 records per second, but this also degraded as soon as we hit the limit going down to 150 records per second.

    System stats on the database box showed that the disk was almost idle for most of the run and then suddenly shot up to 90-100% activity once we hit this limit, so it was obvious that at this point, the DB was exchanging data between buffers and disk all the time.

    At this point, someone suggested that we try partitioning, which was available in MySQL 5.1. My first instinct was to partition based on the primary key so that we could read data out easily. However, reads weren't really our problem since we had no restriction on how fast they needed to be (at least not as much as writes). Instead, I decided to partition my table based on the pattern of incoming data.

    The first part was obvious, use a separate table for each day's data. On a table of this size, DROP TABLE is much faster than DELETE From <table> Where ..., and it also reclaims lost space. I should mention at this point that we used file_per_table as well to make sure that each table had its own file rather than use a single innodb file.

    Secondly, each table was partitioned on time. 12 partitions per day, 2 hours of data per partition. The MySQL docs for Partitioning were quite useful in understanding what to do. The command ended up looking like this:
        CREATE TABLE (
    ...
    ) PARTITION BY RANGE( ( time DIV 3600 ) MOD 24 ) (
    Partition p0 values less than (2),
    Partition p0 values less than (4),
    Partition p0 values less than (6),
    Partition p0 values less than (8),
    Partition p0 values less than (10),
    Partition p0 values less than (12),
    Partition p0 values less than (14),
    Partition p0 values less than (16),
    Partition p0 values less than (18),
    Partition p0 values less than (20),
    Partition p0 values less than (22),
    Partition p0 values less than (24)
    );
    The time field is the timestamp of incoming records, and since time always moves forward (at least in my universe), this meant that I would never write to more than 2 partitions at any point in time. Now, a little back of the envelope calculations:
        44M x 102 bytes = approx 4.2GB
    2x for InnoDB overhead = approx 8.4GB
    +10% for partitioning overhead = 9.2GB
    /12 partitions = approx 760MB per partition
    This turned out to be more or less correct. In most cases total table size ranges between 8-10GB, sometimes it goes up to 13GB. Partition sizes range from less than 700MB to over 1GB depending on the time of day. With 4GB of RAM, we had an innodb_buffer_pool set at 2.7GB, which was good enough to store two partitions, but not good enough to work on any other tables or do anything else on the box. Boosting the RAM to 16GB meant that we could have a 12GB buffer pool, and leave 4GB for the system. This was enough for 2 partitions, even if the total number of records went up, and we could work on other tables as well.

    After partitioning, tests showed that we could sustain an insert rate of 10K rows per second for some time. As the table size grew past 10 million records, the insert rate dropped to about 8500 rows per second, but it stayed at that rate for well over 44 million records. I tested inserts up to 350 million records and we were able to sustain an insert rate of around 8500 rows per second. Coincidentally, during Michael Jackson's memorial service, we actually did hit an incoming rate of a little over 8000 records per second for a few hours.

    One more BotE calculation:
        8500 rows per second  x  86400 seconds per day = 734.4 Million records per day
    Considering that before this system was redesigned it was handling about 7 Million records per day, I'd say that we did pretty well.

    PlanetMySQL Voting:
    Vote UP /
    Vote DOWN"

    Friday, 2 October 2009

    Is the query cache useful?

    Is the query cache useful?: "

    Mark Callaghan posted a good test of the MySQL query cache in different versions. His tests clearly show that in 5.0.44 and 5.0.84 and 5.1.38, there is more query throughput when the query cache is disabled.


    However, the tests are skewed — not on purpose, I am sure, and Mark admits he has not used the query cache before — but they are skewed all the same. Mark’s error was that he assumed he could just turn on the query cache and see if it works. Most features of MySQL do not work that way — you have to understand the strengths and weaknesses of the feature in order to use it properly.


    Mark’s benchmark definitely reinforces that turning on the query cache without any knowledge of your system is a bad idea, and I agree with him on that. But it does not in any way mean that the query cache is always a bad idea. In fact, the MySQL manual page at http://dev.mysql.com/doc/refman/5.1/en/query-cache.html has some caveats about when the query cache is useful and when it is not useful.


    It is important to know how the MySQL query cache works, so I will first explain that, and then explain why Mark’s test is not a very good broad generalization. MySQL’s query cache is not useful all the time, but it can be quite useful! If you are already familiar with the query cache, you can skip ahead to why Mark’s benchmark is skewed.




    How to use the MySQL query cache

    Firstly, there are a few ways to use the MySQL query cache. You can disable it, which means no queries are cached; you can set it to cache all queries, and use a special keyword to not cache queries (replace SELECT with SELECT SQL_NO_CACHE). query_cache_type=1 or ON will set the query cache in this way.


    You can also set it to cache no queries except those that have a special keyword — you guessed it, replace SELECT with SELECT SQL_CACHE and a query will attempt to be cached. To set the query cache in this way, set query_cache_type=2 or DEMAND.


    What queries are cached

    Regardless of which method you choose, not all possible queries are cached. Only deterministic SELECT statements are cached — a statement such as SELECT count(*) from tbl is deterministic, while SELECT NOW() is non-deterministic for the purpose of the query cache.* Queries that use user-defined functions, temporary tables, LOCK IN SHARE MODE, FOR UPDATE, INFORMATION_SCHEMA or mysql system tables are not cached. Most SELECT subqueries are not cached. SELECT queries that are part of stored functions, triggers, views and events are not cached. However, in MySQL 5.1, SELECT queries that contain a view can be cached. The MySQL manual page at http://dev.mysql.com/doc/refman/5.1/en/query-cache-operation.html has more detailed information on what is allowed and what is not allowed.


    In the query cache, a hash of the query is stored along with the result. There is a variable, query_cache_limit, which sets an upper limit on the size of the result set that can be cached. So even if a query can be cached, it may not be cached if the result set is larger than query_cache_limit.


    How the query cache is used

    The lifecycle of a non-prepared SELECT statement when the query cache is on (query_cache_type > 0) is:


    1) hash the SELECT query

    2) check the hash against the query cache

    3) if hash matches, returned the result set from the query cache. If not, the query is sent to the parser and executed in the usual manner, and results are stored in the query cache if the query is cachable.


    This means that having the query cache on has some overhead, even if no queries are ever cached.


    A query (and its result) is removed from the query cache when it is invalidated or pruned. A query is invalidated when any table it refers to has been changed, even if the changes do not affect the actual result set in the query cache. A query is pruned when a new query needs to be inserted into the query cache and there is no room; the query cache prunes queries using a least recently used (LRU) algorithm.


    In other words, there will be a lot of unnecessary overhead with the query cache if a table is often written to, because queries using that table will be constantly removed from the query cache. This does not mean that if you have some tables that are frequently written to, you should turn the query cache off — you can use the query_cache_type of ON with the SQL_NO_CACHE keyword to cache all except some queries, or you can use the query_cache_type of DEMAND and the SQL_CACHE keyword in SELECT queries to cache no queries except those you specify.


    Why Mark’s Benchmark is skewed


    It is important to note that InnoDB was set up with:

    innodb_buffer_pool_size=2000M


    and the sysbench program was run with:


    ../sysbench --test=oltp --oltp-table-size=2000000 --max-time=180 --max-requests=0 --mysql-table-engine=innodb --db-ps-mode=disable --mysql-engine-trx=yes --oltp-read-only --num-threads=$nt run


    I will explain what the important sysbench variables are in context.


    1) The benchmark used sysbench in OLTP mode against an InnoDB table. The InnoDB buffer pool is hot after the table is created and populated, while the query cache is empty and cold.


    InnoDB has its own cache — the InnoDB buffer pool. sysbench is run with –oltp-read-only, meaning there are no INSERT, DELETE or UPDATE statements. This is good; it means that the results are not skewed by query cache invalidations, though there may be pruning.


    The first thing sysbench does is preparation — it creates the table and populates it with data (2,000,000 rows as per oltp-table-size). After this is done, the InnoDB buffer pool (2000M in size) has gone from empty to containing data. I do not know how large the row size of the sysbench table is; however, I can do some calculations:


    2000 Mb * 1024 = 2,048,000 Kb / 2,000,000 rows = 1.024 Kb per row


    This means that in order for some data to *not* be current in the InnoDB buffer pool, the row size had to be approximately larger than 1 Kb per row.


    The manual at http://sysbench.sourceforge.net/docs/#database_mode shows the schema of the table that is used.


    CREATE TABLE `sbtest` ( `id` int(10) unsigned NOT NULL auto_increment, `k` int(10) unsigned NOT NULL default ‘0′, `c` char(120) NOT NULL default ”, `pad` char(60) NOT NULL default ”, PRIMARY KEY (`id`), KEY `k` (`k`)


    (note that you at least need to add a final parenthesis “)” for the query to work, and should also specify ENGINE=INNODB if you want to test on your system).


    So, that’s two 4-byte integers, and two character fields…for the sake of argument, let’s say you are using UTF-8 in MySQL 5.1, where utf8 is 3 bytes per character, that’s:


    4 + 4 + 120*3 + 60*3 = 548 bytes


    Let’s say you are using a version of MySQL that uses 4 bytes per character for utf8 (I know 6.0 was using that, not sure about 5.4):


    4 + 4 + 120*4 + 60*4 = 728 bytes


    So either way, all of the data in the table is already loaded in the InnoDB buffer pool when the test begins. The InnoDB buffer pool is already hot, whereas the query cache is empty.


    On systems where a query can be cached and used instead of executing and having to look on disk for data, using the MySQL query cache will give you *much* better performance.


    2) The query cache statistics are not given. It’s very possible that the only thing that was measured was how much overhead the query cache provides if it is never used.


    The queries that are run are the default (oltp-test-mode is not set, and it defaults to “complex”) which can be seen under the “Advanced transactional” heading in the sysbench manual at http://sysbench.sourceforge.net/docs/#database_mode. Only read queries are done, so the queries are:


    SELECT c FROM sbtest WHERE id=N

    SELECT c FROM sbtest WHERE id BETWEEN N AND M

    SELECT SUM(K) FROM sbtest WHERE id BETWEEN N and M

    SELECT c FROM sbtest WHERE id between N and M ORDER BY c

    SELECT DISTINCT c FROM sbtest WHERE id BETWEEN N and M ORDER BY c


    The values for the variables in the query are chosen at random, though they are sensible values. The testing time is very short, only 3 minutes of running time (sysbench is called with max-time=180). It is quite possible that all the SELECT queries were put into the query cache and there was never a query cache hit. Of course there will be a lot of overhead if the query cache is never used! Particularly if it has to prune for more memory.


    I would like to see Qcache_hits, Qcache_inserts, Com_select (number of SELECT statements that did not use the query cache) and Qcache_lowmem_prunes. That is what I look at for any system that has the query cache running, so I can determine the effectiveness of the query cache.


    There is more in-depth information on how to find the usefulness of the query cache, query cache fragmentation, and a few ways to cache more queries in the MySQL Administrator’s Bible on pages 427-434 — part of the “Caching with MySQL” chapter. I used the book to help me write this blog post, so I do think it is fair to cite my sources….even though it happens to be a source I created (and that’s why I consider it a shameless plug, I have no shame citing my sources)!


    —————-


    So that all being said, the query cache is extremely useful when it is used for repeated queries. The benchmark Mark performed most likely did not actually use this. I have seen production environments fall apart when someone turned on on the query cache for all queries; Mark’s benchmark proves that it is not a good idea to randomly turn on the query cache. You have to know what you’re doing.


    * for the purpose of replication, it is deterministic, but that’s another topic.


    PlanetMySQL Voting:
    Vote UP /
    Vote DOWN"

    Sike's shared items