SQLite 作为低流量站点的生产数据库

发布于 2024-07-22 06:03:25 字数 196 浏览 1 评论 0原文

我正在考虑使用 SQLite 作为一个网站的生产数据库,该网站可能会同时接收 20 个用户,但峰值的潜力可能是其数倍(因为该网站可以在开放的 Internet 上访问,并且总是有一个有人可能会在某个地方发布一个链接,从而吸引很多人同时访问该网站)。

SQLite 有可能吗?

我知道这不是一个理想的生产场景。 我只是想问这是否有可能实现。

I'm considering using SQLite as a production database for a site that would receive perhaps 20 simultaneous users, but with the potential for a peak that could be many multiples of that (since the site would be accessible on the open Internet and there's always a possibility that someone will post a link somewhere that could drive many people to the site all at once).

Is SQLite a possibility?

I know it's not an ideal production scenario. I'm only asking if this is within the realm of being a realistic possibility.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(10

痴情换悲伤 2024-07-29 06:03:26

为了补充一个已经很出色的答案:由于在这种情况下您正在使用无服务器解决方案,因此您可以告别复制或数据库的任何类型的水平扩展以及其他高级选项。

如果您有多个用户更新相同的信息块,那么它也不是最佳选择。 如果将来要对数据库进行分片,则必须迁移数据并转移到其他地方。

此外,如果您有一个负载均衡器并且涉及多个系统,那么使用 SQLite 就很难维护数据中心性。

这些只是不推荐的一些原因。 它非常适合小型项目,也非常适合开发。

To add to an already brilliant answer: Since you are working with a server-less solution in this case, you can say goodbye to replication, or any sort of horizontal scaling of your db, as well as other advanced options.

It also isn't the best choice if you have multiple users updating the same exact chunk of information. If you were to shard the database in the future, you would have to migrate the data and move to something else.

Also if you have a load balancer and multiple systems involved it would be difficult to maintain data centrality if using SQLite.

These are just some of the reasons why it isn't recommended. Its great for smaller projects, and great for development.

梦里梦着梦中梦 2024-07-29 06:03:26

看起来,通过队列,您还可以避免 SQLite 的许多并发写入问题。 您不是直接写入 SQLite 数据库,而是写入队列,然后队列以先进先出模式依次写入 SQLite 数据库。

我不确定您的应用程序是否达到了您需要的位置,是否值得编写或只是转移到客户端/服务器数据库......但这是一个想法。

It seems like with queuing you could also get away with avoiding a lot of the concurrency write problems with SQLite. Instead of writing directly to the SQLite database, you would write to a queue that then in turn sequentially writes to the SQLite database in a first in first out mode.

I am not sure if your application reaches to where you would need this if it would be worth writing or just moving on to client/server database...but it is a thought.

诠释孤独 2024-07-29 06:03:25

无论如何,继续针对 SQLite 进行开发,并且您最初可能可以很好地使用它。 如果您发现您的应用程序有更多用户,您将需要转换到 PostgreSQL 或 MySQL。

SQLite 的作者在网站上解决了这个问题:

SQLite 作为大多数中低流量网站(即大多数网站)的数据库引擎效果很好。 SQLite 可以处理的 Web 流量取决于网站使用其数据库的程度。 一般来说,任何每天点击量低于 10 万次的网站都应该可以与 SQLite 配合良好。 每天 10 万次点击量是保守估计,而不是硬性上限。 SQLite 已被证明可以处理 10 倍的流量。

SQLite 网站 (https://www.sqlite.org/) 使用 SQLite 本身,当然,截至撰写本文时(2015 年),它每天处理大约 400K 到 500K HTTP 请求,其中大约 15-20% 是接触数据库的动态页面。 每个网页动态内容使用大约 200 个 SQL 语句。 此设置在单个虚拟机上运行,​​该虚拟机与其他 23 个虚拟机共享物理服务器,但大多数时间仍将平均负载保持在 0.1 以下。

所以我认为总而言之,就去做吧,如果它对你来说效果不佳,那么过渡到企业级数据库无论如何都是相当微不足道的。 但是,请务必注意您的架构,并在设计数据库时考虑到增长和效率。


这是一个线程,其中包含一些关于将 SQLite 用于生产 Web 应用程序的更独立的评论。 听起来它的使用效果好坏参半。

自从这个答案发布以来,SQLite 现在具有 多线程模式预写日志模式 这可能会影响您对其是否适合中低流量网站的评估。

Charles Leifer 撰写了一篇博文,内容涉及SQLite 的 WAL(预写日志记录)功能以及一些关于适当用例的深思熟虑的意见。

By all means, continue to develop against SQLite, and you're probably fine to use it initially. If you find your application has more users down the track, you're going to want to transition to PostgreSQL or MySQL however.

The author of SQLite addresses this on the website:

SQLite works great as the database engine for most low to medium traffic websites (which is to say, most websites). The amount of web traffic that SQLite can handle depends on how heavily the website uses its database. Generally speaking, any site that gets fewer than 100K hits/day should work fine with SQLite. The 100K hits/day figure is a conservative estimate, not a hard upper bound. SQLite has been demonstrated to work with 10 times that amount of traffic.

The SQLite website (https://www.sqlite.org/) uses SQLite itself, of course, and as of this writing (2015), it handles about 400K to 500K HTTP requests per day, about 15-20% of which are dynamic pages touching the database. Dynamic content uses about 200 SQL statements per webpage. This setup runs on a single VM that shares a physical server with 23 others and yet still keeps the load average below 0.1 most of the time.

So I think the long and short of it is, go for it, and if it's not working well for you, making the transition to an enterprise-class database is fairly trivial anyway. Do take care of your schema, however, and design your database with growth and efficiency in mind.


Here's a thread with some more independent comments around using SQLite for a production web application. It sounds like it has been used with some mixed results.

Since this answer was posted, SQLite now features a multi-threaded mode and write ahead logging mode which may influence your evaluation of its suitability for low-medium traffic sites.

Charles Leifer has written a blog post about SQLite's WAL (write ahead logging) feature and some well-considered opinions on appropriate use cases.

倾其所爱 2024-07-29 06:03:25

SQLite 网站 的小摘录说明了一切。

  • 数据是否通过网络与应用程序分离? → 选择
    客户端/服务器

  • 许多并发作家? → 选择客户端/服务器

  • 大数据? → 选择客户端/服务器

  • 否则→选择SQLite

SQLite“正常工作”(当然,直到它不起作用)。

The small excerpt from the SQLite website says it all.

  • Is the data separated from the application by a network? → choose
    client/server

  • Many concurrent writers? → choose client/server

  • Big data? → choose client/server

  • Otherwise → choose SQLite!

SQLite "just works" (until it doesn't of course).

樱娆 2024-07-29 06:03:25

我们经常使用 SQLite 作为内部数据库:员工目录、事件日历和其他 Intranet 服务都在轻量级数据库上运行。 以我们在“真实”数据库(如MySQL<)上运行的规模运行这些应用程序将是一个重大的矫枉过正。 /a>. 当您考虑到它们在一台中型计算机上与其他四个虚拟机一起运行时尤其如此。

曾经,我们有一个面向外部的站点,它在 SQLite 数据库上运行了数月,只需要重新启动一次。 显然,它的流量非常低,但它的表现却很好。

We often use SQLite for internal databases: The employee directory, our calendar of events, and other intranet services all run on lightweight databases. It would be major overkill to be running these applications at the scale we do on a "real" database like MySQL. This is especially true when you factor in that they're running alongside four other virtual machines on a single mid-range computer.

At one point we had an outward facing site that ran on an SQLite database for months with only a single reboot required. Obviously, it was very low traffic, but it put along nicely for what it did.

玩物 2024-07-29 06:03:25

我们在绝对没有写入的环境中遇到了类似的选项,并且我们选择使用 SQLite。

请参阅我关于该主题的博客文章

嗯,理论上这个解决方案的主要假设
可能的是我们的 SQLite 数据库是完全只读的。 我们的服务器
代码永远不应该改变它。 这将解决任何锁定问题,因为
没有读锁。 我们在互联网上找不到任何人
说SQLite高吞吐量读取有问题
没有写入 - 这是可能的!

We have encountered a similar option on an environment with absolutely no writes, and we selected using SQLite.

See my blog post on the subject:

Well, the main assumption which makes this solution theoretically
possible is that our SQLite database is totally read-only. Our server
code should never change it. This would solve any locking problems, as
there are no read locks. We could find nowhere on the internet anyone
saying there is a problem in high-throughput reading of SQLite when
there are no writes - it could be possible!

痴意少年 2024-07-29 06:03:25

我认为这主要取决于您的读/写比率。 如果主要是从数据库中读取,那么可能没问题。 由于 SQLite 锁定数据库的方式,多用户写入可能会成为一个问题。

I think it would depend mostly on what your read/write ratio will be. If it's mostly reading from the database, you may be okay. Multi-user writing in SQLite can be a problem because of how it locks the database.

执笔绘流年 2024-07-29 06:03:25

人们谈论并发问题,但 SQLite 有一种方法可以缓存传入的请求并让它们等待一段时间。 它不会立即超时。

我读过有关默认超时设置从零开始的内容,这意味着它会立即超时,这是无稽之谈。 也许人们没有调整这个设置?

People speak about concurrency problems, but SQLite has a way to cache incoming requests and have them wait for some time. It doesn't time out immediately.

I've read things about the default timeout setting beginning at zero, meaning it times out immediately and that's nonsense. Maybe people didn't adjust this setting?

小伙你站住 2024-07-29 06:03:25

我在一个流量非常低的网络服务器(它是一个基因组数据库)中使用它,并且没有任何问题。 但只有 SELECT 语句,不涉及写入数据库

I am using it in a very low traffic web server (it is a genomic database) and I don't have any problems. But there are only SELECT statements, no writing to the DB involved.

吻风 2024-07-29 06:03:25

这取决于网站的使用情况。 如果大多数时候您只是读取数据,那么您几乎可以使用任何数据库并将数据缓存在应用程序中以获得良好的性能。

It depends on the usage of the site. If most of the time you're just reading data, you can pretty much use anything for a DB and cache the data in the application to achieve good performance.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文