我希望你们不会介意我问一个离题和幼稚的问题。但是,我找不到任何令人满意的答案。最大值,平均一个页面必须允许处理多少个查询以呈现输出(我正在寻找质量方面)。例如,在电子商务应用程序中,平均需要 4 到 5 个查询。查询次数越少,响应时间越短。因此问题。这个问题与任何编程平台无关。但是,让我们以 PHP 和 MySql 为例。
3 回答
与运行 5 个总共需要 1/10 秒才能完成的简单查询相比,一个需要半秒才能执行的复杂查询的优化效果要差一些。
为了让您的代码更有条理,拥有更多数量的简单查询也可能是一种权衡。例如,与手动编写查询相比,ORM 通常会进行更多的数据库调用,但它们使应用程序的开发更加简单。
但是,最终,任何复杂到需要担心数据库调用次数的应用程序都足够复杂,以至于它应该尽可能地使用缓存层。只要没有需要很长时间才能加载的页面,就不值得挑剔查询的确切数量。
Actually, It's difficult to say how many queries, a page must fire. It depends on following factors :
Complexity of Application
Data shown in a web page in a big, complex and data-oriented application is large in quantity, compared to normal web pages. Thus, it may requires you to fire more number of queries to get data.
Types of Queries
You may opt to fire more queries to get individual piece of data OR You can use complicated Join to fetch all the data from multiple tables in one go. Thus, here you are making tradeoff between no. of db calls VS Amount of Processing and memory, a Complex JOIN requires. If the tables you are joining are not very large, then join is the best option. But, If your tables are large, then it may make more sense to make individual call to db to fetch data.
Deployment Configuration
In case when you application server and db server are configured on the same machine, then making multiple queries may not have big significance. But, if your db server and application server are located at different places, then minimum queries must be used or single queries with more joins must be used, to avoid network latency.
我开发了许多网页,每页最多 50 个查询。所有的速度都可以接受。诀窍不是“查询数量”,而是它们的“速度”。在最好的情况下,查询需要不到 10 毫秒。其中 50 个仍然不到半秒。在这样的页面中,页面的呈现可能需要比这更长的时间。也就是说,MySQL 不是瓶颈。
如何加快查询速度?简单的查询。点查询。良好的索引(通常是“复合”)。
如何减慢查询速度?EAV。“显示 123456 中的 10 个结果”。表扫描。
想要了解更多详情?让我们看一些查询。