python - 为 iOS 发送 9000/s 推送通知

标签 python ios push-notification apple-push-notifications

我的系统有大约 10000 个 iOS 用户,我想向他们发送推送通知但不需要花时间,因为我可能会在 5 分钟或更短的时间内为同一用户发送另一条消息, 我之前读过这个答案,它也是在 Apple 网站上创建的:

Push Notification Throughput and Error Checking

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.

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

但是我一个一个发通知的时候不知道怎么发9000/s的消息。

我正在使用 Python (PyAPNs),这是我的代码:

from apns import APNs,Payload
result = execute("SELECT token_hex FROM `Users`")
for row in result:
    token_hex = row['token_hex']
    apns = APNs(use_sandbox=False, cert_file='Cert.pem', key_file='CertKey.pem')
    payload = Payload(alert="Message",badge=1,sound='default')
    apns.gateway_server.send_notification(token_hex, payload)

我要在 30 多分钟内发送给 10000 个用户...

那么我的代码有什么问题,或者我该怎么做才能在更短的时间内发送通知...

提前致谢

最佳答案

我不懂 python,但查看您的代码,您似乎在不必要地重复调用。您应该使用相同的连接来发送所有通知。

也许你应该尝试这样的事情:

from apns import APNs,Payload
result = execute("SELECT token_hex FROM `Users`")
apns = APNs(use_sandbox=False, cert_file='Cert.pem', key_file='CertKey.pem')
payload = Payload(alert="Message",badge=1,sound='default')
for row in result:
    token_hex = row['token_hex']
    apns.gateway_server.send_notification(token_hex, payload)

这是假设您向所有设备发送相同的通知负载。

关于python - 为 iOS 发送 9000/s 推送通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17450255/

相关文章:

python - 使用 python 创建正确的 JSON 字符串

ios - UITableViewCell 中 UIVisualEffectView 的性能问题

ios - AVAudioPlayer pause() 未按预期运行

ios - 完成启动后或在我们的应用程序内启用/禁用推送通知

ios - PhoneGap/Cordova pushplugin iOs 注册回调未触发

mobile - 跨平台移动推送通知

java - 如何在python中返回包含sqlalchemy中的对象的列表,类似于java中的List<OrderInfo>

python - 从局域网访问sql数据库

python - Perl 的 (<>) 在 Python 中的等价物是什么? fileinput 没有按预期工作

php - 服务器能否在用户不知情的情况下将更改通知 iOS/Android 应用程序?