简体   繁体   English

SQLite 比 MySQL 快吗?

[英]SQLite faster than MySQL?

I want to set up a teamspeak 3 server.我想建立一个teamspeak 3服务器。 I can choose between SQLite and MySQL as database.我可以选择 SQLite 和 MySQL 作为数据库。 Well I usually tend to "do not use SQLite in production".好吧,我通常倾向于“不要在生产中使用 SQLite”。 But on the other hand, it's a teamspeak server.但另一方面,它是一个teamspeak服务器。 Well okay, just let me google this... I found this:好吧,让我谷歌一下……我发现了这个:

  1. Speed速度
    SQLite3 is much faster than MySQL database. SQLite3 比 MySQL 数据库快得多。 It's because file database is always faster than unix socket.这是因为文件数据库总是比 unix socket 快。 When I requested edit of channel it took about 0.5-1 sec on MySQL database (127.0.0.1) and almost instantly (0.1 sec) on SQLite 3. [...]当我请求编辑频道时,它在 MySQL 数据库 (127.0.0.1) 上花费了大约 0.5-1 秒,在 SQLite 3 上几乎立即(0.1 秒)。 [...]

http://forum.teamspeak.com/showthread.php/77126-SQLite-vs-MySQL-Answer-is-here http://forum.teamspeak.com/showthread.php/77126-SQLite-vs-MySQL-Answer-is-here

I don't want to start a SQLite vs MySQL debate.我不想开始 SQLite 与 MySQL 的辩论。 I just want to ask: Is his argument even valid?我只想问:他的论点还有道理吗? I can't imagine it's true what he says.我无法想象他说的是真的。 But unfortunately I'm not expert enough to answer this question myself.但不幸的是,我不够专业,无法自己回答这个问题。

Maybe TeamSpeak dev's have some major differences in their db architecture between SQLite and MySQL which explains a huge difference in speed (I can't imagine this).也许 TeamSpeak 开发人员在 SQLite 和 MySQL 之间的数据库架构上有一些重大差异,这解释了速度上的巨大差异(我无法想象)。

At First Access Time will Appear Faster in SQLite在 SQLite 中首次访问时间会更快

The access time for SQLite will appear faster at first instance, but this is with a small number of users online. SQLite 的访问时间一开始看起来会更快,但这是在少数用户在线的情况下。 SQLite uses a very simplistic access algorithm, its fast but does not handle concurrency. SQLite 使用一种非常简单的访问算法,它速度快但不处理并发。

As the database starts to grow, and the amount of simultaneous access it will start to suffer.随着数据库开始增长,同时访问的数量将开始受到影响。 The way servers handle multiple requests is completely different and way more complex and optimized for high concurrency.服务器处理多个请求的方式完全不同,并且更加复杂并且针对高并发进行了优化。 For example, SQLite will lock the whole table if an update is going on, and queue the orders.例如,如果更新正在进行,SQLite 将锁定整个表,并将订单排队。

RDBMS's Makes a lot of extra work that make them more Scalable RDBMS 做了很多额外的工作,使它们更具可扩展性

MySQL for example, even with a single user will create an access QUEUE, lock tables partially instead of allowing only single user-per time executions, and other pretty complex tasks in order to make sure the database is still accessible for any other simultaneous access.例如 MySQL,即使只有一个用户,也会创建一个访问队列,部分锁定表而不是每次只允许单个用户执行,以及其他非常复杂的任务,以确保数据库仍可用于任何其他同时访问。

This will make a single user connection slower, but pays off in the future, when 100's of users are online, and in this case, the simple "LOCK THE WHOLE TABLE AND EXECUTE A SINGLE QUERY EACH TIME" procedure of SQLite will hog the server.这会使单个用户的连接变慢,但在未来会有回报,当 100 名用户在线时,在这种情况下,SQLite 的简单“锁定整个表并每次执行单个查询”过程将占用服务器.

SQLite is made for simplicity and Self Contained Database Applications. SQLite 是为了简单和自包含数据库应用程序而设计的。

If you are expecting to have 10 simultaneous access writing at the database at a time SQLite may perform well, but you won't want an 100 user application that constant writes and reads data to the database using SQLite.如果您希望一次对数据库进行 10 个同时访问写入,SQLite 可能表现良好,但您不希望有 100 个用户的应用程序使用 SQLite 不断地向数据库写入和读取数据。 It wasn't designed for such scenario, and it will trash resources.它不是为这种情况设计的,它会浪费资源。

