Scaling MySQL to 700 million inserts per day
tech.bluesmoon.info
tech.bluesmoon.info
Quoth the article: "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."
This isn't a job for a database. This is a job for a log file. You might want to use a database to store the summarized data, of course; but bulk data which is written, never updated, and quite likely only ever read once? That's practically the definition of a log file.
The non-MySQL RDBMS people that I know, know when their RDBMS of choice isn't the right tool for the job. Most of the MySQL people I know, seem to think that you just shove everything into the DB, and let Eris sort it out.
Because no other member of the pantheon is crazy enough to even look at that mess.
[1]: http://www.reddit.com/r/programming/comments/764fp/mysql_vs_postgresql/c05sayb
[2]: http://sqlanywhere.blogspot.com/2008/03/unpublished-mysql-faq.html
[3]: http://news.ycombinator.com/item?id=561277
[4]: http://ask.metafilter.com/117908/Theres-got-to-be-a-faster-way-to-update
There seems to be a similar effect between Linux and BSD. I'm not going to claim that BSD is objectively superior in every regard, but on average, the BSD community seems to be quite a bit better informed than the Linux community. It may just be because Linux is so much more visible. People using BSD, Postgres, etc. probably already knew enough to evaluate their options, while the path of least resistance stays overrun with clueless newbies.MySQL is a popular RDBMS starting point. Therefore, almost by definition, if you run into someone using a RDBMS but not really knowing WTF they are doing, they're quite often using MySQL.
If it wasn't MySQL, the same people would flock to, and poorly use, some other tool.
That's what I said, deeper in the thread. I don't think it's because MySQL is terrible, but almost all the people who don't really know databases start with MySQL by default, so the community surrounding it consistently has more people who are grossly misinformed than (for example) Postgres's.
And later on they end up writing them to a text file and bulk inserting them in 10K batches. Wouldn't it be easier to just write them all to a file then summarize at the end of the day? (It also says they do a DROP TABLE on each day's data.)
"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."
The 'correct' way to deal with this in MySQL is using the auto_increment_increment.
http://dev.mysql.com/doc/refman/5.0/en/server-system-variabl...
Of course, the real difficulty with mutli-master setups split across data centres isn't ensuring uniqueness of primary keys, it's ensuring data-integrity under a split-brain scenario, i.e. where one server can't reach the other, but users can reach one or the other. UPDATEs and DELETEs to rows can then become extremely difficult to merge back together. This wasn't a problem for this application, but as others have commented, this use case probably wasn't best suited for an RDBMS anyway.
secondly, the autoincrement id adds 4 bytes to each row which are never used for anything. only use an id if you need to reference a row from another table.
Make that duplicate rows WILL get inserted -- even if only due to network glitches causing connections to die after the database adds the row but before the client receives the acknowledgement resulting in the client retrying the request. Unless you don't retry failures, in which case you lose rows instead, of course.
The use of ORMs like active record, many of which choke on natural keys, has turned a lot of devs into automatons for artificial key creation. Natural keys are often superior.