什么更快?从数据库检索数据还是从文本文件检索数据?
我正在制作一个包含许多不同元素的页面,我想当您将鼠标悬停在每个元素上时显示一个工具提示。有数千个元素,因此每个工具提示的信息都需要使用 ajax 来恢复。
我想知道是否最好将所有工具提示信息保存在 mysql 数据库上并通过一个 ajax 请求检索所有必要的信息,或者是否最好将每个工具提示保存到单独的文件中,并在需要时将 ajax 每个文件保存起来。
I'm making a page with with lots of diferent elements and i want to show a tooltip when you hover over each one. There are thousands of elements so the information for each tooltip will need to be recorved with ajax.
I was wondering if its better to save all that tooltip information on mysql database and retrieve all necesery information with one ajax request, or is it better to save each tooltip to a seperate file and the ajax each file when needed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
是否将信息存储在数据库中或平面文本文件中的选择可以与是否一次检索所有值或一次检索一个值的选择正交。
话虽如此,您可以考虑以下两件事:
一个好的解决方案是将工具提示分组为可能在同一时间访问的组(即,页面的每个部分一组)。然后,您可以检索具有所需工具提示的组,它将在不久后获取用户可能需要的所有工具提示。
另一种选择是通过 javascript 文件(而不是通过 ajax)检索工具提示,然后在加载页面后异步加载该文件。该页面将显示,当用户第一次查看该页面时,工具提示可以在后台加载。如果我没记错的话,这也会让浏览器缓存数据(js 文件),这样,如果用户返回同一页面,则不需要重新加载信息(即,无需执行任何操作即可进行缓存)得到它)。
至于选择数据库还是文本文件,文本文件通常会更快。但是,我会更多地根据您可能如何/何时更改工具提示来做出选择。如果您愿意在每次更改工具提示时推送应用程序的新版本,那么平面文件是一个合理(且简单)的选择。如果您希望能够动态更改工具提示(这似乎不太可能),那么数据库可能是更好的选择。无论哪种方式,您选择何时加载工具提示以及加载工具提示的数量可能会掩盖数据库和平面文件之间的差异。
The choice of whether to store the information in the database or in a flat text file can be made orthogonally to the choice of whether to retrieve all the values at once or one at a time.
That being said, you can consider the following two things:
What might be a good resolution is to group the tooltips into bunches that are likely to be accessed around the same time (ie, a group for each section of the page). Then, you can retrieve the group that has the tooltip you need and it will grab the all the ones the user is likely to need shortly thereafter.
Another option is to retrieve the tooltips via a javascript file (rather than via ajax), and then load the file asynchronously once the page is loaded. The page will display and, while the user is first looking at it, the tooltips can be loading in the background. If I remember correctly, this will also let the browser cache the data (js file) so that the information won't need to be reloaded if the user comes back to the same page (ie, caching without you having to do any work to get it).
As to the decision of a db vs a text file, the text file will generally be faster. However, I would make the choice based more on how/when you're likely to change the tooltips. If you're comfortable needing to push a new version of the app whenever you change a tooltip, the flat file is a reasonable (and simple) choice. If you want to be able to change tooltips dynamically (which seems unlikely), the database is probably a better choice. Either way, the choice by which you choose when to load the tooltips and how many of them will probably overshadow the difference between the database and a flat file.
就性能而言,文本文件可能会更快;因为您不会产生服务器端页面访问数据库并将数据返回给客户端的开销。文本文件可以直接读取,开销很小。
Performance wise, the text file would probably be faster; since you wouldn't incur the overhead of having a server side page hit the database and return the data to the client. The text file could just be read directly with little overhead.
DB 比单独的文件更快,因为它会缓存结果。要么使用 DB,要么使用单个文件。
DB would be faster than separate files, because it will cache results. Either use DB, either use one single file.
我想说带有缓存的 SQL 数据库是你最好的选择:
看到这样的东西
http://www.troywolf.com/articles/php/class_db/
I would say SQL database with caching is your best bet:
See something like this
http://www.troywolf.com/articles/php/class_db/