如何减少通过 REST API 发送数据的延迟

发布于 2024-08-26 20:23:57 字数 546 浏览 8 评论 0原文

我有一个应用程序从我们的其他服务器之一获取 JSON 格式的数据。我面临的问题是,请求此信息时存在明显的延迟。由于需要传递大量数据(每个请求大约 1000 条记录,其中每条记录都非常大),因此有一种压缩方法可以帮助降低速度。如果是这样,您会推荐哪种压缩方案。

我在另一个线程上读到,数据模式对它们也很重要需要使用的压缩类型。数据模式是一致的,类似于以下内容

 :desc=>some_description
 :url=>some_url
 :content=>some_content
 :score=>some_score
 :more_attributes=>more_data

有人可以推荐一个解决方案来减少这种延迟吗?他们的延迟大约是 6-8 秒。我使用 Ruby on Rails 来开发这个应用程序,提供数据的服务器大部分使用 Python。

I have an application which obtains data in JSON format from one of our other servers. The problem I am facing is, there is is significant delay when when requesting for this information. Since a lot of data is passed (approx 1000 records per request where each record is pretty huge) is there a way that compression would help reducing the speed. If so which compression scheme would you recommend.

I read on another thread that they pattern of data also matters a lot on they type of compression that needs to be used. The pattern of data is consistent and resembles the following

 :desc=>some_description
 :url=>some_url
 :content=>some_content
 :score=>some_score
 :more_attributes=>more_data

Can someone recommend a solution to how I could reduce this delay. They delay is approx 6-8 seconds. I'm using Ruby on Rails to develop this application and the server providing the data uses Python for the most part.

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

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

发布评论

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

评论(2

怀中猫帐中妖 2024-09-02 20:23:57

我首先会看看这 8 秒的延迟有多少与以下内容相关:

  1. 服务器端处理(生成数据需要花费多少时间)
    这次有很多技巧需要改进,包括:

    • 数据库索引

    • 缓存

    • 更快的 to_json 库

一些优秀的资源是 Rails 上的 NewRelic 播客可扩展性http://railslab。 newrelic.com/2009/02/09/episode-7-fragment-caching

  1. 传输延迟(数据在服务器和客户端之间发送需要多长时间)

I would first look at how much of this 8s delay is related to:

  1. Server side processing (how much took for the data to be generated)
    There are a lot of techniques to improve this time, including:

    • DB indexes

    • caching

    • a faster to_json library

Some excellent resources are the NewRelic podcasts on Rails scalability http://railslab.newrelic.com/2009/02/09/episode-7-fragment-caching

  1. Transmission delay(how much time took for the data to be sent between the server and the client)

熟人话多 2024-09-02 20:23:57

gzip 可能会显着减小文本数据并优化加载速度。 YSlow 也推荐了它。

gzip might significantly reduce the size of text data and optimize load speeds. It's also recommended by YSlow.

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