Considering your TeamSpeak scenario you are likely to be ok with SQLite, even for some business it is OK, some websites need databases that will be read only unless when adding new content.考虑到您的 TeamSpeak 场景,您可能对 SQLite 没问题,即使对于某些业务也可以,但某些网站需要只读的数据库,除非添加新内容。

For this kind of uses SQLite is a cheap, easy to implement, self contained, perfect solution that will get the job done.对于这种用途,SQLite 是一种廉价、易于实现、自包含、完美的解决方案,可以完成工作。

I have not personally tested SQLite vs MySQL, but it is easy to find examples on the web that say the opposite ( for instance ).我没有亲自测试过 SQLite 与 MySQL,但很容易在网上找到相反的例子例如)。 You do ask a question that is not quite so religious: is that argument valid?你确实问了一个不太虔诚的问题:这个论点有效吗?

First, the essence of the argument is somewhat specious.首先,论证的本质有些似是而非。 A Unix socket would be used to communicate to a database server. Unix 套接字将用于与数据库服务器通信。 A "file database" seems to refer to the fact that communication is through a compiled-in interface. “文件数据库”似乎是指通信是通过编译接口进行的。 In the terminology of SQLite, it is server-less .在 SQLite 的术语中,它是无服务器的 Most databases store data in files, so the terminology "file database" is a little misleading.大多数数据库将数据存储在文件中,因此术语“文件数据库”有点误导。

Performance of a database involves multiple factors, such as:数据库的性能涉及多种因素,例如:

  • Communication of query to the database.与数据库的查询通信。
  • Speed of compilation (ability to store pre-compiled queries is a plus here).编译速度(存储预编译查询的能力在这里是一个加分项)。
  • Speed of processing.处理速度。
  • Ability to handle complex processing.处理复杂加工的能力。
  • Compiler optimizations and execution engine algorithms.编译器优化和执行引擎算法。
  • Communication of results back to the application.将结果传送回应用程序。

Having the interface be compiled-in affects the first and last of these.编译接口会影响其中的第一个和最后一个。 There is nothing that prevents a server-less database from excelling at the rest.没有什么可以阻止无服务器数据库在其他方面表现出色。 However, database servers are typically millions of lines of code -- much larger than SQLite.然而,数据库服务器通常有数百万行代码——比 SQLite 大得多。 A lot of this supports extra functionality.其中很多都支持额外的功能。 Some of it supports improved optimizations and better algorithms.其中一些支持改进的优化和更好的算法。

As with most performance questions, the answer is to test the systems yourself on your data in your environment.与大多数性能问题一样,答案是根据环境中的数据自行测试系统。 Being server-less is not an automatic performance gain.无服务器并不是一种自动的性能提升。 Having a server doesn't make a database "better".拥有服务器不会使数据库“更好”。 They are different applications designed for different optimization points.它们是针对不同优化点设计的不同应用程序。

The relevant difference is that SQLite uses a much simpler locking algorithm (a simple global database lock).相关的区别在于 SQLite 使用了更简单的锁定算法(简单的全局数据库锁)。

Using fine-grained locking (as MySQL and most other DB servers do) is much more complex, and slower if there is only a single database user, but required if you want to allow more concurrency.使用细粒度锁定(如 MySQL 和大多数其他数据库服务器所做的那样)复杂得多,如果只有一个数据库用户,速度也会更慢,但如果您想允许更多并发,则需要使用细粒度锁定。

In short:简而言之:

  • For Local application databses, single user applications, and little simple projects keeping small data SQLite is winner.对于本地应用程序数据库、单用户应用程序和保留小数据的小型简单项目,SQLite 是赢家。
  • For Network database applications, multiuser and concurrency, load balancing and growing data managements, security and roll based authentications, big projects and widely used services you should choose MySql.对于网络数据库应用程序、多用户和并发、负载平衡和不断增长的数据管理、安全性和基于滚动的身份验证、大型项目和广泛使用的服务,您应该选择 MySql。

In your question I do not know much about teamspeak servers and what kind of data it actually needs to keep in its database but if it just needs a local DBMS and not needs to proccess lots of concurrency and managements SQLite will be my choice.在您的问题中,我不太了解 teampeak 服务器以及它实际需要在其数据库中保留什么样的数据,但如果它只需要一个本地 DBMS 而不需要处理大量并发和管理,SQLite 将是我的选择。

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

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