Http性能 - 许多小请求或一个大请求 [英] Http Performance - Many small requests or one big one

查看:169
本文介绍了Http性能 - 许多小请求或一个大请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

情景:


  1. 在我的网站中,我会显示图书。

  2. 用户可以将每本书添加到稍后阅读列表中。

行为:

当用户进入该网站后,他们会看到一系列书籍。
其中一些已经在他们的Read Later列表中,有些则不是。

When the user enters the site, they are presented with a list of books. Some of which are already in their "Read Later" list, some aren't.

用户在每本书旁边都有一个指示,告诉他们这本书是否已被添加到列表中。

The user has an indication next to each book telling them whether the book has been added to the list or not.

我的问题

我在辩论哪种方案适合我的情况。

I am debating which option is the ideal for my situation.

选项1:


  1. 预订,查询服务器是否已存在于用户列表中。

  2. 更新每本书的指标。

Pro:
对服务器的请求非常小,响应非常简单(真或假)。

Pro: Very small request to the server, and very easy response (true or false).

Con:在30页面中书籍,我将发送30个单独的http请求,这些请求可以阻止套接字,并且考虑到浏览器和服务器必须为每个事务执行整个握手,这个请求相当慢。

Con: In a page with 30 books, I will send 30 separate http requests, which can block sockets, and is rather slow considering the browser and the server have to perform the entire handshake for each transaction.

选项2:


  1. 我查询服务器一次,并以稍后阅读列表中的完整书籍列表作为数组获得响应。

  2. 在浏览器中,我查看数组,并更新指示每本书都基于它是否存在于数组中。

Pro:我只提出一个请求,并立即更新所有图书的指标。

Pro: I only make one request, and update the indicator for all the books at once.

Con:稍后阅读列表可能包含数百本书,传递大型数据可能会导致速度过慢。特别是在屏幕上没有出现30本书的情况下,只有2-3本。 (也就是说,我想检查某个书是否在列表中,为此我让服务器向客户端发送列表中的整个书籍列表。)

Con: The "Read Later" list might have hundreds of books, and passing a big array might prove slow and excessive. Especially in scenarios when not 30 books appear on the screen, but only 2-3. (That is, I want to check if a certain book is in the list, and for this I have the server send the client the entire list of books from the list).

那么,

您最优化哪种方式:1或2?

Which way would you go to maximize performance: 1 or 2?

我有什么替代品吗?

推荐答案

选项1听起来不错,但在可扩展性方面存在很大问题。

Option 1 sounds good but has a big problem in terms of scalability.

选项2减轻了这种可扩展性问题,我们可以改进其设计:

Option 2 mitigates this scalability problem and we can improve its design:

客户端通过javascript只收集显示的图书ID并通过ajax查询一次对于一组读取后的信息,仅适用于那30本书。通过这种方式,您仍可快速提供页面并请求一小组附加信息,一次只需一个http请求。

Client side, via javascript, collect only displayed book ids and query once, via ajax, for an array of read-later info, only for those 30 books. This way you still serve the page fast and request a small set of additional info, once with a single http request.

服务器端您可以进一步改进缓存内存数组每个用户的后读ID。

Server side you can further improve caching an in memory array of read-later ids for each user.

这篇关于Http性能 - 许多小请求或一个大请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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