我应该一次加载全部数据库结果还是发出多个请求? [英] Should I load database results all at once or make multiple requests?

查看:222
本文介绍了我应该一次加载全部数据库结果还是发出多个请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要过滤具有以下列的大型数据库:

I want to filter a large database with the following columns:

名称-最大高度-最小高度-范围-最大角度-最小角度

name - max-height - min-height - range - max-angle - min-angle

我想对其进行过滤,以匹配用户可以在其之前插入的某些条件,例如如果用户输入最大高度(80厘米),它将显示所有最大高度小于80厘米的条目列表. (用户还可以输入更多条件).

I want to filter it to match certain criteria the user can insert before, e.g. if the user enters the max-height (80cm) it should display list all the entries which max-height is smaller than 80cm. (The user can also enter more criteria).

输入看起来像这样:

我打算在用户输入内容时使用onchange属性对其进行过滤.

I'm planning to use the onchange property to filter it while the user enters something.

我将node.js用作后端,将Vue.js用作主要的前端框架.我的问题是,将数据库中的所有数据加载到数组中并将其发送到前端并在此处进行过滤是否更好,或者每当用户输入条件时向数据库发出请求是否更好.

I use node.js as backend and Vue.js as main frontend framework. My question is if it's better to load all of the data from the database into an array and send it to the frontend and filter it there or if it's better to make a request to the database whenever a user enters a criteria.

推荐答案

由于以下原因,它取决于数据集的大小:

It depends on the size of the dataset because of:

  • 使用的服务器资源(CPU,RAM等)
  • 使用的带宽
  • 转让时间
  • 使用的客户端资源(CPU,RAM等)

[服务器资源] :根据服务器资源的可用性,您可能不必要地通过生成和发送大型数据集来消耗已分配的主机容量.这可能意味着更昂贵的托管和/或服务器速度减慢,以及缓慢的用户体验.添加其他并发用户将有助于达到这一效果.

[Server Resources]: Depending on the availability of server resources, you could unnecessarily eat up allocated hosting capacity by generating and sending large datasets. This could mean more costly hosting and/or server slowdown and a slow user experience. Adding additional concurrent users would contribute to the effect.

[带宽] :使用过多带宽/传输容量时也是如此.

[Bandwidth]: The same goes for using up too much bandwidth / transfer capacity.

[传输时间] :如果发送大型数据集所需的时间太长,则可能会造成不必要的缓慢用户体验,尤其是对于连接速度较慢而必须等待更长时间的用户.

[Time to transfer]: If sending a large dataset takes too long, it may create an unnecessarily slow user experience, especially for users with slower connections who have to wait even longer.

[用户资源] :预留时间,如果数据集使用过多的用户资源(RAM等),这也可能因设备速度降低或冻结而产生缓慢的用户体验,尤其是在容量较小的设备上.用户可以通过各种各样的设备进行连接.

[User Resources]: Transfer time aside, if the dataset uses too much of the user's resources (RAM, etc.) that could also create a slow user experience from device slowdown or freezing, especially on devices with less capacity. Users may connect from a wide variety of devices.

[结论]::如果这些事情无关紧要,或者数据集不够大而不会引起这些问题中的任何一个:如果需要,可以将整个事情发送出去.向服务器发送一个全面的请求,而不是发送大量的小连接请求,甚至是有益的.

[Conclusion]: If these things are not concerns or the dataset isn't large enough to cause any of these issues: send the whole thing if you want. It can even be beneficial to send one comprehensive request to the server instead of numerous little connection requests.

其他想法:

[缓存]:例如,根据应用程序,每个用户发送一次数据并将其存储在用户的localStorage中也可能是明智的.然后执行一些检查,以确保在后续访问中存储了正确的数据. (某些大小限制适用于localStorage,并且在不同的浏览器中有所不同.)

[Caching]: It might also be sensible, depending on the app, to send the data once per user and store it locally, in the user's localStorage, for example. Then implement some checks to confirm the right data is stored on subsequent visits. (Some size limits apply to localStorage, and it's different on different browsers.)

[测试]:您可以通过测试和分析上述指标来确定适合您的情况的截断大小.

[Testing]: You can determine what cutoff size is acceptable for your situation through testing and analyzing the metrics mentioned.

这篇关于我应该一次加载全部数据库结果还是发出多个请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