My fun with MySQL on EC2

Morgan is looking in to EC2 on MySQL, so I thought I'd pipe up about stuff I've been playing with.

The ephemeral nature of the data is troubling, because at best you're going to have some lag before you can back stuff up to S3 or some other place. (Unless that was happening continuously... but we'll come back to that) On the other hand, if you're doing app sharding or something similar, this essentially just makes you plan that your machines can all die at any time. If you used Google's semi-sync replication patch, you could easily spin up little replication clusters as needed.

Hm. Clusters. Well, I'm also a fan of MySQL Cluster. What if you ran MySQL Cluster on a single ec2 node (both data and sql nodes)? What if, further, you wrote (and by you, I mean me... code coming soon, I promise) an AsyncFile implementation for Cluster that read and wrote to S3 instead of local disk. Cluster itself is already decoupled from disk write latency. Sounds like a good UC talk...

Then you could do the same thing with a multi-node cluster, but Amazon doesn't let you control the network between EC2 nodes, so the latency there could kill you.

I have put together a few scripts for spinning up an EC2 node with MySQL (and Cluster) ready to go, but I'm sitting in an airport right now, so I'll have to post the code later.

I think the possibilities for scale-out here are fantastic, but like all application partitioning approaches, they do require some engineering of the application to take advantage of it.
0 comments
Tags: ha

Running more than one ndbd on a machine

Personally, I'm not a fan of more than one ndbd per machine...

Diamond Notes » Fun with Running a Cluster on Two Servers
Others might argue with this, but I would never put the SQL nodes on the same servers as the ndbd nodes for production. Some say you can run multiple ndbd nodes on the same server and I am more comfortable with that since I can lock the ndbd daemon into memory and know its not going to change (my ndbd nodes on those two servers have been at exactly 71.3% since I started them up. If I had servers for the ndbd nodes that had 16+ gigs of RAM I might start allocating 4 gigs of RAM to a ndbd daemon with 3+ daemons per node. My understanding is that this helps keep the transactional logs for the nodes under control. When you do a ndbd node restart it takes less time for a node to get up and running because of the smaller files to read. I might be mistaken and its too late for me to look it up :) Anyone got other reasons or maybe (if I am right) someone can elaborate.


First of all, I'm very excited to see that Cluster is being used for MogileFS here. I've actually been thinking it might be fun to write a MogileFS::Store::NDB class to use NDB/Perl ... but that's another story.

One of the things that's nice about NDB is that it spread across mutliple machines. Now, granted, in development we can't always do this. I run NDB on my laptop all the time, so I certainly feel the pain there. But with a multi-node design, I say take advantage of it. People on other architecture are always asking how they can spread the load more easily across multiple machines, and here you can. If you need 8 data nodes, get 8 machines.

Practically, there is another reason. If you put 3 data nodes on a single physical machine, then if that machine crashes, you have not a single node failure, but 3 nodes failing at the same time. Although there is no specific reason that this won't work, it's also essentially an edge case and not really tested all that well. Other people may disagree with me here, especially as currently running multiple ndbd's on a single box is the only way to take advantage of more that 2 CPU cores, but I'm just not a fan. For something like this, go get a bunch of 2 CPU boxes.

To address the larger question, though, you can certainly spread the write load and the redo log burden by having more data nodes, and having the data distributed across more data nodes will certainly make the log recovery shorter on any one given node. However, there is a price to pay here in query latency. The more data nodes you have, the more nodes your data might be on. If you are not using the NDB API (or any of the NDB/Connectors) then there is no optimized node selection going on. (I've heard someone is working on an Optimized TC Selection patch for mysqld, but it's not in the mainline yet) So if you go from 2 nodes to 4 nodes, you went from a 100% chance that the TC will have your data and not have to ask someone else, to a 50% chance. At 8 nodes you are at a 25% chance that the TC selection will select a node with your data. That's for primary key operations. If you're doing a scan, then your data is going to (most likely) be on all of the nodes, which can be good or bad. But if you're doing MogileFS queries, perhaps the extra milliseconds of latency isn't a concern in this case and you'd rather have faster node recovery. I'd test that hypothesis out and see how much better the recovery is.

Another potential reason to have more data nodes even with the higher latency costs (and extra network traffic as that many more nodes have to talk to that many more nodes) is scalability. Of course, more nodes mean more scaling. But as of now ADDING a data node is not an online operation. Adding more memory can be done in a rolling fashion. So if you think you might need 8 data nodes worth of CPU processing, go ahead and get 8 data nodes with 4G of RAM a piece. Then as you need to store more data, stick in more RAM. Before long, you'll have a nice 256G system... :)

SO... as with everything cluster, there is certainly room on both side of the argument as to what's best here. And as always, testing is the best bet to see how it maps to your environment.

(Also, it's 4AM at the moment, so please forgive me if this rambles a little.)
0 comments
Tags: ha

Join Syntax changes in 5.0 (not a bug)

Our friend Dathan recently suggested that The Quality of mySQL lately sucks.
I've just ran into yet another obvious bug that has made it's way into production.

While I'm not going to argue that more unit tests would be a good thing, I'd like to point out that what he's referring to is not so much a bug as it is a change that happened (and was documented) in 5.0.12:
Beginning with MySQL 5.0.12, natural joins and joins with USING, including outer join variants, are processed according to the SQL:2003 standard. The changes include elimination of redundant output columns for NATURAL joins and joins specified with a USING clause and proper ordering of output columns. The precedence of the comma operator also now is lower compared to JOIN, LEFT JOIN, and so forth.
These changes make MySQL more compliant with standard SQL. However, they can result in different output columns for some joins. Also, some queries that appeared to work correctly prior to 5.0.12 must be rewritten to comply with the standard. For details about the scope of the changes and examples that show what query rewrites are necessary, see Section 12.2.7.1, “JOIN Syntax”.

What this means is that the query in the bug report:
SELECT p.id, gt.object_id FROM Photos p, PhotosExtra px LEFT JOIN GeoTagged gt ON gt.object_id=p.id WHERE px.photo_id=p.id AND p.id = 2173;
should be rewritten to either:
SELECT p.id, gt.object_id FROM PhotosExtra px, Photos p LEFT JOIN GeoTagged gt ON gt.object_id=p.id WHERE px.photo_id=p.id AND p.id = 2173;

or even:
SELECT p.id, gt.object_id FROM , Photos p LEFT JOIN GeoTagged gt ON gt.object_id=p.id JOIN PhotosExtra px ON px.photo_id=p.id WHERE p.id = 2173;

This is a common thing people have to deal with when upgrading to 5.0.
0 comments
Tags: ha

Multiple bond interfaces in CentOS/RHEL

Kris writes:
I had a machine with 4 nics that I wanted to bond 2 by to. I had no problem getting the bond0 device up witn any of the interfaces, however getting a bond1 up always resulted in the above error.
The friendly guys from #centos on freenode pointed me to the missing config.
options bonding mode=4 max_bonds=4


An important thing to keep in mind here is that in the RHEL/CentOS initscripts package, these options are global. There is no way to set a different set of options for each bond. So, if for instance, you had 4 NICs and wanted to have 2 of them bonded in mode 1 and 2 of them in mode 4, you're SOL. (Unless, of course, you go for insmodding everything by hand. But that's ugly)
0 comments
Tags: ha

About

The MySQL HA blog is focused on MySQL High Availability, Cluster and Performance Tuning, although we'll be sure to talk about other things as well. Monty and Alexander are both Senior Consultants for MySQL and would be more than happy to have someone in our sales department talk with you about consulting services.
0 comments
Tags: ha