散装苹果推送通知

散装苹果推送通知

问题描述:

我有一个包括发送苹果推送通知到〜100万用户定期的应用程序。这样做的设置已建成并通知少量测试。既然没有办法,我可以测试该尺度的发送,我想知道是否有批量发送推送通知任何陷阱。我写的Python脚本打开的推送服务器的单一连接,并通过该连接发送的所有通知。苹果建议保持它开放尽可能长时间。但我也看到,连接终止,你需要重新建立它。

I have an app that involves sending Apple Push Notifications to ~1M users periodically. The setup for doing so has been built and tested for small numbers of notifications. Since there is no way I can test sending at that scale, I am interested in knowing whether there are any gotchas in sending bulk push notifications. I have scripts written in Python that open a single connection to the push server and send all notifications over that connection. Apple recommends keeping it open for as long as possible. But I have also seen that the connection terminates and you need to reestablish it.

所有的一切,这是令人不安的,成功的将不被确认,只有那些错误被标记。从程序员的角度来看,而不是简单地检查一件事:如果(成功)你现在需要看众多事情可能出错。

All in all, it is disconcerting that successful sends are not acknowledged, only erroneous ones are flagged. From a programmer's standpoint instead of simply checking one thing "if (success)" you now need to watch for numerous things that could go wrong.

我的问题是:什么是组典型的,你需要注意,以确保您的消息不会声息被人遗忘的错误?连接关闭是容易的。是否有其他人呢?

My question is: What are the typical set of errors that you need to watch out for to make sure your messages don't silently disappear into oblivion? The connection closing is an easy one. Are there others?

我完全同意你的看法,这个API是非常令人沮丧,如果他们将发送的每个通知这本来是很容易实现的响应。

I completely agree with you that this API is very frustrating, and if they would have sent a response for each notification it would have been much easier to implement.

这是说,这里就是苹果公司说,你应该做的(由技术说明 ):

That said, here's what Apple say you should do (from Technical Note) :

推送通知吞吐量和错误检查

Push Notification Throughput and Error Checking

有没有使用的APN帽或批量大小限制。 iOS的6.1
  preSS发布声明的APN已超过4万亿推送到
  因为通知正式成立。它是在WWDC 2012发布
  那是的APN每天发送7十亿通知。

There are no caps or batch size limits for using APNs. The iOS 6.1 press release stated that APNs has sent over 4 trillion push notifications since it was established. It was announced at WWDC 2012 that APNs is sending 7 billion notifications daily.

如果你看到吞吐量每秒降低超过9,000通知,
  您的服务器可能会受益于改进的错误处理逻辑。

If you're seeing throughput lower than 9,000 notifications per second, your server might benefit from improved error handling logic.

下面是如何检查错误使用增强的二进制文件时
  接口。继续写,直到写入失败。如果流是就绪
  再次书写,重新发送通知和坚持下去。如果
  流是没有准备好写,参见如果流是可
  阅读。

Here's how to check for errors when using the enhanced binary interface. Keep writing until a write fails. If the stream is ready for writing again, resend the notification and keep going. If the stream isn't ready for writing, see if the stream is available for reading.

如果是,读出可以从流的一切。如果你得到零
  字节回,连接被关闭,因为一个错误,如
  无效的命令字节或其他解析错误。如果你得到六个字节
  回来了,这是一个错误的反应,你可以检查响应
  code和导致错误通知的ID。你需要
  发送每个通知再次下一个。

If it is, read everything available from the stream. If you get zero bytes back, the connection was closed because of an error such as an invalid command byte or other parsing error. If you get six bytes back, that's an error response that you can check for the response code and the ID of the notification that caused the error. You'll need to send every notification following that one again.

一旦一切都已经发送,错误做最后一检查
  响应。

Once everything has been sent, do one last check for an error response.

这可能需要一段时间的下跌连接从做它的方式
  APNS回您的服务器仅仅因为正常的延迟。这是可能的
  发送500通知的写入失败,因为的前
  连接被丢弃。大约1700通知写入可能会失败
  只是因为管道是满的,所以在执行一次在这种情况下,一旦
  流已准备好再次书写。

It can take a while for the dropped connection to make its way from APNs back to your server just because of normal latency. It's possible to send over 500 notifications before a write fails because of the connection being dropped. Around 1,700 notifications writes can fail just because the pipe is full, so just retry in that case once the stream is ready for writing again.

现在,这里的地方的权衡变得有趣。您可以检查的
  以后每隔错误响应写,你会赶上错误权
  远。但是,这会导致它需要发送的时间大幅增加
  一批通知。

Now, here's where the tradeoffs get interesting. You can check for an error response after every write, and you'll catch the error right away. But this causes a huge increase in the time it takes to send a batch of notifications.

设备令牌应该几乎全部是有效的,如果你已经抓获了他们
  正确,你将它们发送到正确的环境。所以
  有意义的优化假设故障,将是罕见的。你会得到的方式
  或更好的性能,如果您等待写入失败的批次
  完成之前检查错误响应,算上时间
  再次发送回落通知。

Device tokens should almost all be valid if you've captured them correctly and you're sending them to the correct environment. So it makes sense to optimize assuming failures will be rare. You'll get way better performance if you wait for write to fail or the batch to complete before checking for an error response, even counting the time to send the dropped notifications again.

这一切都不是真的特定的APN,它适用于大多数
  插座级编程。

None of this is really specific to APNs, it applies to most socket-level programming.

如果您选择的开发工具支持多线程或
  间通信,你可以有一个线程或进程等待
  对于错误响应所有的时间,让主发送线程或
  进程知道什么时候应该放弃,然后重试。

If your development tool of choice supports multiple threads or interprocess communication, you could have a thread or process waiting for an error response all the time and let the main sending thread or process know when it should give up and retry.