简体   繁体   English

为非关键webapp数据选择MySQL表类型(MyISAM与InnoDB)

[英]Choice of MySQL table type for non-critical webapp data (MyISAM vs. InnoDB)

Consider this scenario with the following assumptions: 考虑这种情况,假设如下:

  • The database is used for a non-critical webapp. 该数据库用于非关键Web应用程序。
  • Query speed is of vital importance. 查询速度至关重要。
  • The read/write patterns are roughly >95 % reads and <5 % writes. 读/写模式大约> 95%读取和<5%写入。
  • The database is backuped up daily using mysqldump. 每天使用mysqldump备份数据库。
  • The is no need for transactions or advanced crash recovery. 不需要事务或高级崩溃恢复。 If the database crashes I'll simply import last night's mysqldump. 如果数据库崩溃,我只需导入昨晚的mysqldump。 This is good enough in this scenario. 在这种情况下,这已经足够了。
  • No need for full-text searching. 无需全文搜索。

Pros of MyISAM under said assumptions: 在所述假设下MyISAM的优点:

  • It's very fast (with one exception - see below). 它非常快(有一个例外 - 见下文)。
  • It's light-weight and has an easy-to-understand mapping between database/table to physical files in file system (.MYD/.MYI/.frm). 它重量轻,并且在数据库/表与文件系统中的物理文件(.MYD / .MYI / .frm)之间具有易于理解的映射。
  • Easy backup (mysqldump). 轻松备份(mysqldump)。

All-in-all I'm very happy with MyISAM with one major exception. 总而言之,我对MyISAM非常满意,但有一个例外。 MyISAM has one major shortcoming under said assumptions and that is table level locking. 在所述假设下,MyISAM有一个主要缺点,即表级锁定。 When UPDATEs are running towards a frequently read table all reads are blocked. 当UPDATE向经常读取的表运行时,所有读取都被阻止。 Needless to say this causes major performance problems which must be solved. 不用说,这会导致必须解决的主要性能问题。

My questions are: 我的问题是:

  1. Is there some way to get rid of table level locking without switching away from MyISAM? 有没有办法在不切换MyISAM的情况下摆脱表级锁定?
  2. If I must switch to InnoDB - how do I configure InnoDB so that it behaves as similar to MyISAM as possible (think no transactions, logical file structure, etc.). 如果我必须切换到InnoDB - 我如何配置InnoDB,使其行为尽可能与MyISAM类似(不要考虑事务,逻辑文件结构等)。 How do I configure a InnoDB to be "just like MyISAM but without table level locking"? 如何将InnoDB配置为“就像MyISAM但没有表级锁定”?
  1. No, MyISAM means table level locking. 不,MyISAM意味着表级锁定。
  2. You can't get it "just like", but you can get it "a lot more like" by turning on the innodb_file_per_table option. 你不能“只是喜欢”它,但你可以通过打开innodb_file_per_table选项让它“更像”。 InnoDB will still store critical information in its system-level data file, however, and you can't do things like casually rename a database by renaming the directory it lives in like you can with MyISAM. 然而,InnoDB仍会将关键信息存储在其系统级数据文件中,并且您无法通过重命名数据库来重命名数据库,就像使用MyISAM一样。

Have you actually taken performance metrics using myisam and innodb tables? 您是否真的使用myisam和innodb表获取了性能指标? In my experience the differences in speed is not really that much when you consider all the ACID benefits you get from innodb. 根据我的经验,当你考虑从innodb获得的所有ACID好处时,速度上的差异并不是那么多。 Just the table locking alone will affect speed such that innodb would be overall faster. 只是单独锁定表会影响速度,因此innodb总体上会更快。

Also notice that myisam is much faster on inserts, not so much on selects. 另请注意,myisam在插入时要快得多,而不是选择。 You are inserting only 5% of the time... do the math. 你只插入5%的时间...做数学。

You can always do mysqldump using an innodb, so your backup rocess is the same. 你总是可以使用innodb做mysqldump,所以你的备份过程是一样的。

I know some projects use a mirror DB for searching. 我知道有些项目使用镜像DB进行搜索。 It tends to be optimized for the searches and sometimes even run on a different machine, just to isolate the overhead. 它倾向于针对搜索进行优化,有时甚至可以在不同的机器上运行,只是为了隔离开销。

The only drawback here is that keeping them in sync is a bit of a hassle. 这里唯一的缺点是保持它们同步有点麻烦。 If stale data in your search table isn't too troubling, it might be the best bet. 如果搜索表中的陈旧数据不是太麻烦,那么它可能是最好的选择。 If performance is an issue that is. 如果性能是一个问题。

It isn't my favorite solution, but it is pretty simple in theory. 这不是我最喜欢的解决方案,但理论上它非常简单。

  1. When it comes to backup InnoDB doesn't prevent you from using mysqldump. 说到备份InnoDB并不妨碍你使用mysqldump。
  2. Are you sure that you really need to maintain the mapping between database tables and files on disk? 您确定您确实需要维护磁盘上数据库表和文件之间的映射吗? Manual operations on database files are rarely a good idea. 对数据库文件的手动操作很少是个好主意。
  3. With InnoDB you don't have to use transactions, by default it works in "autocommit" mode (every query will be commited automatically). 使用InnoDB,您不必使用事务,默认情况下它以“自动提交”模式工作(每个查询将自动提交)。
  4. "InnoDB is slower" is mostly myth these days, but of course it depends on your workload. “InnoDB速度较慢”现在主要是神话,但当然这取决于你的工作量。

In other words I think you should definitely give InnoDB a try and benchmark the performance of your application. 换句话说,我认为你一定要试试InnoDB并对应用程序的性能进行基准测试。 Migration is extremely simple, so I don't see a reason not to try. 迁移非常简单,所以我没有理由不去尝试。 For me InnoDB is a default choice for a long time. 对我来说,InnoDB很长一段时间都是默认选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM