Monday, March 29, 2010

OK, you have waited long enough, here's my take on NoSQL

I have to admit I'm getting old, and I am now scaringly close to being a sad old git, and not only that, I'm a database guy also, and I have worked with SQL based relational databases for more than 20 years now.

So considering my age and heritage, I really should just dispose the NoSQL movement as something for those young kids with earrings and a baseball cap (and to add insult to injury, the cap is worn backwards) and that any serious database dude like myself, with my loads of experience (like the invaluable experience of having run Oracle on a Wang word-processor. Real valuable stuff I tell you). But no, you will not hear me do that. But also, you will not hear me say that NoSQL key-value stores will replace all SQL databases within 5 years (If I worked for an analyst and was paid dearly to say things like that, I might have, though. Any takers?).

My take is actually quite simple. The strength of the relational model is that it is inredibly generic. The lack of a specific order and hierarchy makes it even more generic. I think few people would argue that more or less all applications served by NoSQL could just as well be served by a SQL database, if it wasn't for two things:
  • Scalability - The lack of the strict consistency rules of RDBMS heritage in most NoSQL implementations makes them much more scalable. The very nature of most NoSQL stores is distributed, and the lack of strict distributed consistency makes this distribution scalable beyond what is usually possible with an RDBMS, given the same platform etc.
  • Performance - This is largely due to the above, i.e. a NoSQL store being more scalable makes it easier to cram more performance out of it.
Now, with all this in mind, am I saying that NoSQL has all the advantages of an RDBMS, but with much better scalability? Nope, no way, José.

The strict consistency requirements of an RDBMS is also an advantage. It's not so that, if I understand them correctly, the propoents for NoSQL stores thinks that consistency is bad, it's just that they don't want to pay the price in terms of performance for it. And to be frank, although in many cases data inconsistency is acceptable, it still has to be controlled, an uncontrolled consistency, i.e. you don't know how inconsistent your store is and in what way or anything, is not something we want. So even a NoSQL store is limited.

So it all comes down to performance then. We sacrifice consistency to gain performance through scalability. Right? If you agree to that, then I think NoSQL is not a long term solution. It's not that I am saying that "NoSQL is for kids, real databases needs SQL", that was the argument against SQL based databases in the 1980's largely, where Hierarchical databases still ruled, and SQL just had a too big overhead, or so it was thought. The differerence here is that SQL had higher functionality than the competing technologies of the 1980's, but not enough performance in many cases. But performance is bound to go up. All the time. And for much less money. At least for a while to come. Look at virtualization. I've been a proponent for that for quite a while, and just a few years back, the argument against it was that "performance sux". Well, compared to raw iron maybe it did, but that wasn't the point. The point was, did I get enough performance? And in many cases you did, with an environment that was a lot easier to manage and at a low cost.

What this means to me is that there is a place for NoSQL stores right now, where the performance and size requiements are really high, and where one is willing to compromize consistency. But a technology that limits functionality, features and ease-of-use at the price of performance will continue to be a niche technology. But that doesn't mean it's useless or anything, quite the opposite, I'm a pragmatist at heart, and whatever works, works. But if I had the choise of storing my data in consistent or in-consistent state, and if both solutions provided enough performance for my needs, I'd go consistent any time.

And then there is one more thing. The scalability of the NoSQL stores is largely due to it's distributed nature. And there are arguments out there that says that you cannot create a consistent, distributed, scalable datastore. I think you can, I'm convinced of it actually. There may be other compromises needed to achieve that, but that it can be done I am sure.

/Karlsson

Sunday, March 28, 2010

More fun with the MySQL Audit Plugin API

The Audit API has more uses that you may think! When a statement is executed in the server, the notification function in this API will be called, and we can use that do some interesting things!

