简体   繁体   English

自定义设置推进器速率限制

[英]Custom setting Pusher rate limit

I'm using a Rails after_save callback in one of my ActiveRecord models to send push notifications to the client, which then triggers a partial refresh. 我在一个ActiveRecord模型中使用Rails after_save回调向客户端发送推送通知,然后触发部分刷新。 I'm using Pusher. 我正在使用Pusher。 Problem that I have is that I might be creating or updating up to 50 records over 5-10 seconds or whatever, which sends a lot of push notifications and ultimately refreshes. 我遇到的问题是,我可能会在5到10秒之内(最多)创建或更新多达50条记录,这会发送大量推送通知并最终刷新。 I know pusher has a rate limit of no more than 10 messages per second per client (connection). 我知道推送器的速率限制为每个客户端(连接)每秒不超过10条消息。 Is there any way to adjust that rate limit to say no more than 1 message per minute per client (connection)? 有什么办法可以调整速率限制,以使每个客户端(连接)每分钟不超过1条消息?

Note: I used to work for Pusher 注意:我曾经为Pusher工作

The rate limit you mention is actually when sending events between clients. 您提到的速率限制实际上是在客户端之间发送事件时。 It doesn't affect sending messages via their REST API. 它不会影响通过其REST API发送消息。

Client event docs can be found here: http://pusher.com/docs/client_api_guide/client_events#trigger-events 客户端事件文档可在以下位置找到: http : //pusher.com/docs/client_api_guide/client_events#trigger-events

The server docs don't say anything about a rate limit: http://pusher.com/docs/server_api_guide/interact_rest_api#publishing-events 服务器文档未说明速率限制: http//pusher.com/docs/server_api_guide/interact_rest_api#publishing-events

You appear to have four options: 您似乎有四个选择:

  1. Do something on your server so that you rate limit sending messages to the Pusher API. 在您的服务器上执行某些操作,以便限制发送消息到Pusher API的速率。 This will also save you using up your "messages per day" allocation. 这也可以节省您的“每日邮件”分配。
  2. Do something on the client; 对客户做点事; set a timeout that waits for up to 10 seconds to see if any other refresh messages are going to come along. 设置一个等待最多10秒钟的超时,以查看是否还会出现其他刷新消息。 It can therefore ignore them and only refresh when it's sure no more messages are going to arrive and then trigger the refresh yet again after the reload. 因此,它可以忽略它们,仅在确定不再有消息到达时刷新,然后在重新加载后再次触发刷新。
  3. When you refresh the page don't connect to Pusher for up to 10 seconds. 刷新页面时,最多10秒钟不要连接到Pusher。 That way you'll miss all the other refresh messages from the same batch. 这样,您将错过同一批次中的所有其他刷新消息。
  4. If possible, change your code so that the message you send isn't simply to tell the page to refresh but provides the information that is required to change the page dynamically on the client. 如果可能,请更改代码,以使您发送的消息不仅只是告诉页面刷新,而且还提供了在客户端上动态更改页面所需的信息。 Since you are doing a partial refresh - probably via an XHR which gets updated content - this may be possible. 由于您正在执行部分刷新(可能是通过XHR来获取更新的内容),因此这是可能的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM