sqlite 查询与在服务器上重新加载 txt 文件的比较

发布于 2024-11-30 03:47:48 字数 327 浏览 3 评论 0原文

我正在创建一个聊天应用程序,我让页面每 10 秒检查一次 sqlite 数据库的更新。我目前使用 sqlite 数据库检查更新,我只请求时间戳大于我上次检查的帖子。

我知道 sqlite 非常高效,因为它使用索引和缓存。但我想知道在我的服务器上创建一个只存储 Unix 时间戳的 txt 文件是否会更好。它只有 10 个字节,然后每次用户发帖时我都会用 php 更新它。这样我可以每 10 秒使用 ajax 重新加载 txt 文件,然后在有新帖子时进行 sqlite 查询。

我的问题是,txt 文件或 sqlite 查询哪个对服务器的压力较小?

注意:我不想使用长拉,这对我来说太复杂了:}

I'm creating a chat application, I have the page check for updates from my sqlite database every 10 seconds. I currently check for updates using a sqlite database, I just request posts that have a timestamp that is greater than my last check.

I know sqlite is pretty efficient because it uses indexes and caching. But I was wondering if I would be better off creating a txt file on my server that just stores a Unix Time Stamp in it. It would only be 10 bytes and then I would just update it with php every time a user posts. This way I could reload the txt file with ajax every 10 seconds and then make the sqlite query when there is a new post.

My question is which would less stressful on the server, a txt file or sqlite queries?

Note: I don't want to use long pulling, it's too complicated for me :}

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

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

发布评论

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

评论(1

晨敛清荷 2024-12-07 03:47:48

为每个用户或请求使用一个新文件将比使用每个用户扩展的相同 SQLite 文件使用更多的资源。

打开和关闭文件的成本很高,并且不同的文件不一定会占用磁盘和内存缓存中的相同位置。

因此,如果您的目标是最大限度地降低这些操作的成本,请使用 SQLite。

如果您不需要持久性,您也可以将该信息保留在内存中(SQLite 支持内存表)。

Using a new file for each user or request will use far more resources than using the same SQLite file extended by each user.

Opening and closing files is expensive, and different files will not necessarily occupy the same place on disk and in the memory caches.

So, if your goal is to minimize the cost of these operations, use SQLite.

If you don't need persistence, you could as well keep that information in memory (SQLite supports in-memory tables).

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