Like: Ever wanted to know what the most executed query in your running system is? I mean the information is in there somewhere, right, it's just q question of how to get at it? And frankly, I don't think the queries:
SELECT * FROM user_data WHERE user_id = 57;
and
SELECT * FROM user_data WHERE user_id = 113;
Should count as different queries? I mean, hey, the issue is that the application may be issuing the same query too many times, with different arguments mostly, but still the query:
SELECT * FROM user_data WHERE user_id = <somevalue>

Is executed too often? And if so, how can I figure it out? Well, using MySQL 5.5 with a combination of the Audit Plugin API and the INFORMATION_SCHEMA API, you can do this. The principle is simple:

The logging of queries
This is handled by the notification function in the Audit API. In the plugin, we have a an array of queries, and for every query we see, we "normalize it", in the sense that all literals are replaced by question marks, i.e. the query above would be represented as:
SELECT * FROM user_data WHERE user_id = ?
Then we look for this query among the queries I already know about. If the query is found, I just increment teh execution cound for it, and if it is not found, I add it. I keep track of X number of queries, and I log the time each query is added, so when I add a new query, and there already are X queries logged, I get rid of the one that was executed longest ago. And LRU list in short.
In the sample I code I prove evetually, I also log some other data, but this is the basics. And the list is stored in memory by the way.

Seeing the latest queries
For viewing the queries, I use an INFORMATION_SCHEMA plugin, that is part of the same plugin library as the one above. although this is a different type of plugin. This is again pretty simple. The plugin will expose an INFORMATION_SCHEMA table that contains the list of the queries above, and when I select from that table, I materialize the list as a table. As this will then look like any normal table, you can use just about any SQL operation on it, like ordering, filtering specific queries etc. And all this with a simple SELECT!

The issues
Will this affect performance? Yes, sure, but I don't really know to what extent right now, I havent gotten around to test that. And then there is one more issue: You need MySQL 5.5 m3 or above, which currently means you need to get it from Launchpad, there are still (March 29) only m2 binaries to be found at http://dev.mysql.com.

Example code
Now it's time for some sample code. Lets first have a look at how it works. There is an information_schema table introduced by the plugin called my_is_proclist, and this is the one we are interested in. I have a table in the test database that I issue queries on. And it looks like this then:
MySQL [test]> select last_executed, num_executes, statement from information_schema.my_is_proclist where statement like '%from t1%';
+---------------------+--------------+-------------------------------+
| last_executed | num_executes | statement |
+---------------------+--------------+-------------------------------+
| 2010-02-28 15:12:26 | 4 | select * from t1 |
| 2010-02-28 15:34:07 | 6 | select * from t1 where c1 < ? |
+---------------------+--------------+-------------------------------+
2 rows in set (0.00 sec)

MySQL [test]> select * from t1 where c1 <>
+------+------+
| c1 | c2 |
+------+------+
| 1 | 16 |
| 2 | 16 |
| 3 | 16 |
+------+------+
3 rows in set (0.00 sec)

MySQL [test]> select last_executed, num_executes, statement from information_schema.my_is_proclist where statement like '%from t1%';
+---------------------+--------------+-------------------------------+
| last_executed | num_executes | statement |
+---------------------+--------------+-------------------------------+
| 2010-02-28 15:12:26 | 4 | select * from t1 |
| 2010-02-28 15:34:12 | 7 | select * from t1 where c1 < ? |
+---------------------+--------------+-------------------------------+
2 rows in set (0.00 sec)

As you can see, the counter goes of what I execute the query in question. Nothing complicated, and as you can see, I can do all sorts of filtering on the INFORMATION_SCHEMA table.

Installing the plugin
The plugins are contained within one library. I have the sourcecode and a simple makefile downloadable here: http://www.papablues.com/src/my_proclist.tar.gz

Modify the supplied Makefile appropriately and run:
make
make install
Note that you must have rights to write to the MySQL Server plugin directory for the install to work! Once this is done, you must tell the MySQL server about the plugins:
install plugin my_proclist soname 'my_proclist.so';
install plugin my_is_proclist soname 'my_proclist.so';
And that's it! Note that there is also a status variable that shows how many statement I currently keep track of. Currently, the max number of statement I track is 30, but there is a simple
#define NUM_STMTS 30
in my_proclist.cc that you may edit to fix that.


/Karlsson

Friday, March 26, 2010

More on the MySQL Audit Plugin interface

I will write some more on this interface eventually, following up my previous MySQL Audit API post, and will show some ideas and hopefully push some interesting code (I have ideas!). But note that the API so far isn't well documented (only source so far), but there is work underway to fix this by the friendly MySQL docs team.
Already I have realized that Audit events are different than I thought. The source of the event is currentlyt either from inside the parser code or from the general log code. The events I got looked like general log events, so I just imaginged this was the source of what I saw, and I never relaized that there was another possible source, the parser. Actually, when the general log is not on, the parser events is all you get, but as I have shown, this is usually good enough. For the log events to be received, you still have to have the general log on. In practice, this doesn't seem to be much of a difference, but I'll keep an eye on it once the documentation is in place, and if there is a use for having Audit general log events, without having the general log per-se on, then I will create a worklog for that (along the lines of having the general_log variables have 3 values (ON, AUDIT_ONLY and OFF) or something like that.

/Karlsson

Monday, March 22, 2010

The MySQL Audit plugin API

MySQl 5.5 is getting more and more solid, and one thing recently (at least I think so) pushed is the Audit plugin. Currently, this is only in the source repository (I tried from 5.5.4-m3). This prugin is actually quite useful, more useful than you might expect. Any event that would cause a write to the general query log will send a notification to a function in this API, and note that this will happen even if the general query log is enabled or not.

The stuff that gets passed to the notification function is a struct with similar data that gets written to an entry of the general query log, but don't let this limit you, also passed is a pointer to the THD class for the thread that caused the notification. And if you haven't looked a lot at the MySQL sourcecode, note that the THD class has MANY members, and contains all sorts of information.

If you wanted to create your own general log, that would allow filtering on, say, specific nodes, statements, users or something, this is where to hook into for that. Another advantage over using the general query log, is that you can log a lot more information, by virtue of the THD being passed.

Currently, there is a lack of documentation for the AUDIT plugin API, but you can figure it out from the null_audit plugin that is part of the 5.5.4-m3 source. The API is pretty simple, and only three functions are usually needed, one called when initializing the plugin, one to handle the event notification, and one that is called after when deinitalizing the plugin. A complete plugin that does this, that is based on the null_audit one, but which is written to support C++, as I want to use the THD which is a C++ class, this is a requirement if you want to get at the THD (unless you are cheating that is).

To begin with, we need some headers and stuff:
#define MYSQL_SERVER
#include
#include <../sql/mysql_priv.h>
#include
#include
#include

#if !defined(__attribute__) && (defined(__cplusplus) || !defined(__GNUC__) || __GNUC__ == 2 && __GNUC_MINOR__ <>
#define __attribute__(A)
#endif

static FILE *log_fp;
static volatile int localhost_commands;

Then we need to init, deinit and notification functions:
static int my_general_log_plugin_init(void *arg __attribute__((unused)))
{
log_fp = NULL;
localhost_commands = 0;
return(0);
}


static int my_general_log_plugin_deinit(void *arg __attribute__((unused)))
{
fclose(log_fp);
return(0);
}


static void my_general_log_notify(MYSQL_THD thd, const struct mysql_event *event)
{
mysql_event_general *pEvent;

/* Open the log file, if not already done. */
if(log_fp == NULL)
log_fp = fopen("/tmp/my_general_log.log", "a");

/* Only log if on localhost. */
if(thd->net.vio->localhost && event->event_class == MYSQL_AUDIT_GENERAL_CLASS
&& log_fp != NULL)
{
pEvent = (mysql_event_general *) event;

localhost_commands++;
if(pEvent->general_query != NULL && *(pEvent->general_query) != '\0')
{
fprintf(log_fp, "%s;\n\n", pEvent->general_query);
fflush(log_fp);
}
}
}

As you see, this is kept real simple, so as not to confuse things. But it is rather powerful, as I have both the event and the THD data available. Before I compile the above, I also need to add the structs that control the plugin itself:
static struct st_mysql_audit my_general_log_descriptor=
{
MYSQL_AUDIT_INTERFACE_VERSION,
NULL,
my_general_log_notify,
{(unsigned long) -1}
};


static struct st_mysql_show_var my_general_log_status[]=
{
{"my_general_log_commands", (char *) &localhost_commands, (enum_mysql_show_type) SHOW_INT},
{0,0,(enum_mysql_show_type) 0}
};


mysql_declare_plugin(my_general_log)
{
MYSQL_AUDIT_PLUGIN,
&my_general_log_descriptor,
"my_general_log",
"Anders Karlsson",
"A general log that will log localhost access only",
PLUGIN_LICENSE_GPL,
my_general_log_plugin_init,
my_general_log_plugin_deinit,
0x0001,
my_general_log_status,
NULL,
NULL
}
mysql_declare_plugin_end;

The st_mysql_show_var struct provides a simple status value, that is displayed when you issue a SHOW STATUS command.

Beyond the above, you need a Makefile. I wrote mine myself, to keep things simple, and I also use no fancy macros, just the simple stuff:
MYSQL_BASE=../..
MYSQL_INST=/usr/local/mysql5.5/lib/mysql/plugin
CFLAGS=-D_HAVE_CONFIG_H -DMYSQL_DYNAMIC_PLUGIN -fPIC
all: my_general_log.so

my_general_log.o: my_general_log.cc
g++ $(CFLAGS) -I$(MYSQL_BASE)/include -I$(MYSQL_BASE)/regex -I$(MYSQL_BASE)/sql -c my_general_log.cc

my_general_log.so: my_general_log.o
g++ -shared my_general_log.o -o my_general_log.so

install: my_general_log.so
cp my_general_log.so $(MYSQL_INST)/my_general_log.so

If you are to try this yourself, you will need to modify the names and the paths and stuff, but I think you get the point and then run make and make install. The last thing to do is to enable the plugin. Just enter the mysql commandline client as root and run:
install plugin my_general_log soname 'my_general_log.so';

As foir the MySQL base source for this, either get 5.5.4-m3 from launchpad, or wait a few days and get it from http://dev.mysql.com when it is available there.

Hey, even being audited can be fun!

/Karlsson

Monday, February 1, 2010

How Open Source saved the day. Nuthin' on databases though

This post has no content related to databases, liek MySQL, tuning or anything like that. It is a precursor to such a posting though. And for those of you who have been around a bit and was reading Byte magazine in the good old days, featuring Jerry Pournelles "Computing at Chaos Manor" column, you might recognize a Chaos Manor style pattern here, along the lines of:
- A new printer is bought.
- It doesn't work on the laptop.
- The main computer is hooked up to the printer instead.
- Allowing network access fails as the gateway between the laptop and the main computer doesn't work.
- Gateway is reconfigured, but now the sons computer has no network access.
- While fixing the sons computer network access, the kitchen sink suddenly gets clogged.
- When the kitchen sink is fixed, the laptop suddenly burst into flames.
etc. etc.

Now, for my version of this, which is actually a true story.

It started with me upgrading main main Windows box. I do a lot of photo editing on this box, so there is a lot of disks in it. Was was chaning an old RAID-set of 2 250 Gb disks in RAID-1 (mirror) configuration to 2 1Tb disks, again in RAID-1. This box has had some hardware instability issies before, but it has always fixed itself. This times, after the upgrading the disks, the Mobo was dead.

This was not so bad, as I had wanted to upgrade the configuration of this box for some time now. So I went shopping. I now wanted 64-bit and some more memory, so I ended up buying a new Asus 1156 Mobo, an Intel i7 860 CPU, 8 Gb of DDR3 RAM and an SSD drive for programs and booting.

I immediate learned a lesson: With DDR2 memories, although these were shaky when DDR2 was new, current, most DDR2 within spec will fit. Not so with DDR3 though, they are in the same state as DDR2 when new, which means: Only get DDR3 memories as certied for the Mobo you used. Doh! I had to change from the planned (and bought) OCZ to a new set of Corsair memories. Luckily, memory isn't that expensive anymore.

Secondly, don't beleive everything you hear about SSD disks. Although in theory they are the same as just any plain SATA disk, that is not how Windows see things. My SSD was an 80 Gb Intel S25. If I had known in advance what I was up to, I would have done things differently, and I wouldn't have gone with an Intel drive, probably.

In the event, Windows 7 would let me install on the Intel drive. I called Microsoft support and after a few days they told me that I maybe needed a driver for the SATA controller. That was all bogus of course, but I expected nothing else. The SSD needed a firmware upgrade though, as the particular version in my copy was known to have a bug that would trash a Windows 7 installation (Thanx you Intel and Microsoft for that), but even after that, Windows 7 wouldn't install. The machine was a bit shaky.

I finally figured out how to install Windows 7 on that SSD anyway. I first let a Windows XP install disk do the partitioning and formatting, and interupted the Windows XP install after that, and then I let Windows 7 install on that partition. If you want to try this trick yourself, note that you should not touch either the partitioning or the formatting for this to work.

OK, Windows 7 install, all i well then? No, the thing was very unreliable. I found out then about the DDR3 issue mentioned above. Having gotten myself a new set of DDR3 memories, and which were supported for my Asus Mobo, I was now rocking and rolling? Well, sort of.

In the process of upgrading, I wanted to clean out some stuff in the box, so I had the old bootdisk removed, as this was substituted for the SSD anyway, and another disk that was my "work disk", containing all sorts of programs, my own source code for stuff, some archived data and stuff like that, was also removed from the box.

The machine worked fine now, the Adaptec 1420 SATA-II RAID controlller was alive, and I started building the new 1Tb array. The work-disk was placed in a eSATA / USB external enclosure and I was to access that from the box this way instead of having the disk in the box itself and eventually copy all that stuff to a RAIDed internal or external disk, as this stuff was actually rather important.

When I attached the external enclosure to the box though, there was an issue. The disk did not shouw up in explorer, and in Disk Management I was told this disk was "Dynamic" and the the status was "Invalid". So I had read up on this. A Dynamic disk is the "new" was of setting up disks in Windows, the "old" way is using "Basic" disks. Now, that is how I would like it to be, but not so Microsoft. Dynamic disks has the advantage of being possible to software RAID in Microsoft. In an attempt at not allowing us mere mortals to protect out disk data by RAIDing though, Microsoft decided to keep Dynamic disks for the non-Home users only. Why? If you ask me, for no good reason, except to make life difficult for us Windows users. Now I had a disk that was "dynamic", as it was partitioned on a Win2K box ages ago. Windows XP which is suppoed to be better than Win2K really isn't in this respect, so my other Windows box, a Win XP Laptop, could not work in this disk either, as it was "Status: Invalid" and didn't like this dynamic disk, despite this was a Win XP Pro.

Now Windows has two ways of handling disks, Basic and Dynamic, and although Dynamic is much better, I really recommend against it, as it cannot be used all over, so you cannot easily move one disk from one box to another. And it doesn't stop there of course, sometimes Microsoft does things to incredibly complex for no good reason at all.

A Basic disk can be upgraded to a Dynamic disk, no problems. But a Dynamic disk cannot be converted to a Basic disk, or rather, it can, but all data will be lost. Again, for no good reason, and this I know as this is only about formating the partition, nuthin' else. A dynamic disk contains some metadata about the disk, I guess this is for when you work with disk groups, volumes, software RAID etc. So converting to a Basic disk would require you to just get rid of that. Nope, Windows will not do that for you.

In my case, the Dynamic disk was also flagged in Windows 7 as "Status: Invalid". Googling on this I found numerous issues with this, and only a few replies. In Disk Management help in Windows, this status isn't even mentioned, thank you Microsoft. Although Windows 7 can import a Dynamic disk, it cannot import one with Status Invalid, there is nothing it can do it it actually. In the process of getting access to my disk, and I was getting desperate, I checked out Dynamic Disk Converter. This is a software kit that would do what Microsoft Windows 7 cannot, which is fix the partition table of a Dynamic disk and convert it to a basic disk, without touching the data on the disk. Why Windows 7 cannout do this is beyond me, it's just a partition table in heavens name, why do you insist on overwriting all the data just to change that! And why can't all Windows versions use the same kind of "good" disk setup? Why? But OK, this 3rd party software then can fix this. Turns out it can't. The software sux, and it cannot do it's work with any kind of Dynamic disk, specifically not a disk with "Status: Invalid", in this case it will instead do something much more interesting: Crash, after a completely unintelligible error message. Thank you again Microsoft!

So no disk yet. Now I was really upset with Microsoft and Windows 7 and all stupid people involved with "Dynamic" disks. I will keep all my disks Basic on all systems in the future, and Microsoft has just forced this on me, after Microsoft spending lots of R&D dollars on developing something that is so much better than the Basic disk, but delivering it in such a way that it is just useless and incredibly annoying.

So what did I do? Well, what was left was an Open Source hack called TestDisk. I downloaded this on a Linux box and then I attached the "Status: Invalid" Dynamic USB disk on a USB port on this box. Look here, Microsoft: This is a disk created on an OS provided by you. I want to use it on a box with an OS provided by you. ANd before you ask, I am a paying customer. I have payed for all these OSes, and I have used it in accordance with the licence. And you guys still suck. And you guys cannot handle the disks that I created with your software on your operating systems. Linux and TestDisk had no problems at all! None. The disk was that, as was all the data! I used TestDisk to backup all the data on the disk, easily, all I had to fix was to make sure I had enough disk on the Linux box for the backup. TestDisk found the drive, figured out the partitioning, just like that, and found all the data on the disk. Also, TestDisk allowed me to backup the the files on the disk, to be safe. After this, I had TestDisk rewrite the partition table.

Now, for the scary part: Remounting the disk in my Windows 7 box. And it worked like a charm: The disk was found, it was "Basic" and all the data was intact.

All this is not to say that I dislike Windows per se, or even that I think Microsoft does everything wrong. But here, Microsoft flunked, big time: Come on, let all versions of Windows use all kinds of disk, any way the like. Maybe Microsoft forgot about it, or didn't know, but we, ordinary users, often have more than 1 computer. And we sometimes move disks and data between them. And surprisingly, we sometimes upgrade the OS, even though it seems MS doesn't want us to.

If you want to use the Dynamic to Basic Disk trick with TestDisk, the instructions I mainly followed are here: http://mypkb.wordpress.com/2007/03/28/how-to-non-destructively-convert-dynamic-disks-to-basic-disks/

/Karlsson
Who just has to fix the eSATA port to be happy now

Thursday, January 7, 2010

New Storage Engine Kids on Linux

Following my recent blogg on the performance of MariaDB and PBXT on Windows showed that these new kids still has some work to do. Another question I was thinking testing was if the overhead of Transactions really matters, they do have a performance advantage also (like: You don't have to persist until the transaction is done), and so does row-level locking. And what about Linux? We could see that MariaDB on Windows was less than optimal, maybe this was a Windows problem. And finally, the Windows box I was testing on was a real old clunky box.

Hardware setup
So now, here are the results on a Linux box with a 4 Core AMD CPU and 4Gb of memory. Still not an exceptional box, but a decent one.

The first test on Linux
Again, all engines have the default settings, no tuning has been done at all. This time, with some more concurrent threads running (10 therads in total, as before, but now I have 4 running concurrently at full speed), row-level locking and increased concurrency support in PBXT and InnoDB pays off, they are both about the same speed, running in at 9216 and 8928 Operations per second respectively. Then we have MyISAM at 5615 Operations ser second, but I was expecting more here, and this is what I got, sonsistently over several runs. Last in, way behind after InnoDB, PBXT and MyISAM are already drinking beers at the local Storage Engine Pub, Maria gets in at 2285 Operations per second. So all in all, faster than in the case of my Windows test, but with a lot more Iron, and Maria way, way behind again.

Adding more threads
Wanting to try a bit more, I decided to change my test setup slightly. I insert 10000 rows per thread, instead of 1000, and run 40 simultaneous threads, to see what happens. And the results are pretty consistent with what I got before, maybe PBXT shines a bit more, at 11950 Operations / second, InnoDB comes in at 9796, MyISAM at 7665 and finally Maria, again at a sluggish 2092 Operations per second.

At this point, someone might say that Maria is still beta. But it is claimed to be RC quality, so it should be as close to GA as PBXT, but I don't really see that.

Thread impact and Transactions
Before I close the lid on this very simplistic benchmark, two more things. First, is it so that multiple-threads really cause less contention in InnoDB and PBXT than in the table-level locking Maria and MyISAM? Let's try with just 1 thread running, inserting 10000 rows. This time, MyISAM comes out best at 4468 Operations per second followed by PBXT (2170), InnoDB (2137) and last, as usual I was about to say, Maria at 1910. Now, this time Maria isn't THAT far behind, but note that Maria is not transactional, which PBXT and InnoDB is.

Lastly, let's see what good transactions can do, performance-wise. In this case, I will only persist (commit) every 100 Operations with PBXT and InnoDB. I am inserting 10000 rows in 10 threads each, and each thread is doing a commit every 100 rows then. For both PBXT and InnoDB this meant huge performance boosts, turing in at 28264 and 25773 Rows per second respectively, with MyISAM at 5540 and Maria at 2063.

Array inserts should help, but some simple tests shows that the relation stays the same, with PBXT and InnoDB on top, followed by MyISAM and Maria far behind (maybe even more behind).

Conclusion
Whereas PBXT seems good and ready for prime time, at least from a performance POV, and at least with this simple load, Maria is not there yet. This is a shame, I was hoping for Maria to be the crash-proof MyISAM we always wanted. Also, it seems that increased number of concurrent threads really do need more database concurrency (no big surprise there) in terms of row-level locking. And that transactions also may improve performance is also clear, at least to me.
And before I close, don't take this test too seriously, it is a very simplistic test, but Maria is so far behind even in this simple test (and data loads, as this is what this test is doing), is nearkly always important at some point (mysqldump recovery springs to mind :-).

/Karlsson

Tuesday, January 5, 2010

New kids on the block doin a stupid benchmark on Windows

There are now some interesting Storage Engines out there, beyond the usual MyISAM, InnoDB, NDB etc. The question is then, how do they perform? And as usual, I was a bit curious on the feasibility of these new guys on Windows?

I decided to try out MariaDB first, based on MySQL 5.1.39, and this also includes PBXT, which was convenient, now I got a chance to try, with one installation, InnoDB, MyISAM, Maria and PBXT. The MariaDB Windows download was no fun at all, though. This includes among many other things, the text setup (300Mb just that), pdb files for libraries and executables, embedded versions and debug and optimized libraries, adding up to a whopping 869 Mb on disk (but you have to exclude my current data which amounts to 94 Mb). Standard 5.1.39 is 134 Mb on disk, excluding data.

What is more annoying is that there is no installer, no MSI no nuthin', just a zip. Which is sort of fine for me, but goes to show that this really isn't even close to RC.

As for Maria with this build, if you do this:
SELECT engine, transactions, xa FROM INFORMATION_SCHEMA.ENGINES;
What is returned is this:
+------------+--------------+------+
| engine | transactions | xa |
+------------+--------------+------+
| CSV | NO | NO |
| MRG_MYISAM | NO | NO |
| PBXT | YES | NO |
| MARIA | YES | NO |
| BLACKHOLE | NO | NO |
| MyISAM | NO | NO |
| ARCHIVE | NO | NO |
| MEMORY | NO | NO |
| InnoDB | YES | YES |
+------------+--------------+------+
9 rows in set (0.00 sec)
Note here that Maria claims to be transactional, which isn't really true. Looking at the Maris docs, this is because they plan to make it transactional.

Benchmark setup
Now, for the benchmark, I decided for something really simple. No engines has been tuned at all, i.e. no engine specific parameters are set. The tables for the different engines were created like this:
create table t1_maria(c1 int not null primary key auto_increment, c2 char(100)) engine=maria;
create table t1_pbxt(c1 int not null primary key auto_increment, c2 char(100)) engine=pbxt;
create table t1_innodb(c1 int not null primary key auto_increment, c2 char(100)) engine=innodb;
create table t1_myisam(c1 int not null primary key auto_increment, c2 char(100)) engine=myisam;

As you can see, again no engine special settings, just out of the box stuff. What I do in the actual benchmark is this:
Start 10 threads, each thread executes 1000 operations like this:
INSERT INTO t1_maria VALUES(NULL, 'xxxxxxxxxx');
Just changing the table name. This isn't anything complex, hardly scientific, but there applications out there that does something like this, no more, no less.

The hardware used was my crappy old Lenovo Laptop running Windows XP. This is not the hottest computer since Osborne-1, but all Storage Engines shared the same hardware.

Expectations
OK, what was I expecting here? MyISAM was expected to be the fastest, no surprise, there are just too many shortcuts taken for it not to be. But if I had increased the # of threads, performance would slow down, due to concurrency issues, but not even that might be true, as the table was all clean now, and MyISAM has some tricks to deal with that. InnoDB was expected to be slower, and I was expected the usual InnoDB slowdown in some threads (I always see a few InnoDB operations being slow, although performance is good overall). As for Maris, I expected something along the lines of in the middle between InnoDB and MyISAM. Maria being crash proof would add to the overhead, but on the other hand, no transaction support and MyISAM heritage would speed it up. PBXT I didn't know what to expect from, but as this should be the kind of thing that PBXT is expected to excel at, but on the other hand being transactional (and this time it really IS transactional :-), I was expecting InnoDB'ish performance, maybe even better at this PBXT oriented load.

So the results then?
MyISAM fast as expected (but not crashproof), performed on average 8553 operations / s.

InnoDB on the other end of the scale, transactional and crash proof and all that, achieved 105 Operations / s. Not bad for an untuned InnoDB. Also, note that autocommit was used all over the place, had pumped some more data per transaction or relaxed the durability, things would sure be better.

PBXT performed real well, despite not being tuned at all. 181 Operations per second, and pretty consistent throughput across the threads.

So what about Maria then? Well, I don't know, apparently performance will be addressed in a later release (personally, I think performance first and foremost is a result of design, but what do I know) according to the docs. Also, this is a beta release (but PBXT is RC I think, and Monty et all claims that Maria 1.5 "we think it's good enough for RC"). In any case, I got 20 Operations per second from Maria. Less than 1/5 of InnoDB, MyISAM being more than 4000 as fast as Maria. Hmmm, I was a bit disappointed here, I was expecting more. And where is the Windows installer?

Conclusion
PBXT looks promising to me. I've always liked the Primebase focus on smart technology and thinking outside-the-box. Here it seems it may have paid off (I write "may have", as this benchmark is far from conclusive). InnoDB works as expected (here I was using the built-in InnoDB by the way, not the plug-in). MyISAM is fast, but takes too many shortcuts for my taste. And Maria seems not ready for prime time. I admit that it wasn't tuned, but none of the other engines were tuned either, and the difference was just too big, 1/5 of InnoDB performance without transaction support. And the lack of a Windows installer is another sign of this. Too bad.

/Karlsson